-
Notifications
You must be signed in to change notification settings - Fork 18
/
gulpfile.js
332 lines (285 loc) · 8.15 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
// Currently unused. However, I would prefer to use Gulp
// in future instead of Grunt (marble)
const autoprefix = require('autoprefixer');
const browserSync = require('browser-sync');
const del = require('del');
const gulpStylelint = require('gulp-stylelint');
const cssnano = require('cssnano');
const modernizr = require('gulp-modernizr');
const optimizejs = require('gulp-optimize-js');
const pkg = require('./package.json');
const postcss = require('gulp-postcss');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const stylelint = require('stylelint');
const svgmin = require('gulp-svgmin');
const ugliterse = require('gulp-uglify-es').default;
const util = require('./gulp/util.js');
const { modernizrOptions } = require('./gulp/options.js');
const { src, dest, series, parallel, watch } = require('gulp');
// cleaning
function cleanAllTask(done) {
'use strict';
del.sync(['GENERATED', 'GENERATED-min', 'GENERATED-reports']);
done();
}
function cleanCssTask(done) {
'use strict';
del.sync(['GENERATED/static/css']);
done();
}
function cleanCssOwnTask(done) {
'use strict';
del.sync(['GENERATED/static/css/theme.*', 'GENERATED/static/css/webfonts.*', 'GENERATED/static/css/fontawesome.*']);
done();
}
function cleanJsTask(done) {
'use strict';
del.sync(['GENERATED/static/js']);
done();
}
function cleanJsOwnTask(done) {
'use strict';
del.sync([
'GENERATED/static/js/theme.*',
'GENERATED/static/js/searchtools.*',
'GENERATED/static/js/doctools.*',
'GENERATED/static/jsmaps/theme.*',
'GENERATED/static/jsmaps/searchtools.*',
'GENERATED/static/jsmaps/doctools.*',
]);
done();
}
// copying
function cssCopyOwnTask() {
'use strict';
return src(['sass/theme.scss', 'sass/webfonts.scss', 'sass/fontawesome.scss'])
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded',
sourceComments: true,
errLogToConsole: true
}))
.pipe(postcss([
autoprefix({
cascade: true,
remove: true
}),
stylelint({
fix: true,
faillAfterError: false,
reportOutputDir: 'GENERATED-reports/lint',
configOverrides: {
"rules": {
"declaration-block-no-duplicate-properties": null,
}
},
reporters: [
{formatter: 'verbose', console: true},
{formatter: 'json', save: 'report.json'},
]}),
]))
.pipe(sourcemaps.write('.'))
.pipe(dest('GENERATED/static/css/'))
;
}
function copyFontsTask() {
'use strict';
return src(['node_modules/@fortawesome/fontawesome-free/webfonts/**/*'])
.pipe(src(['fonts/**/*', '!**/*.txt']))
.pipe(dest('GENERATED/static/fonts/'));
}
function copyHtmlTask(done) {
'use strict';
return src(['clickdummy/webroot/**/*'])
.pipe(dest('GENERATED/'));
}
function copySvgTask(done) {
'use strict';
return src(['img/**/*.svg'])
.pipe(svgmin())
.pipe(dest('GENERATED/static/img/'));
}
function jsCopyOwnTask(done) {
'use strict';
return src(['js/**/*.js'])
.pipe(optimizejs())
.pipe(dest('GENERATED/static/js/'));
}
function copyVendorStuffTask(done) {
'use strict';
return src(['node_modules/gsap/dist/**/*'])
.pipe(dest('GENERATED/static/vendor/gsap/dist/'));
}
function jsCopyVendorTask() {
'use strict';
return src(['node_modules/jquery/dist/jquery.js'])
.pipe(src(['node_modules/popper.js/dist/umd/popper.js']))
.pipe(src(['node_modules/bootstrap/dist/js/bootstrap.js']))
.pipe(src(['node_modules/autocompleter/autocomplete.js']))
.pipe(src(['node_modules/underscore/underscore.js']))
.pipe(optimizejs())
.pipe(dest('GENERATED/static/js'));
}
function jsCopyMinVendorTask() {
'use strict';
return src(['node_modules/jquery/dist/jquery.min.js'])
.pipe(src(['node_modules/popper.js/dist/umd/popper.min.js']))
.pipe(src(['node_modules/bootstrap/dist/js/bootstrap.min.js']))
.pipe(src(['node_modules/autocompleter/autocomplete.min.js']))
// .pipe(src(['node_modules/underscore/underscore.min.js']))
.pipe(dest('GENERATED-min/static/js'));
}
// devault
function defaultTask(done) {
'use strict';
console.log("run: 'yarn gulp --simple-tasks' or 'yarn gulp -T'");
done();
}
// css
function cssMinifyTask() {
'use strict';
return src(['GENERATED/static/css/**/*.css'])
.pipe(sourcemaps.init())
.pipe(rename({suffix: '.min'}))
.pipe(postcss([
cssnano({
discardComments: {
removeAll: true
}
}),
]))
.pipe(sourcemaps.write('./'))
.pipe(dest('GENERATED/static/css/'))
;
}
function cssMinifyOwnTask() {
'use strict';
return src([
'GENERATED/static/css/theme.css',
'GENERATED/static/css/webfonts.css',
'GENERATED/static/css/fontawesome.css',
])
.pipe(sourcemaps.init())
.pipe(rename({suffix: '.min'}))
.pipe(postcss([
cssnano({
discardComments: {
removeAll: true
}
}),
]))
.pipe(sourcemaps.write('./'))
.pipe(dest('GENERATED/static/css/'))
;
}
function jsAddModernizrTask(done) {
'use strict';
return src(['js/**/*.js'])
.pipe(modernizr(modernizrOptions))
.pipe(dest('GENERATED/static/js/'));
}
function jsUglifyTask() {
'use strict';
return src(['GENERATED/static/js/**/*.js'])
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.init())
.pipe(ugliterse())
.pipe(sourcemaps.write('../jsmaps'))
.pipe(dest('GENERATED/static/js/'))
;
}
function jsUglifyOwnTask() {
'use strict';
return src(['GENERATED/static/js/theme.js', 'GENERATED/static/js/doctools.js', 'GENERATED/static/js/searchtools.js'])
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.init())
.pipe(ugliterse())
.pipe(sourcemaps.write('../jsmaps'))
.pipe(dest('GENERATED/static/js/'))
;
}
function uglifyOwnTask() {
'use strict';
return src(['GENERATED/static/js/theme.js', 'GENERATED/static/js/doctools.js', 'GENERATED/static/js/searchtools.js'])
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.init())
.pipe(ugliterse())
.pipe(sourcemaps.write('../jsmaps'))
.pipe(dest('GENERATED/static/js/'))
;
}
function startServer(done) {
'use strict';
// https://browsersync.io/docs/options
browserSync.init({
server: {
baseDir: 'GENERATED/'
}
});
done();
}
function reloadBrowser(done) {
'use strict';
browserSync.reload();
done();
}
function watchSource(done) {
'use strict';
watch('clickdummy/webroot', series(exports.copyHtml, reloadBrowser));
watch('sass', series(exports.cssBuildOwn, reloadBrowser));
watch('js' , series(exports.jsBuildOwn, reloadBrowser));
done();
}
// 1st level solo
exports.default = defaultTask;
exports.decodePackageJson = util.decodePackageJsonTask;
exports.cleanCss = cleanCssTask;
exports.cleanCssOwn = cleanCssOwnTask;
exports.cleanJs = cleanJsTask;
exports.cleanJsOwn = cleanJsOwnTask;
exports.copyFonts = copyFontsTask;
exports.copyHtml = copyHtmlTask;
exports.copySvg = copySvgTask;
exports.copyVendorStuff = copyVendorStuffTask;
exports.cssCopyOwn = cssCopyOwnTask;
exports.cssMinify = cssMinifyTask;
exports.jsAddModernizr = jsAddModernizrTask;
exports.jsCopyMinVendor = jsCopyMinVendorTask;
exports.jsCopyOwn = jsCopyOwnTask;
exports.jsCopyVendor = jsCopyVendorTask;
exports.jsCopyVendorAll = parallel(jsCopyVendorTask, jsCopyMinVendorTask);
exports.jsUglify = jsUglifyTask;
exports.jsUglifyOwn = jsUglifyOwnTask;
// 2nd level combined
exports.CLEAN_ALL = cleanAllTask;
exports.CSS_BUILD_ALL = series(
exports.cleanCss,
exports.cssCopyOwn,
exports.cssMinify,
);
exports.JS_BUILD_ALL = series(
exports.cleanJs,
parallel(
exports.jsAddModernizr,
exports.jsCopyOwn,
exports.jsCopyVendorAll,
),
exports.jsUglify
);
// 3nd level combined
exports.frontend = series(
exports.CLEAN_ALL,
parallel(
exports.CSS_BUILD_ALL,
exports.JS_BUILD_ALL,
exports.copyFonts,
exports.copyHtml,
exports.copySvg,
exports.copyVendorStuff,
),
);
exports.watch = series(exports.frontend, startServer, watchSource);
exports.cssBuildOwn = series(cleanCssOwnTask, cssCopyOwnTask, cssMinifyOwnTask);
exports.jsBuildOwn = series(cleanJsOwnTask, jsCopyOwnTask, uglifyOwnTask);