-
Notifications
You must be signed in to change notification settings - Fork 14
/
gulpfile.js
191 lines (165 loc) · 4.62 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
/**
* Automating Development Tasks
* ----------------------------
* @package wp-job-openings
* @since 1.0.0
*/
"use strict";
/*============================= Dependencies =============================*/
const gulp = require("gulp"),
config = require("./config"),
concat = require("gulp-concat"),
rename = require("gulp-rename"),
lineEC = require("gulp-line-ending-corrector"),
bs = require("browser-sync").create();
/* --- Dependencies: css --- */
const cleanCSS = require("gulp-clean-css"), // Minify CSS
autoprefixer = require("gulp-autoprefixer");
/* --- Dependencies: js --- */
const uglify = require("gulp-uglify"), // Minify JavaScript
stripDebug = require("gulp-strip-debug"); // Remove debugging stuffs
/* --- Dependencies: i18n --- */
const wpPot = require("gulp-wp-pot"),
sort = require("gulp-sort");
/*================================= Tasks =================================*/
let init = cb => {
console.log("-------------------------------------------");
console.log("<<<<<-------- WP Job Openings -------->>>>>");
console.log("-------------------------------------------");
cb();
};
/* --- Tasks: Browsersync --- */
let browserSync = cb => {
bs.init({
ghostMode: false,
proxy: config.previewURL,
notify: false
});
cb();
};
let bsReload = cb => {
bs.reload();
cb();
};
browserSync.description = `Initialize Browsersync and proxy ${config.previewURL}`;
gulp.task("browser-sync", browserSync);
/* --- Tasks: CSS --- */
for (let type in config.style) {
let styleTask = () => {
let src =
type === "general"
? [config.style.general.src + "*.css"]
: [
config.style[type].src + "vendors/*.css",
config.style[type].src + "includes/*.css",
config.style[type].src + "*.css"
];
let outputName = config.style[type].outputName;
let dest = config.style[type].dest;
return gulp
.src(src, {sourcemaps: config.debug ? true : false})
.pipe(concat(outputName))
.pipe(autoprefixer())
.pipe(cleanCSS({compatibility: "ie9"}))
.pipe(rename({suffix: ".min"}))
.pipe(lineEC())
.pipe(gulp.dest(dest, {sourcemaps: config.debug ? "." : false}));
};
let loadStyleTask = () => {
let src = config.style[type].dest;
return gulp.src(src + "*.css").pipe(bs.stream());
};
styleTask.description = `Concatenate ${type} styles and minify it`;
gulp.task(`${type}-style`, styleTask);
gulp.task(`load-${type}-styles`, gulp.series(`${type}-style`, loadStyleTask));
}
/* --- Tasks: JS --- */
for (let type in config.scripts) {
let scriptTask = () => {
let src = [
config.scripts[type].src + "vendors/*.js",
config.scripts[type].src + "*.js"
];
let outputName = config.scripts[type].outputName;
let dest = config.scripts[type].dest;
let stream = gulp.src(src, {sourcemaps: config.debug ? true : false});
if (!config.debug) {
stream = stream.pipe(stripDebug());
}
stream = stream
.pipe(concat(outputName))
.pipe(uglify())
.pipe(rename({suffix: ".min"}))
.pipe(lineEC())
.pipe(gulp.dest(dest, {sourcemaps: config.debug ? "." : false}));
return stream;
};
scriptTask.description = `Concatenate ${type} js files and minify it`;
gulp.task(`${type}-scripts`, scriptTask);
gulp.task(`load-${type}-scripts`, gulp.series(`${type}-scripts`, bsReload));
}
/* --- Tasks: i18n --- */
let i18n = () => {
return gulp
.src(["./**/*.php", "!./build/**/*.php", "!./vendor/**/*.php"])
.pipe(sort())
.pipe(
wpPot({
domain: config.translation.domain,
package: config.translation.package,
team: config.translation.team
})
)
.pipe(gulp.dest(config.translation.dest));
};
i18n.description = "Generates pot file for plugin localization";
gulp.task("translate", i18n);
/* --- Generic Tasks --- */
const genericTasks = [
"general-style",
"public-style",
"admin-style",
"admin-global-style",
"admin-overview-style",
"public-scripts",
"admin-scripts",
"admin-overview-scripts"
];
/* --- Tasks: Watch files for any change --- */
let watchFiles = () => {
gulp.watch("./**/*.php", bsReload);
for (let type in config.style) {
gulp.watch(
config.style[type].src + "**/*.css",
gulp.series(`load-${type}-styles`)
);
}
for (let type in config.scripts) {
gulp.watch(
config.scripts[type].src + "**/*.js",
gulp.series(`load-${type}-scripts`)
);
}
};
watchFiles.description = "Watch PHP, JS and CSS files for any change";
gulp.task(
"watch",
gulp.series(browserSync, gulp.parallel(...genericTasks), watchFiles)
);
/* --- Tasks: Default tasks --- */
gulp.task(
"default",
gulp.series(
init,
gulp.parallel(...genericTasks),
browserSync
)
);
/* --- Tasks: Build tasks --- */
gulp.task(
"build",
gulp.series(
init,
gulp.parallel(...genericTasks)
)
);