1+ 'use strict' ;
2+
3+ import { src , dest , watch , series , parallel } from 'gulp' ;
4+ import postcss from 'gulp-postcss' ;
5+ import sourcemaps from 'gulp-sourcemaps' ;
6+ import minify from 'gulp-terser' ;
7+ import zip from 'gulp-zip' ;
8+
9+ // PostCSS Plugins
10+ import postcssImport from 'postcss-import' ;
11+ import postcssNested from 'postcss-nested' ;
12+ import postcssCustomProperties from 'postcss-custom-properties' ;
13+ import postcssNormalize from 'postcss-normalize' ;
14+ import postcssSortMediaQueries from 'postcss-sort-media-queries' ;
15+ import autoprefixer from 'autoprefixer' ;
16+ import cssnano from 'cssnano' ;
17+
18+
19+ const paths = {
20+ styles : {
21+ src : [ 'assets/styles/*.css' , '!assets/styles/variables.css' ] ,
22+ dest : 'assets/styles/build/' ,
23+ watch : [ 'assets/styles/**/*.css' , '!assets/styles/build/**' ]
24+ } ,
25+ scripts : {
26+ src : 'assets/scripts/*.js' ,
27+ dest : 'assets/scripts/build/' ,
28+ watch : [ 'assets/scripts/**/*.css' , '!assets/scripts/build/**' ]
29+ }
30+ } ;
31+
32+ function styles ( ) {
33+ const processors = [
34+ postcssImport ( ) ,
35+ postcssNested ( ) ,
36+ postcssCustomProperties ( ) ,
37+ postcssNormalize ( { forceImport : true } ) ,
38+ postcssSortMediaQueries ( ) ,
39+ autoprefixer ( ) ,
40+ cssnano ( {
41+ preset : [
42+ 'default' ,
43+ {
44+ calc : false ,
45+ mergeLonghand : false // These conflict with processing nested calc() and env values().
46+ }
47+ ]
48+ } )
49+ ] ;
50+ return src ( paths . styles . src )
51+ . pipe ( sourcemaps . init ( ) )
52+ . pipe ( postcss ( processors ) )
53+ . pipe ( sourcemaps . write ( './' ) )
54+ . pipe ( dest ( paths . styles . dest ) ) ;
55+ }
56+
57+ function scripts ( ) {
58+ return src ( paths . scripts . src )
59+ . pipe ( sourcemaps . init ( ) )
60+ . pipe ( minify ( ) )
61+ . pipe ( sourcemaps . write ( './' ) )
62+ . pipe ( dest ( paths . scripts . dest ) ) ;
63+ }
64+
65+ function watchTask ( ) {
66+ watch ( paths . styles . watch , styles ) ;
67+ watch ( paths . scripts . src , scripts ) ;
68+ }
69+
70+ function bundle ( ) {
71+ return src (
72+ [
73+ './*' ,
74+ './assets/**' ,
75+ './locales/**' ,
76+ './partials/**' ,
77+ '!./.*' ,
78+ '!./node_modules' ,
79+ '!./distribution'
80+ ] ,
81+ { base : '.' }
82+ )
83+ . pipe ( zip ( 'decode.zip' ) )
84+ . pipe ( dest ( './distribution' ) ) ;
85+ }
86+
87+ // Workflows
88+ // $ gulp: Builds, prefixes, and minifies CSS files; concatenates and minifies JS files; watches for changes. The works.
89+ const defaultTask = parallel ( styles , scripts , watch ) ;
90+
91+ // $ gulp build: Builds, prefixes, and minifies CSS files; concatenates and minifies JS files. For deployments.
92+ const buildTask = parallel ( styles , scripts ) ;
93+
94+ // $ gulp bundle: Builds and bundles theme into a ZIP for simple theme install.
95+ const bundleTask = series ( buildTask , bundle ) ;
96+
97+ // Exports
98+ export {
99+ styles ,
100+ scripts ,
101+ watchTask as watch ,
102+ buildTask as build ,
103+ bundleTask as bundle
104+ } ;
105+
106+ export default defaultTask ;
0 commit comments