forked from PersonalBrandMgmt/admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·242 lines (180 loc) · 8.13 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
'use strict';
/*
* CLEAN UI HTML ADMIN TEMPLATE GULP FILE
*/
/////////////////////////////////////////////////////////////////////////////
// CONFIGURATION
var cleanui = {
"templateName": "Clean UI HTML Admin Template",
"pageTitle": "Clean UI HTML Admin Template",
"description": "Clean UI HTML – a modern professional admin template, based on Bootstrap 4 framework. Clean UI is a powerful and super flexible tool, which suits best for any kind of web application: Web Applications; CRM; CMS; Admin Panels; Dashboards; etc.",
};
/////////////////////////////////////////////////////////////////////////////
// GULP PLUGINS
var gulp = require('gulp'),
watch = require('gulp-watch'),
autoprefix = require('gulp-autoprefixer'),
sass = require('gulp-sass'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rigger = require('gulp-rigger'),
ignore = require('gulp-ignore'),
rimraf = require('gulp-rimraf'),
browserSync = require("browser-sync"),
wrap = require('gulp-wrap'),
template = require('gulp-template'),
data = require('gulp-data'),
print = require('gulp-print'),
replace = require('gulp-replace-task'),
promise = require('gulp-promise'),
fs = require('fs');
/////////////////////////////////////////////////////////////////////////////
// GULP PATHS
var path = {
src: {
versions: 'src/versions/',
pages: 'src/pages/**/*.html',
components: 'src/components/',
templates: 'src/components/**/**/*.html',
img: 'src/components/**/img/**/*.*',
css: 'src/components/**/**/*.scss',
js: 'src/components/**/**/*.js',
favicon: 'src/components/dummy-assets/img/favicon.ico',
vendors_by_bower: 'src/vendors/by_bower/**/*.*',
vendors_by_hands: 'src/vendors/by_hands/**/*.*'
},
build: {
versions: 'dist/versions/',
components: 'dist/components/',
vendors: 'dist/vendors/'
},
clean: ['dist/*']
};
/////////////////////////////////////////////////////////////////////////////
// PRINT ERRORS
function printError(error) {
console.log(error.toString()); // print error
this.emit('end'); // end task
}
/////////////////////////////////////////////////////////////////////////////
// BROWSERSYNC SERVE
gulp.task('serve', function () {
browserSync({
server: {
baseDir: "./dist/", // base dir path
directory: true // show as directory
},
tunnel: false, // tunnel
host: 'localhost', // host
port: 9000, // port
logPrefix: "frontend", // console log prefix
}); // run BrowserSync
});
/////////////////////////////////////////////////////////////////////////////
// BUILD PAGES
gulp.task('build:versions', function () {
var tasks = [];
var arrayHtml = fs.readdirSync(path.src.versions).filter(function(e) { return e !== 'head.html' }); // get template versions path excluding head.html
for (var i in arrayHtml) {
tasks.push(
new Promise(function(resolve, reject) {
gulp.src(path.src.pages) // get pages templates
.pipe(ignore.exclude('**/head.html')) // exclude mixins.scss file
.pipe(data({
templateName: cleanui.templateName,
pageTitle: cleanui.pageTitle,
productVersion: cleanui.version
})) // set variables
.pipe(wrap({src: path.src.versions + arrayHtml[i]})) // insert all pages to layout
.pipe(rigger()) // include component templates to generated pages
.pipe(template()) // replace DATA variables
.pipe(rename(function (path) {
var prefix = path.dirname;
path.dirname = "/";
path.basename = prefix + '-' + path.basename;
})) // rename pages
.on('error', printError) // print error if found
.pipe(gulp.dest(path.build.versions + arrayHtml[i].replace('.html', ''))) // copy generated pages to build folder
.on('end', resolve)
})
)
}
return Promise.all(tasks).then(function () {
browserSync.reload(); // reload BrowserSync
});;
});
/////////////////////////////////////////////////////////////////////////////
// VENDORS BUILD
gulp.task('build:vendors', function() {
gulp.src([path.src.vendors_by_bower, path.src.vendors_by_hands]) // get folders with vendors components
.pipe(gulp.dest(path.build.vendors)); // copy to destination folder
});
/////////////////////////////////////////////////////////////////////////////
// JAVASCRIPT BUILD
gulp.task('build:js', function () {
gulp.src(path.src.js, {base: path.src.components}) // get folder with js
.pipe(gulp.dest(path.build.components)) // copy to destination folder
.on('end', function(){ browserSync.reload(); }) // reload BrowserSync
});
/////////////////////////////////////////////////////////////////////////////
// STYLES BUILD
gulp.task('build:css', function () {
gulp.src(path.src.css, {base: path.src.components}) // get folder with css
.pipe(ignore.exclude('**/mixins.scss')) // exclude mixins.scss file
.pipe(sass({outputStyle: 'expanded', indentWidth: 4})) // css formatting
.on('error', printError) // print error if found
.pipe(autoprefix({
browsers: ['last 30 versions', '> 1%', 'ie 9'],
cascade: true
})) // add cross-browser prefixes
.pipe(gulp.dest(path.build.components)) // copy sources
.on('end', function(){ browserSync.reload(); }) // reload BrowserSync
});
/////////////////////////////////////////////////////////////////////////////
// IMAGES BUILD
gulp.task('build:img', function () {
gulp.src(path.src.img, {base: path.src.components}) // get folder with images
.pipe(ignore.exclude('**/favicon.ico')) // exclude favicon.css file
.on('error', printError) // print error if found
.pipe(gulp.dest(path.build.components)); // copy to destination folder
gulp.src(path.src.favicon, {base: path.src.components}) // get favicon
.pipe(gulp.dest(path.build.components)); // copy to destination folder
});
/////////////////////////////////////////////////////////////////////////////
// GLOBAL BUILD
gulp.task('build', [
'build:versions', // run build:html task
'build:css', // run build:css task
'build:js', // run build:js task
'build:img', // run build:img task
'build:vendors' // run build:vendors task
]);
/////////////////////////////////////////////////////////////////////////////
// FILES CHANGE WATCHER
gulp.task('watch', function(){
watch([path.src.versions, path.src.pages, path.src.templates], function() { // watch components, components, versions and templates folders
gulp.start('build:versions'); // run build:versions task
});
watch([path.src.css], function() { // watch css folder
gulp.start('build:css'); // run build:css task
});
watch([path.src.js], function() { // watch js folder
gulp.start('build:js'); // run build:js task
});
watch([path.src.img], function() { // watch img folder
gulp.start('build:img'); // run build:img task
});
watch([path.src.vendors_by_bower, path.src.vendors_by_hands], function() { // watch folder with vendors components
gulp.start('build:vendors'); // run build:vendors task
});
});
/////////////////////////////////////////////////////////////////////////////
// CLEAN PRODUCTION
gulp.task('clean', function () {
return gulp.src(path.clean) // get build folder
.pipe(rimraf()); // erase all
});
/////////////////////////////////////////////////////////////////////////////
// DEFAULT TASK
gulp.task('default', ['build', 'watch', 'serve']);