-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
392 lines (349 loc) · 8.1 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
/**
* Gulp workflow for WordPress
*
* @author Sanjeev Shrestha
* @version 1.0.0
*/
/**
* Load Plugins
*
* Load gulp and it's plugin.
*/
var gulp = require( 'gulp' );
// CSS Plugins
var autoprefixer = require( 'gulp-autoprefixer' ); // Prefixes CSS.
var uglifycss = require( 'gulp-uglifycss' ); // Minifies CSS.
var rtlcss = require( 'gulp-rtlcss' ); // Generates RTL CSS.
var sass = require( 'gulp-sass' ); // Compiles sass into CSS.
// JS Plugins
var uglify = require( 'gulp-uglify' ); // Minify JS.
// Utility Plugins
var browserSync = require( 'browser-sync' ).create(); // Reloads browser.
var imagemin = require( 'gulp-imagemin' ); // Minifies Images.
var rename = require( 'gulp-rename' ); // Renames files.
var wpPot = require( 'gulp-wp-pot' ); // Generates translation file.
var zip = require( 'gulp-zip' ); // Compresses into zip file.
var notify = require( 'gulp-notify' ); // Sends notification.
var readme = require( 'gulp-readme-to-markdown' ); // Genrates readme.md from readme.txt
// Linter Plugins
var stylelint = require( 'gulp-stylelint' ); // Checks for the CSS errors.
var eslint = require( 'gulp-eslint' ); // Checks for the JS errors.
var phpcs = require( 'gulp-phpcs' ); //Checks for the php errors and WordPress standards.
/**
* Project information.
*/
var info = {
name: 'Cenote',
slug: 'cenote',
url: 'https://themegrill.com/themes/cenote',
author: 'ThemeGrill',
authorUrl: 'https://themegrill.com',
authorEmail: '[email protected]',
teamEmail: '[email protected]',
localUrl: 'cenote.local'
};
/**
* Defines paths
*/
var paths = {
scss: {
src: './assets/sass/**/*.scss',
dest: './'
},
adminscss: {
src : './inc/admin/sass/admin.scss',
dest: './inc/admin/css/'
},
css: {
src: [ './assets/css/*.css', '!./assets/css/*.min.css' ],
dest: './assets/css'
},
rtlcss: {
src: [ './style.css' ],
dest: './'
},
prefixStyles: {
src: './*.css',
dest: './'
},
lintFiles: {
php: [
'./*.php',
'./inc/**/*.php',
'!./inc/kirki/**',
'!./inc/tgm-plugin-activation/**',
'./inc/widgets/*.php',
'./template-parts/**/*.php'
],
styles: [ './assets/sass/**/*.scss' ],
js: [ './assets/js/*-custom.js', '!./assets/js/*.min.js' ]
},
js: {
src: [ './assets/js/*.js', '!./assets/js/*.min.js' ],
dest: './assets/js/'
},
php: {
src: [
'./*.php',
'./inc/*.php',
'./inc/customizer/**/*.php',
'./template-parts/**/*.php'
]
},
img: {
src: [ './assets/img/**' ],
dest: './assets/img'
},
zip: {
src: [
'**',
'!vendor',
'!vendor/**',
'!node_modules',
'!node_modules/**',
'!assets/sass',
'!assets/sass/**',
'!dest.xml',
'!dist',
'!dist/**',
'!*.json',
'!*.md',
'!gulpfile.js',
'!composer.lock',
'!phpcs.xml'
],
dest: './dist'
}
};
/**
* Gulp Series Tasks
*
* Run task on series.
*/
// Style tasks
var styles = gulp.series( compileSass, generateRTLCSS, prefixStyles );
// Start a front-end development server.
var server = gulp.series( browserSyncStart, watch );
// Test code
var test = gulp.series( lintPHP, lintJS, lintStyle );
// Build
var build = gulp.series( styles, minifyCSS, minifyJs, generateReadme, generatePotFile, compressZip );
// Start browserSync
function browserSyncStart( cb ) {
browserSync.init(
{
proxy: info.localUrl
},
cb
);
}
// Reloads the browser
function browserSyncReload( cb ) {
browserSync.reload();
cb();
}
// Streams the browser.
function browserSyncStream( cb ) {
browserSync.stream();
cb();
}
// Compiles SCSS into CSS.
function compileSass() {
return gulp
.src( paths.scss.src )
.pipe(
sass( {
indentType: 'tab',
indentWidth: 1,
outputStyle: 'expanded',
linefeed: 'crlf'
} )
)
.pipe( browserSync.stream() )
.pipe( gulp.dest( paths.scss.dest ) )
.on( 'error', notify.onError() );
}
function compileAdminSass() {
return gulp.src( paths.adminscss.src )
.pipe( sass({
indentType: 'tab',
indentWidth: 1,
outputStyle: 'expanded',
linefeed: 'crlf'
} )
.on( 'error', sass.logError) )
.pipe( gulp.dest( paths.adminscss.dest ) )
.pipe( browserSync.stream() );
}
// Prefixes CSS.
function prefixStyles() {
return gulp
.src( paths.prefixStyles.src )
.pipe(
autoprefixer( {
browsers: [ 'last 2 versions' ],
cascade: false
} )
)
.pipe( gulp.dest( paths.prefixStyles.dest ) )
.pipe( browserSync.stream() )
.on( 'error', notify.onError() );
}
// Generates RTL CSS file.
function generateRTLCSS() {
return gulp
.src( paths.rtlcss.src )
.pipe( rtlcss() )
.pipe( rename( { suffix: '-rtl' } ) )
.pipe( gulp.dest( paths.rtlcss.dest ) )
.on( 'error', notify.onError() );
}
// Minify css file
function minifyCSS() {
return gulp
.src( paths.css.src )
.pipe( uglifycss() )
.pipe( rename( { suffix: '.min' } ) )
.pipe( gulp.dest( paths.css.dest ) );
}
// Runs all the task of style.
function styles() {
return gulp.series( compileSass, prefixStyles, generateRTLCSS );
}
// Lint php through phpcs and PHPCompatibility
function lintPHP() {
return gulp
.src( paths.lintFiles.php )
.pipe(
phpcs( {
bin: 'vendor/bin/phpcs',
standard: 'phpcs.xml',
warningSeverity: 0
} )
)
.pipe( phpcs.reporter( 'log' ) )
.pipe( phpcs.reporter( 'fail', { failOnFirst: false } ) )
.on( 'error', notify.onError() );
}
// Lint scss,css file through stylelint
function lintStyle() {
return gulp
.src( paths.lintFiles.styles )
.pipe(
stylelint( {
failAfterError: true,
reporters: [ { formatter: 'string', console: true } ]
} )
)
.on( 'error', notify.onError() );
}
// Lint js files through eslint
function lintJS() {
return gulp
.src( paths.lintFiles.js )
.pipe( eslint() )
.pipe( eslint.format() )
.on( 'error', notify.onError() );
}
// Minfies image files.
function minifyImg() {
return gulp
.src( paths.img.src )
.pipe( imagemin() )
.pipe( gulp.dest( paths.img.dest ) )
.on( 'error', notify.onError() );
}
// Minifies the js files.
function minifyJs() {
return gulp
.src( paths.js.src )
.pipe( uglify() )
.pipe( rename( { suffix: '.min' } ) )
.pipe( gulp.dest( paths.js.dest ) )
.on( 'error', notify.onError() );
}
// Generates readme.md
function generateReadme() {
return gulp
.src( './readme.txt' )
.pipe( readme() )
.pipe( gulp.dest( './' ) );
}
// Generates translation file.
function generatePotFile() {
return gulp
.src( paths.php.src )
.pipe(
wpPot( {
domain: info.slug,
package: info.name,
bugReport: info.authorEmail,
team: info.teamEmail
} )
)
.pipe( gulp.dest( 'languages/' + info.slug + '.pot' ) )
.on( 'error', notify.onError() );
}
// Compress theme into a zip file.
function compressZip() {
return gulp
.src( paths.zip.src )
.pipe( rename( function ( path ) {
path.dirname = info.slug + '/' + path.dirname;
} ) )
.pipe( zip( info.slug + '.zip' ) )
.pipe( gulp.dest( paths.zip.dest ) )
.on( 'error', notify.onError() )
.pipe(
notify( {
message: 'Great! Package is ready',
title : 'Build successful'
} )
);
}
// Watch for file changes
function watch() {
gulp.watch( paths.scss.src, styles );
gulp.watch( paths.adminscss.src, compileAdminSass );
gulp.watch( paths.js.src, browserSyncReload );
gulp.watch( paths.php.src, browserSyncReload );
}
// Builds the package.
function build() {
return gulp.series(
lintPHP,
lintJS,
lintStyle,
compileSass,
prefixStyles,
generateRTLCSS,
minifyCSS,
minifyImg,
minifyJs,
generatePotFile,
compressZip
);
}
// define tasks
exports.browserSyncStart = browserSyncStart;
exports.browserSyncReload = browserSyncReload;
exports.browserSyncStream = browserSyncStream;
exports.compileSass = compileSass;
exports.compileAdminSass = compileAdminSass;
exports.prefixStyles = prefixStyles;
exports.generateRTLCSS = generateRTLCSS;
exports.minifyCSS = minifyCSS;
exports.minifyImg = minifyImg;
exports.minifyJs = minifyJs;
exports.generateReadme = generateReadme;
exports.generatePotFile = generatePotFile;
exports.lintPHP = lintPHP;
exports.lintStyle = lintStyle;
exports.lintJS = lintJS;
exports.compressZip = compressZip;
exports.watch = watch;
exports.styles = styles;
exports.test = test;
exports.server = server;
exports.test = test;
exports.build = build;