-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.js
More file actions
279 lines (225 loc) · 8.4 KB
/
gulpfile.js
File metadata and controls
279 lines (225 loc) · 8.4 KB
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
const gulp = require('gulp');
const zip = require('gulp-zip');
const wpPot = require('gulp-wp-pot');
const sourcemaps = require('gulp-sourcemaps');
const sass = require('gulp-sass')(require('sass'));
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const notify = require('gulp-notify');
const plumber = require('gulp-plumber');
const rename = require('gulp-rename');
const shell = require('gulp-shell');
/*
===========================================================
=
= Change these constants according to your need
=
====================================================
*/
// #1 base script files path
var base__script__path = {
base__script__src: [
'./assets/src/js/jQuery/*.js',
'./assets/src/js/libs/*.js',
'./assets/src/js/scripts/*.js',
'!./assets/src/js/conditional/*.js',
'!./assets/src/js/compatibility/*.js',
],
base__script__build__path: "./assets/build/js/",
}
var compiled__base__script_build = "xenial-script.js";
// #1.1 base script files path
var compatibility__script__path = {
compatibility__script__src: [
'./assets/src/js/compatibility/*.js',
],
compatibility__script__build__path: "./assets/build/js/compatibility/",
}
// #2 base sass files path
var base__sass__path = {
base__sass__src: [
"./assets/src/scss/**/*.scss",
"!./assets/src/scss/woocommerce/**",
"!./assets/src/scss/compatibility/**",
],
base__sass__build__path: "./assets/build/css/",
}
var compiled__base__sass__build__name = "xenial-style.css"; // what would you like to name your compiled CSS file
// #2.1 woocommerce sass file path
var woocommerce__sass__path = {
woocommerce__sass__src: [
"./assets/src/scss/woocommerce/**"
],
compiled__woocommerce__sass__build__path: "./assets/build/css/woocommerce/",
}
var compiled__woocommerce__sass__build__name = 'woocommerce.css';
// #2.3 compatibility sass file path
var compatibility__sass__path = {
compatibility__sass__src: [
"./assets/src/scss/compatibility/**"
],
compiled__compatibility__sass__build__path: "./assets/build/css/compatibility/",
}
// #3 path of php files to generate WordPress POT file
var project__name = 'Xenial';
var project__text__domain = 'xenial';
var php__file__path = [
'./*.php',
'./**.php',
'./**/*.php',
'!./github/**',
'!./node_modules/*.php',
'!./.git/*.php',
'!./inc/plugin-recommendation.php',
'!./third-party/class-tgm-plugin-activation.php',
]
// #4 zip files & folders for production
var output__compressed__file = 'xenial.zip';
const source__files__folders__to__compress = {
source__files__folders: [
'./*',
'./*/**',
'!./.gitignore',
'!./.github/**',
'!./.vscode',
'!./assets/src/**',
'!./gulpfile.js',
'!./package.json',
'!./package-lock.json',
'!./node_modules/**',
'!./composer.json',
'!./composer.lock',
'!./sftp-config.json'
],
path__to__save__production__zip: "./",
}
/*
===========================================================
=
= Define task (Almost no changes required)
=
====================================================
*/
// # 1 Base script task
gulp.task('baseScriptsTask', function () {
return gulp.src(base__script__path.base__script__src)
.pipe(concat(compiled__base__script_build))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest(base__script__path.base__script__build__path));
});
// # 1.1 Compatibility script task
gulp.task('compatibilityScriptsTask', function () {
return gulp.src(compatibility__script__path.compatibility__script__src)
//.pipe(concat())
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest(compatibility__script__path.compatibility__script__build__path));
});
// # 2 Base SASS task
gulp.task('baseSassTask', function () {
var onError = function (err) {
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
return gulp.src(base__sass__path.base__sass__src)
.pipe(sourcemaps.init())
.pipe(plumber({ errorHandler: onError }))
.pipe(sass.sync().on('error', sass.logError))
.pipe(postcss([autoprefixer('last 2 version'), cssnano()])) // PostCSS plugins
.pipe(concat(compiled__base__sass__build__name))
.pipe(sourcemaps.write('.')) // write sourcemaps file in current directory
.pipe(gulp.dest(base__sass__path.base__sass__build__path)); // put final CSS in build folder
});
// # 2.1 WooCommerce SASS task
gulp.task('woocommerceSassTask', function () {
var onError = function (err) {
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
return gulp.src(woocommerce__sass__path.woocommerce__sass__src)
.pipe(sourcemaps.init())
.pipe(plumber({ errorHandler: onError }))
.pipe(sass.sync().on('error', sass.logError))
.pipe(postcss([autoprefixer('last 2 version'), cssnano()]))
.pipe(concat(compiled__woocommerce__sass__build__name))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(woocommerce__sass__path.compiled__woocommerce__sass__build__path));
});
// # 2.2 Compatibility SASS task
gulp.task('compatibilitySassTask', function () {
var onError = function (err) {
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
return gulp.src(compatibility__sass__path.compatibility__sass__src)
.pipe(sourcemaps.init())
.pipe(plumber({ errorHandler: onError }))
.pipe(sass.sync().on('error', sass.logError))
.pipe(postcss([autoprefixer('last 2 version'), cssnano()]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(compatibility__sass__path.compiled__compatibility__sass__build__path));
});
// # 3 Generate WordPress POT file
gulp.task('xenialPotFile', function () {
return gulp.src(php__file__path)
.pipe(wpPot({
domain: project__text__domain,
package: project__name
}))
.pipe(gulp.dest('languages/' + project__text__domain + '.pot'));
});
// # 4 Generate Production Zip File
gulp.task('zipProductionFiles', function () {
return gulp.src(source__files__folders__to__compress.source__files__folders)
.pipe(zip(output__compressed__file))
.pipe(gulp.dest(source__files__folders__to__compress.path__to__save__production__zip))
});
//=========================================
// = C O M M A N D S =
//=========================================
//
// 1. Command: gulp zip (zips the production files)
// 2. Command: gulp makepot (will generate language file)
// 3. Command: gulp assets (Compiles all assets)
//
//=========================================
// Run Task: none, just echo message for default command
gulp.task('default', shell.task(
'echo ===== ⛔️ Ooops! gulp default command is disabled in this project. These are the available commands: gulp zip, gulp makepot & gulp assets. =====',
));
// #1 Run Task: Zip production files
gulp.task('zip', gulp.series('zipProductionFiles', (done) => {
done();
}));
// #2 Run Task: Make WordPress POT file
gulp.task('makepot', gulp.series('xenialPotFile', (done) => {
done();
}));
// #3 Run Task: Compile static assets
gulp.task('assets', gulp.series('baseScriptsTask', 'compatibilityScriptsTask', 'baseSassTask', 'woocommerceSassTask', 'compatibilitySassTask', (done) => {
gulp.watch(base__script__path.base__script__src, gulp.series('baseScriptsTask'));
gulp.watch(compatibility__script__path.compatibility__script__src, gulp.series('compatibilityScriptsTask'));
gulp.watch(base__sass__path.base__sass__src, gulp.series('baseSassTask'));
gulp.watch(woocommerce__sass__path.woocommerce__sass__src, gulp.series('woocommerceSassTask'));
gulp.watch(compatibility__sass__path.compatibility__sass__src, gulp.series('compatibilitySassTask'));
done();
}));