forked from CAWebPublishing/CAWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
528 lines (406 loc) · 11.6 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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
/**
* Gulpfile.
*
* Gulp for CAWeb WordPress.
*
* This Gulpfile is a modified version of WPGulp.
* @tutorial https://github.com/ahmadawais/WPGulp
* @author Ahmad Awais <https://twitter.com/MrAhmadAwais/>
*/
/**
* Load WPGulp Configuration.
*
* TODO: Customize your project in the wpgulp.js file.
*/
const config = require( './wpgulp.config.js' );
/**
* Load Plugins.
*
* Load gulp plugins and passing them semantic names.
*/
const gulp = require( 'gulp' ); // Gulp of-course.
var argv = require('yargs').argv;
// CSS related plugins.
const sass = require( 'gulp-sass' ); // Gulp plugin for Sass compilation.
sass.compiler = require('node-sass');
// JS related plugins.
const uglify = require('gulp-uglify-es').default; // Minifies JS files.
// HTML related plugins
const htmlbeautify = require('gulp-html-beautify'); // Beautify HTML/PHP files
// Utility related plugins.
const concat = require( 'gulp-concat' ); // Concatenates files.
const lineec = require( 'gulp-line-ending-corrector' ); // Consistent Line Endings for non UNIX systems. Gulp Plugin for Line Ending Corrector (A utility that makes sure your files have consistent line endings).
const notify = require( 'gulp-notify' ); // Sends message notification to you.
const fs = require('fs'); // File System
const del = require('del'); // Delete plugin
/*
CAWeb Admin Styles
*/
gulp.task('admin-css', async function() {
del( ['css/admin*.css'] );
if ( argv.prod ) {
buildAdminStyles(true);
}
if ( argv.dev ) {
buildAdminStyles(false);
}
if( buildAll(argv) ){
buildAdminStyles(true);
buildAdminStyles(false);
}
});
/*
CAWeb Frontend Styles
*/
gulp.task('frontend-css', async function (_) {
var version = undefined !== argv.ver ? [ argv.ver ] : config.availableVers;
del( ['css/cagov-v*.css'] );
version.forEach(function(v){
if ( argv.prod ) {
buildFrontEndStyles(true, v);
}
if ( argv.dev ) {
buildFrontEndStyles(false, v);
}
if( buildAll(argv) ){
buildFrontEndStyles(false, v);
buildFrontEndStyles(true, v);
}
});
});
/*
CAWeb BootStrap Admin Styles
*/
gulp.task('bootstrap-css', async function() {
del( ['css/bootstrap*.css'] );
if ( argv.prod ) {
buildBootStrapStyles(true);
}
if ( argv.dev ) {
buildBootStrapStyles(false);
}
if( buildAll(argv) ){
buildBootStrapStyles(true);
buildBootStrapStyles(false);
}
});
/*
CAWeb Admin JavaScript
*/
gulp.task('admin-js', async function() {
del( ['js/admin*.js'] );
if ( argv.prod ) {
buildAdminJS(true);
}
if ( argv.dev ) {
buildAdminJS(false);
}
if( buildAll(argv) ){
buildAdminJS(true);
buildAdminJS(false);
}
});
/*
CAWeb JavaScript
*/
gulp.task('caweb-js', async function() {
var version = undefined !== argv.ver ? [ argv.ver ] : config.availableVers;
del( ['js/caweb-v*.js'] );
version.forEach(function(v){
if ( argv.prod ) {
buildCAWebJS(true, v);
}
if ( argv.dev ) {
buildCAWebJS(false, v);
}
if( buildAll(argv) ){
buildCAWebJS(true, v);
buildCAWebJS(false, v);
}
});
});
/*
CAWeb BootStrap Admin Javascript
*/
gulp.task('bootstrap-js', async function() {
del( ['js/bootstrap*.js'] );
if ( argv.prod ) {
buildBootStrapJS(true);
}
if ( argv.dev ) {
buildBootStrapJS(false);
}
if( buildAll(argv) ){
buildBootStrapJS(true);
buildBootStrapJS(false);
}
});
/*
CAWeb Theme Customizer JavaScript
*/
gulp.task('customizer-js', async function() {
del( ['js/theme-customizer*.js'] );
if ( argv.prod ) {
buildCustomizerJS(true);
}
if ( argv.dev ) {
buildCustomizerJS(false);
}
if( buildAll(argv) ){
buildCustomizerJS(true);
buildCustomizerJS(false);
}
});
gulp.task('beautify', async function() {
var options = {indentSize: 2};
var src = ['**/*.php'];
if( argv.hasOwnProperty('file') ){
src = argv.file;
}
gulp.src(src, {base: './'})
.pipe(htmlbeautify(options))
.pipe(gulp.dest('./'));
});
/*
CAWeb Build All CSS/JS and Beautify
*/
gulp.task('build', async function(){
var version = undefined !== argv.ver ? [ argv.ver ] : config.availableVers;
del( ['js/*.js', 'css/*.css'] );
if ( argv.prod ) {
// Build Admin Styles
buildAdminStyles(true);
// Build Admin JS
buildAdminJS(true);
version.forEach(function(v){
// Build Frontend Styles
buildFrontEndStyles(true, v);
// Build CAWeb JS
buildCAWebJS(true, v);
});
// Build Bootstrap Styles
buildBootStrapStyles(true);
// Build Admin Bootstrap JS
buildBootStrapJS(true);
// Build Theme Customizer JS
buildCustomizerJS(true);
}
if ( argv.dev ) {
// Build Admin Styles
buildAdminStyles(false);
// Build Admin JS
buildAdminJS(false);
version.forEach(function(v){
// Build Frontend Styles
buildFrontEndStyles(false, v);
// Build CAWeb JS
buildCAWebJS(false, v);
});
// Build Bootstrap Styles
buildBootStrapStyles(false);
// Build Admin Bootstrap JS
buildBootStrapJS(false);
// Build Theme Customizer JS
buildCustomizerJS(false);
}
if( buildAll(argv) ){
// Build Admin Styles
buildAdminStyles(true);
buildAdminStyles(false);
// Build Admin JS
buildAdminJS(true);
buildAdminJS(false);
version.forEach(function(v){
// Build Frontend Styles
buildFrontEndStyles(true, v);
buildFrontEndStyles(false, v);
// Build CAWeb JS
buildCAWebJS(true, v);
buildCAWebJS(false, v);
});
// Build Bootstrap Styles
buildBootStrapStyles(true);
buildBootStrapStyles(false);
// Build Admin Bootstrap JS
buildBootStrapJS(true);
buildBootStrapJS(false);
// Build Theme Customizer JS
buildCustomizerJS(true);
buildCustomizerJS(false);
}
});
// Gulp Task Functions
async function buildAdminStyles( min = false){
var buildOutputStyle = min ? 'compressed' : 'expanded';
var minified = min ? '.min' : '';
var t = minified ? ' Minified' : '';
t = '✅ CAWeb Admin Styles' + t;
if( ! config.adminCSS.length )
return;
return gulp.src(config.adminCSS)
.pipe(
sass({
outputStyle: buildOutputStyle,
})
)
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems.
.pipe(concat('admin' + minified + '.css')) // compiled file
.pipe( notify({ title: t, message: '<%= file.relative %> was created successfully.', onLast: true }) )
.pipe(gulp.dest('./css/'));
}
async function buildFrontEndStyles( min = false, ver = config.templateVer){
var buildOutputStyle = min ? 'compressed' : 'expanded';
var minified = min ? '.min' : '';
var versionDir = config.templateCSSAssetDir + 'version' + ver;
var versionColorschemesDir = versionDir + '/colorscheme/';
var colors = fs.readdirSync(versionColorschemesDir);
colors.forEach(function(e){
var f = [versionDir + '/cagov.core.css',
versionColorschemesDir + e,
config.templateCSSAssetDir + 'cagov.font-only.css'];
f = f.concat( config.frontendCSS );
f = f.concat( config.SCSSAssetDir + 'cagov/version' + ver + '/custom.scss' );
var color = config.availableColors[e];
var t = minified ? ' Minified' : '';
t = '✅ CAWeb v' + ver + ' ' + color + ' Colorscheme' + t;
if( ! f.length )
return;
var fileName = 'cagov-v' + ver + '-' +
( minified ? e.replace('.css', '.min.css') : e);
return gulp.src(f)
.pipe(
sass({
outputStyle: buildOutputStyle,
})
)
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems.
.pipe(concat(fileName )) // compiled file
.pipe(gulp.dest('./css/'))
.pipe( notify({ title: t, message: '<%= file.relative %> was created successfully.', onLast: true }) );
;
});
}
async function buildBootStrapStyles( min = false ){
var buildOutputStyle = min ? 'compressed' : 'expanded';
var minified = min ? '.min' : '';
var t = minified ? ' Minified' : '';
t = '✅ CAWeb Admin Bootstrap Styles' + t;
if( ! config.adminBootStrapCSS.length )
return;
return gulp.src(config.adminBootStrapCSS)
.pipe(
sass({
outputStyle: buildOutputStyle,
})
)
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems.
.pipe(concat('bootstrap' + minified + '.css')) // compiled file
.pipe( notify({ title: t, message: '<%= file.relative %> was created successfully.', onLast: true }) )
.pipe(gulp.dest('./css/'));
}
async function buildAdminJS( min = false){
var minified = min ? '.min' : '';
var t = minified ? ' Minified' : '';
t = '✅ CAWeb Admin JavaScript' + t;
if( ! config.adminJS.length )
return;
let js = gulp.src(config.adminJS)
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems.
.pipe(concat('admin' + minified + '.js')) // compiled file
.pipe( notify({ title: t, message: '<%= file.relative %> was created successfully.', onLast: true }) )
if( min ){
js = js.pipe(uglify());
}
return js.pipe(gulp.dest('./js/'));
}
async function buildBootStrapJS( min = false ){
var minified = min ? '.min' : '';
var t = minified ? ' Minified' : '';
t = '✅ CAWeb Admin Bootstrap JavaScript' + t;
if( ! config.adminBootStrapJS.length )
return;
let js = gulp.src(config.adminBootStrapJS)
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems.
.pipe(concat('bootstrap' + minified + '.js')) // compiled file
.pipe( notify({ title: t, message: '<%= file.relative %> was created successfully.', onLast: true }) )
if( min ){
js = js.pipe(uglify());
}
return js.pipe(gulp.dest('./js/'));
}
async function buildCAWebJS( min = false, ver = config.templateVer){
var minified = min ? '.min' : '';
var versionDir = config.JSAssetDir + 'cagov/version' + ver;
var f = config.frontendJS.concat(
[versionDir + '/cagov.core.js',
versionDir + '/custom.js'],
config.a11yJS);
var t = minified ? ' Minified' : '';
t = '✅ CAWeb v' + ver + ' JavaScript' + t;
if( ! f.length )
return;
let js = gulp.src(f)
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems.
.pipe(concat('caweb-v' + ver + minified + '.js')) // compiled file
.pipe( notify({ title: t, message: '<%= file.relative %> was created successfully.', onLast: true }) );
if( min ){
js = js.pipe(uglify());
}
return js.pipe(gulp.dest('./js/'));
}
async function buildCustomizerJS( min = false){
var minified = min ? '.min' : '';
var t = minified ? ' Minified' : '';
var t1 = '✅ CAWeb Theme Customizer JavaScript' + t;
var t2 = '✅ CAWeb Theme Customizer Controls JavaScript' + t;
if( ! config.themeCustomizerJS.length )
return;
// Theme Customizer
let js = gulp.src(config.themeCustomizerJS)
.pipe( lineec() )
.pipe(concat('theme-customizer' + minified + '.js')) // compiled file
.pipe( notify({ title: t1, message: '<%= file.relative %> was created successfully.', onLast: true }) )
// Consistent Line Endings for non UNIX systems.
if( min ){
js = js.pipe(uglify());
}
js = js.pipe(gulp.dest('./js/'));
// Theme Customizer Controls
js = gulp.src(config.themeCustomizerControlJS)
.pipe( lineec() )
.pipe(concat('theme-customizer-controls' + minified + '.js'))
.pipe( notify({ title: t2, message: '<%= file.relative %> was created successfully.', onLast: true }) );
if( min ){
js = js.pipe(uglify());
}
js = js.pipe(gulp.dest('./js/'));
}
function buildAll( params = {} ){
var b = params.hasOwnProperty('all') || ! Object.keys(params).length;
var p = params.hasOwnProperty('dev') || params.hasOwnProperty('prod');
return b || ! p ;
}
// DEV (Development Output)
/*gulp.task('dev', parameterized.series(
'admin-css --dev',
'frontend-css --dev',
'bootstrap-css --dev',
'admin-js --dev',
'caweb-js --dev',
'bootstrap-js --dev',
'customizer-js --dev'
)
);
// PROD (Minified Output)
gulp.task('prod', parameterized.series(
'admin-css --prod',
'frontend-css --prod',
'bootstrap-css --prod',
'admin-js --prod',
'caweb-js --prod',
'bootstrap-js --prod',
'customizer-js --prod',
)
);
*/
//gulp.task('build', parameterized.series('dev', 'prod') );