-
Notifications
You must be signed in to change notification settings - Fork 40
/
gulpfile.js
373 lines (343 loc) · 11.2 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
'use strict';
var gulp = require( 'gulp' ),
browserSync = require( 'browser-sync' ).create(),
sass = require( 'gulp-sass' ),
postcss = require( 'gulp-postcss' ),
autoprefixer = require( 'autoprefixer' ),
notify = require( 'gulp-notify' ),
uglifycss = require( 'gulp-uglifycss' ),
rename = require( 'gulp-rename' ),
flatten = require( 'gulp-flatten' ),
concatCss = require( 'gulp-concat-css' ),
concatJS = require( 'gulp-concat' ),
uglify = require( 'gulp-uglify-es' ).default,
rtlcss = require( 'gulp-rtlcss' ),
lec = require( 'gulp-line-ending-corrector' );
// Define paths.
var paths = {
styles : {
src : './assets/sass/**/*.scss',
dest : './'
},
adminStyles : {
src : './inc/admin/sass/*.scss',
dest : './inc/admin/css/'
},
js : {
src : [
'./assets/js/*.js',
'!./assets/js/*.min.js',
'./assets/js/**/*.js',
'!./assets/js/**/*.min.js'
],
dest : './assets/js/'
},
customizePreviewJS : {
src : [
'./inc/customizer/assets/js/*.js',
'!./inc/customizer/assets/js/*.min.js',
],
dest : './inc/customizer/assets/js/',
},
elementorStyles : {
scss : {
src : './inc/elementor/assets/SCSS/**/*.scss',
dest : './inc/elementor/assets/css/'
},
cssmin : {
src : [
'./inc/elementor/assets/css/*.css',
'!./inc/elementor/assets/css/*.min.css',
'!./inc/elementor/assets/css/*-rtl.css'
],
dest : './inc/elementor/assets/css/'
}
},
elementorJS : {
jsmin : {
src : [
'./inc/elementor/assets/js/**/*.js',
'!./inc/elementor/assets/js/**/*.min.js'
],
dest : './inc/elementor/assets/js/'
}
},
metaBoxes : {
scss : {
src : './inc/meta-boxes/assets/scss/*.scss',
dest : './inc/meta-boxes/assets/css'
},
cssmin : {
src : [
'./inc/meta-boxes/assets/css/*.css',
'!./inc/meta-boxes/assets/css/*.min.css',
'!./inc/meta-boxes/assets/css/*-rtl.css'
],
dest : './inc/meta-boxes/assets/css'
},
jsmin : {
src : [
'./inc/meta-boxes/assets/js/*.js',
'!./inc/meta-boxes/assets/js/*.min.js'
],
dest : './inc/meta-boxes/assets/js'
}
},
rtlcss : {
style : {
src : [ './style.css' ],
dest : './'
},
woocommerceStyle : {
src : [ './woocommerce.css' ],
dest : './'
},
blockStyle : {
src : [ './style-editor-block.css' ],
dest : './'
},
elementorStyles : {
src : [
'./inc/compatibility/elementor/assets/css/elementor.css',
'./inc/compatibility/elementor/assets/css/elementor.min.css'
],
dest : './inc/compatibility/elementor/assets/css'
},
metaBoxes : {
src : [
'./inc/meta-boxes/assets/css/meta-boxes.css',
'./inc/meta-boxes/assets/css/meta-boxes.min.css'
],
dest : './inc/meta-boxes/assets/css'
}
}
};
// Start browserSync.
function browserSyncStart( cb ) {
browserSync.init( {
proxy : 'colormag.local/colormag'
}, cb );
}
// Reloads the browser.
function browserSyncReload( cb ) {
browserSync.reload();
cb();
}
// Compiles SASS into CSS.
function sassCompile() {
return gulp.src( paths.styles.src )
.pipe( sass( {
indentType : 'tab',
indentWidth : 1,
outputStyle : 'expanded',
linefeed : 'crlf'
} ).on( 'error', sass.logError ) )
.pipe( postcss( [
autoprefixer( {
browsers : [ 'last 2 versions' ],
cascade : false
} )
] ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.styles.dest ) );
}
// Compiles Admin SASS into CSS.
function adminSassCompile() {
return gulp.src( paths.adminStyles.src )
.pipe( sass( {
indentType : 'tab',
indentWidth : 1,
outputStyle : 'expanded',
linefeed : 'crlf'
} ).on( 'error', sass.logError ) )
.pipe( postcss( [
autoprefixer( {
browsers : [ 'last 2 versions' ],
cascade : false
} )
] ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.adminStyles.dest ) );
}
function elementorStylesCompile() {
return gulp.src( paths.elementorStyles.scss.src )
.pipe( sass( {
indentType : 'tab',
indentWidth : 1,
outputStyle : 'expanded',
linefeed : 'crlf'
} ).on( 'error', sass.logError ) )
.pipe( postcss( [
autoprefixer( {
browsers : [ 'last 2 versions' ],
cascade : false
} )
] ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.elementorStyles.scss.dest ) );
}
// Minifies the elementor js files.
function minifyelementorJs() {
return gulp
.src( paths.elementorJS.jsmin.src )
.pipe( uglify() )
.pipe( rename( { suffix : '.min' } ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.elementorJS.jsmin.dest ) )
.on( 'error', notify.onError() );
}
// Minify elementor styles css file.
function minifyelementorStyles() {
return gulp
.src( paths.elementorStyles.cssmin.src )
.pipe( uglifycss() )
.pipe( rename( { suffix : '.min' } ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.elementorStyles.cssmin.dest ) );
}
// Minifies the js files.
function minifyJs() {
return gulp
.src( paths.js.src )
.pipe( uglify() )
.pipe( rename( { suffix : '.min' } ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.js.dest ) )
.on( 'error', notify.onError() );
}
// Minifies the customizer js files.
function minifyCustomizerJs() {
return gulp
.src( paths.customizePreviewJS.src )
.pipe( uglify() )
.pipe( rename( { suffix : '.min' } ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.customizePreviewJS.dest ) )
.on( 'error', notify.onError() );
}
// Compile meta boxes styles.
function compileMetaBoxSass() {
return gulp
.src( paths.metaBoxes.scss.src )
.pipe( sass( {
indentType : 'tab',
indentWidth : 1,
outputStyle : 'expanded',
linefeed : 'crlf'
} ).on( 'error', sass.logError ) )
.pipe( postcss( [
autoprefixer( {
browsers : [ 'last 2 versions' ],
cascade : false
} )
] ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.metaBoxes.scss.dest ) )
.on( 'error', notify.onError() );
}
// Minify meta box css file.
function minifyMetaBoxCSS() {
return gulp
.src( paths.metaBoxes.cssmin.src )
.pipe( uglifycss() )
.pipe( rename( { suffix : '.min' } ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.metaBoxes.cssmin.dest ) );
}
// Minifies the metabox js files.
function minifyMetaBoxJs() {
return gulp
.src( paths.metaBoxes.jsmin.src )
.pipe( uglify() )
.pipe( rename( { suffix : '.min' } ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.metaBoxes.jsmin.dest ) )
.on( 'error', notify.onError() );
}
// Generates RTL CSS file.
function generateRTLCSS() {
return gulp
.src( paths.rtlcss.style.src )
.pipe( rtlcss() )
.pipe( rename( { suffix: '-rtl' } ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.rtlcss.style.dest ) )
.on( 'error', notify.onError() );
}
// Generates Block Style RTL CSS file.
function generateBlockStyleRTLCSS() {
return gulp
.src( paths.rtlcss.blockStyle.src )
.pipe( rtlcss() )
.pipe( rename( { suffix: '-rtl' } ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.rtlcss.blockStyle.dest ) )
.on( 'error', notify.onError() );
}
// Generates Elementor RTL CSS file.
function generateElementorRTLCSS() {
return gulp
.src( paths.rtlcss.elementorStyles.src )
.pipe( rtlcss() )
.pipe( rename( { suffix: '-rtl' } ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.rtlcss.elementorStyles.dest ) )
.on( 'error', notify.onError() );
}
// Generates Meta Boxes RTL CSS file.
function generateMetaBoxesRTLCSS() {
return gulp
.src( paths.rtlcss.metaBoxes.src )
.pipe( rtlcss() )
.pipe( rename( { suffix: '-rtl' } ) )
.pipe( lec( { verbose : true, eolc : 'LF', encoding : 'utf8' } ) )
.pipe( gulp.dest( paths.rtlcss.metaBoxes.dest ) )
.on( 'error', notify.onError() );
}
// Watch for file changes.
function watch() {
gulp.watch( paths.styles.src, sassCompile );
gulp.watch( paths.adminStyles.src, adminSassCompile );
gulp.watch( paths.elementorStyles.scss.src, elementorStylesCompile );
gulp.watch( paths.elementorStyles.cssmin.src, minifyelementorStyles );
gulp.watch( paths.elementorJS.jsmin.src, minifyelementorJs );
gulp.watch( paths.js.src, minifyJs );
gulp.watch( paths.js.src, minifyCustomizerJs );
gulp.watch( paths.metaBoxes.scss.src, compileMetaBoxSass );
gulp.watch( paths.metaBoxes.cssmin.src, minifyMetaBoxCSS );
gulp.watch( paths.metaBoxes.jsmin.src, minifyMetaBoxJs );
gulp.watch( paths.rtlcss.style.src, generateRTLCSS );
gulp.watch( paths.rtlcss.blockStyle.src, generateBlockStyleRTLCSS );
gulp.watch( paths.rtlcss.elementorStyles.src, generateElementorRTLCSS );
gulp.watch( paths.rtlcss.metaBoxes.src, generateMetaBoxesRTLCSS );
}
// Define series of tasks.
var server = gulp.series( browserSyncStart, watch ),
styles = gulp.series( sassCompile, adminSassCompile, generateRTLCSS, generateBlockStyleRTLCSS ),
scripts = gulp.series( minifyJs ),
elementorStyles = gulp.series( elementorStylesCompile, minifyelementorStyles, minifyelementorJs, generateElementorRTLCSS ),
metaBoxes = gulp.series( compileMetaBoxSass, minifyMetaBoxCSS, minifyMetaBoxJs, generateMetaBoxesRTLCSS ),
compile = gulp.series( styles, scripts, elementorStyles, metaBoxes );
exports.browserSyncStart = browserSyncStart;
exports.browserSyncReload = browserSyncReload;
exports.sassCompile = sassCompile;
exports.adminSassCompile = adminSassCompile;
exports.elementorStylesCompile = elementorStylesCompile;
exports.minifyelementorStyles = minifyelementorStyles;
exports.minifyelementorJs = minifyelementorJs;
exports.watch = watch;
exports.server = server;
exports.styles = styles;
exports.scripts = scripts;
exports.elementorStyles = elementorStyles;
exports.metaBoxes = metaBoxes;
exports.compile = compile;
exports.minifyJs = minifyJs;
exports.minifyCustomizerJs = minifyCustomizerJs;
exports.compileMetaBoxSass = compileMetaBoxSass;
exports.minifyMetaBoxCSS = minifyMetaBoxCSS;
exports.minifyMetaBoxJs = minifyMetaBoxJs;
exports.generateRTLCSS = generateRTLCSS;
exports.generateBlockStyleRTLCSS = generateBlockStyleRTLCSS;
exports.generateElementorRTLCSS = generateElementorRTLCSS;
exports.generateMetaBoxesRTLCSS = generateMetaBoxesRTLCSS;