5
5
/**
6
6
* Site config
7
7
*/
8
- var manifest = require ( './assets/manifest.js' ) ;
9
- var timestamps = require ( './assets/last-edited.json' ) ;
8
+ const manifest = require ( './assets/manifest.js' ) ;
9
+ const timestamps = require ( './assets/last-edited.json' ) ;
10
10
11
11
/**
12
12
* Global modules
13
13
*/
14
- var argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ;
15
- var autoprefixer = require ( 'gulp-autoprefixer' ) ;
16
- var beeper = require ( 'beeper' ) ;
17
- var browsersync = require ( 'browser-sync' ) . create ( ) ;
18
- var concat = require ( 'gulp-concat' ) ;
19
- var flatten = require ( 'gulp-flatten' ) ;
20
- var gulp = require ( 'gulp' ) ;
21
- var gulpif = require ( 'gulp-if' ) ;
22
- var imagemin = require ( 'gulp-imagemin' ) ;
23
- var jshint = require ( 'gulp-jshint' ) ;
24
- var lazypipe = require ( 'lazypipe' ) ;
25
- var merge = require ( 'merge-stream' ) ;
26
- var cssnano = require ( 'gulp-cssnano' ) ;
27
- var plumber = require ( 'gulp-plumber' ) ;
28
- var runsequence = require ( 'run-sequence' ) ;
29
- var sass = require ( 'gulp-sass' ) ;
30
- var sourcemaps = require ( 'gulp-sourcemaps' ) ;
31
- var uglify = require ( 'gulp-uglify' ) ;
32
- var rename = require ( 'gulp-rename' ) ;
33
- var svgmin = require ( 'gulp-svgmin' ) ;
34
- var svgstore = require ( 'gulp-svgstore' ) ;
35
- var file = require ( 'gulp-file' ) ;
14
+ const argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ;
15
+ const autoprefixer = require ( 'gulp-autoprefixer' ) ;
16
+ const beeper = require ( 'beeper' ) ;
17
+ const browsersync = require ( 'browser-sync' ) . create ( ) ;
18
+ const concat = require ( 'gulp-concat' ) ;
19
+ const flatten = require ( 'gulp-flatten' ) ;
20
+ const { series , paralell } = require ( 'gulp' ) ;
21
+ const gulpif = require ( 'gulp-if' ) ;
22
+ const imagemin = require ( 'gulp-imagemin' ) ;
23
+ const jshint = require ( 'gulp-jshint' ) ;
24
+ const lazypipe = require ( 'lazypipe' ) ;
25
+ const merge = require ( 'merge-stream' ) ;
26
+ const cssnano = require ( 'gulp-cssnano' ) ;
27
+ const plumber = require ( 'gulp-plumber' ) ;
28
+ const runsequence = require ( 'run-sequence' ) ;
29
+ const sass = require ( 'gulp-sass' ) ;
30
+ const sourcemaps = require ( 'gulp-sourcemaps' ) ;
31
+ const uglify = require ( 'gulp-uglify' ) ;
32
+ const rename = require ( 'gulp-rename' ) ;
33
+ const svgmin = require ( 'gulp-svgmin' ) ;
34
+ const svgstore = require ( 'gulp-svgstore' ) ;
35
+ const file = require ( 'gulp-file' ) ;
36
36
37
37
/**
38
38
* Asset paths
39
39
*/
40
- var path = {
40
+ const path = {
41
41
"base" : {
42
42
"source" : "assets/" ,
43
43
"dist" : "dist/" ,
@@ -71,7 +71,7 @@ var path = {
71
71
/**
72
72
* Disable or enable features
73
73
*/
74
- var enabled = {
74
+ const enabled = {
75
75
76
76
// disable source maps when `--production`
77
77
maps : ! argv . production ,
@@ -92,7 +92,7 @@ var enabled = {
92
92
*
93
93
* Update asset class timestamp to last-edited.json
94
94
*/
95
- var updateTimestamp = function updateTimestamp ( stamp ) {
95
+ const updateTimestamp = ( stamp ) => {
96
96
97
97
timestamps [ stamp ] = Date . now ( ) ;
98
98
@@ -114,10 +114,10 @@ var updateTimestamp = function updateTimestamp(stamp) {
114
114
* 'globs': 'assets/main.scss,assets/print.scss'
115
115
* }
116
116
*/
117
- var buildAssets = function ( buildFiles ) {
117
+ const buildAssets = ( buildFiles ) => {
118
118
119
- var result = [ ] ;
120
- for ( var buildFile in buildFiles ) {
119
+ let result = [ ] ;
120
+ for ( let buildFile in buildFiles ) {
121
121
122
122
// set correct asset paths
123
123
for ( i = 0 ; i < buildFiles [ buildFile ] . length ; i ++ ) {
@@ -133,8 +133,8 @@ var buildAssets = function(buildFiles) {
133
133
134
134
} ;
135
135
136
- var jsAssets = buildAssets ( manifest . js ( ) ) ;
137
- var cssAssets = buildAssets ( manifest . css ( ) ) ;
136
+ const jsAssets = buildAssets ( manifest . js ( ) ) ;
137
+ const cssAssets = buildAssets ( manifest . css ( ) ) ;
138
138
139
139
/**
140
140
* Process: CSS
@@ -145,7 +145,7 @@ var cssAssets = buildAssets(manifest.css());
145
145
* .pipe(cssTasks('main.css')
146
146
* .pipe(gulp.dest(path.base.dist + 'styles'))
147
147
*/
148
- var cssTasks = function ( filename ) {
148
+ const cssTasks = ( filename ) => {
149
149
150
150
return lazypipe ( )
151
151
@@ -204,7 +204,7 @@ var cssTasks = function(filename) {
204
204
* .pipe(gulp.dest(path.base.dist + 'scripts'))
205
205
* ```
206
206
*/
207
- var jsTasks = function ( filename ) {
207
+ const jsTasks = filename => {
208
208
209
209
updateTimestamp ( 'js' ) ;
210
210
@@ -241,18 +241,18 @@ var jsTasks = function(filename) {
241
241
* By default this task will only log a warning if a precompiler error is
242
242
* raised. If the `--production` flag is set: this task will fail outright.
243
243
*/
244
- gulp . task ( 'styles' , [ ] , function ( ) {
244
+ function styles ( ) {
245
245
246
- var merged = merge ( ) ;
246
+ const merged = merge ( ) ;
247
247
248
248
// update last-edited.json
249
249
updateTimestamp ( 'css' ) ;
250
250
251
251
// process all assets
252
252
for ( i = 0 ; i < cssAssets . length ; i ++ ) {
253
253
254
- var asset = cssAssets [ i ] ;
255
- var cssTasksInstance = cssTasks ( asset . name ) ;
254
+ let asset = cssAssets [ i ] ;
255
+ const cssTasksInstance = cssTasks ( asset . name ) ;
256
256
257
257
// handle possible errors
258
258
if ( ! enabled . failStyleTask ) {
@@ -275,24 +275,24 @@ gulp.task('styles', [], function() {
275
275
. pipe ( gulp . dest ( path . styles . dist ) )
276
276
. pipe ( browsersync . stream ( { match : '**/*.css' } ) ) ;
277
277
278
- } ) ;
278
+ } ;
279
279
280
+ exports . styles = styles ;
280
281
281
282
/**
282
283
* Task: Scripts
283
284
*
284
285
* `gulp scripts` - Runs JSHint then compiles, combines, and optimizes JS.
285
286
*/
286
- gulp . task ( 'scripts' , [ 'jshint' ] , function ( ) {
287
-
288
- var merged = merge ( ) ;
287
+ function scripts ( ) {
288
+ const merged = merge ( ) ;
289
289
290
290
// process all assets
291
291
for ( i = 0 ; i < jsAssets . length ; i ++ ) {
292
292
293
- var asset = jsAssets [ i ] ;
293
+ let asset = jsAssets [ i ] ;
294
294
295
- var jsTasksInstance = jsTasks ( asset . name ) ;
295
+ const jsTasksInstance = jsTasks ( asset . name ) ;
296
296
297
297
merged . add (
298
298
gulp . src ( asset . globs , { base : 'scripts' } )
@@ -309,16 +309,17 @@ gulp.task('scripts', ['jshint'], function() {
309
309
. pipe ( gulp . dest ( path . scripts . dist ) )
310
310
. pipe ( browsersync . stream ( { match : '**/*.js' } ) ) ;
311
311
312
- } ) ;
312
+ } ;
313
+
314
+ exports . scripts = scripts ;
313
315
314
316
/**
315
317
* Task: Fonts
316
318
*
317
319
* `gulp fonts` - Grabs all the fonts and outputs them in a flattened directory
318
320
* structure. See: https://github.com/armed/gulp-flatten
319
321
*/
320
- gulp . task ( 'fonts' , function ( ) {
321
-
322
+ function fonts ( ) {
322
323
return gulp . src ( [ path . fonts . source + '**/*' ] )
323
324
324
325
// flatten directory structures
@@ -330,14 +331,15 @@ gulp.task('fonts', function() {
330
331
// browsersync result
331
332
. pipe ( browsersync . stream ( ) ) ;
332
333
333
- } ) ;
334
+ } ;
335
+ exports . fonts = fonts ;
334
336
335
337
/**
336
338
* Task: Images
337
339
*
338
340
* `gulp images` - Run lossless compression on all the images.
339
341
*/
340
- gulp . task ( 'images' , function ( ) {
342
+ function images ( ) {
341
343
342
344
return gulp . src ( [ path . images . source + '**/*' ] )
343
345
@@ -354,14 +356,16 @@ gulp.task('images', function() {
354
356
// browsersync result
355
357
. pipe ( browsersync . stream ( ) ) ;
356
358
357
- } ) ;
359
+ } ;
360
+
361
+ exports . images = images ;
358
362
359
363
/**
360
364
* Task: Svgstore
361
365
*
362
366
* Create a single sprite.svg file from files in /assets/sprite/.
363
367
*/
364
- gulp . task ( 'svgstore' , function ( ) {
368
+ function svgstore ( ) {
365
369
366
370
updateTimestamp ( 'svg' ) ;
367
371
@@ -380,18 +384,21 @@ gulp.task('svgstore', function () {
380
384
// browsersync result
381
385
. pipe ( browsersync . stream ( ) ) ;
382
386
383
- } ) ;
387
+ } ;
388
+
389
+ exports . svgstore = svgstore ;
384
390
385
391
/**
386
392
* Task: JSHint
387
393
*
388
394
* `gulp jshint` - Lints configuration JSON and project JS.
389
395
*/
390
- gulp . task ( 'jshint' , function ( ) {
391
396
392
- var allJS = [ ] ;
397
+ function jshint ( ) {
398
+
399
+ let allJS = [ ] ;
393
400
for ( i = 0 ; i < jsAssets . length ; i ++ ) {
394
- var globsArray = jsAssets [ i ] . globs ;
401
+ let globsArray = jsAssets [ i ] . globs ;
395
402
for ( j = 0 ; j < globsArray . length ; j ++ ) {
396
403
allJS . push ( globsArray [ j ] ) ;
397
404
}
@@ -404,14 +411,16 @@ gulp.task('jshint', function() {
404
411
. pipe ( jshint . reporter ( 'jshint-stylish' ) )
405
412
. pipe ( gulpif ( enabled . failJSHint , jshint . reporter ( 'fail' ) ) ) ;
406
413
407
- } ) ;
414
+ } ;
415
+
416
+ exports . jshint = jshint ;
408
417
409
418
/**
410
419
* Task: Favicon
411
420
*
412
421
* `gulp favicon` - Run lossless compression for favicons.
413
422
*/
414
- gulp . task ( 'favicon' , function ( ) {
423
+ function favicon {
415
424
416
425
return gulp . src ( [ path . favicon . source + '**/*' ] )
417
426
@@ -429,14 +438,20 @@ gulp.task('favicon', function() {
429
438
// send to /dist/favicon
430
439
. pipe ( gulp . dest ( path . favicon . dist ) ) ;
431
440
432
- } ) ;
441
+ } ;
442
+
443
+ exports . favicon = favicon ;
433
444
434
445
/**
435
446
* Task: Clean
436
447
*
437
448
* `gulp clean` - Deletes the build folder entirely.
438
449
*/
439
- gulp . task ( 'clean' , require ( 'del' ) . bind ( null , [ path . base . dist ] ) ) ;
450
+ function clean ( ) {
451
+ require ( 'del' ) . bind ( null , [ path . base . dist ] ) ) ;
452
+ }
453
+
454
+ exports . clean = clean ;
440
455
441
456
/**
442
457
* Task: Watch
@@ -447,35 +462,39 @@ gulp.task('clean', require('del').bind(null, [path.base.dist]));
447
462
* build step for that asset and inject the changes into the page.
448
463
* See: http://www.browsersync.io
449
464
*/
450
- gulp . task ( 'watch' , function ( ) {
451
- var new_tab = 'local' ;
452
- if ( argv . q ) {
453
- new_tab = false ;
454
- }
455
- // browsersync changes
456
- browsersync . init ( {
457
- files : [
458
- '{inc,partials,template-tags}/**/*.php' ,
459
- '*.php'
460
- ] ,
461
- proxy : manifest . devUrl ( ) ,
462
- snippetOptions : {
463
- whitelist : [ '/wp-admin/admin-ajax.php' ] ,
464
- blacklist : [ '/wp-admin/**' ]
465
- } ,
466
- open : new_tab
467
- } ) ;
468
-
469
- // watch these files
470
- gulp . watch ( [ path . styles . source + '**/*' ] , [ 'styles' ] ) ;
471
- gulp . watch ( [ path . scripts . source + '**/*' ] , [ 'jshint' , 'scripts' ] ) ;
472
- gulp . watch ( [ path . fonts . source + '**/*' ] , [ 'fonts' ] ) ;
473
- gulp . watch ( [ path . images . source + '**/*' ] , [ 'images' ] ) ;
474
- gulp . watch ( [ path . sprite . source + '*' ] , [ 'svgstore' ] ) ;
475
- gulp . watch ( [ path . favicon . source + '*' ] , [ 'favicon' ] ) ;
476
- gulp . watch ( [ 'assets/manifest.js' ] , [ 'build' ] ) ;
477
-
478
- } ) ;
465
+ // function watch() {
466
+ // const new_tab = 'local';
467
+ // if(argv.q) {
468
+ // new_tab = false;
469
+ // }
470
+ // // browsersync changes
471
+ // browsersync.init({
472
+ // files: [
473
+ // '{inc,partials,template-tags}/**/*.php',
474
+ // '*.php'
475
+ // ],
476
+ // proxy: manifest.devUrl(),
477
+ // snippetOptions: {
478
+ // whitelist: ['/wp-admin/admin-ajax.php'],
479
+ // blacklist: ['/wp-admin/**']
480
+ // },
481
+ // open: new_tab
482
+ // });
483
+
484
+ // // watch these files
485
+ watch ( [ path . styles . source + '**/*' ] , [ 'styles' ] ) ;
486
+ // gulp.watch([path.scripts.source + '**/*'], ['jshint', 'scripts']);
487
+ // gulp.watch([path.fonts.source + '**/*'], ['fonts']);
488
+ // gulp.watch([path.images.source + '**/*'], ['images']);
489
+ // gulp.watch([path.sprite.source + '*'], ['svgstore']);
490
+ // gulp.watch([path.favicon.source + '*'], ['favicon']);
491
+ // gulp.watch(['assets/manifest.js'], ['build']);
492
+
493
+ // });
494
+
495
+ exports . build = series ( clean , parallel ( styles , scripts ) ) ;
496
+
497
+ // exports.watch = watch;
479
498
480
499
/**
481
500
* Task: Build
0 commit comments