-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
180 lines (160 loc) · 4.54 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
/**
* Automating Development Tasks
* ----------------------------
* @package wp-job-openings
* @subpackage docs-viewer-add-on-for-wp-job-openings
* @since 1.0.0
*/
"use strict";
/*============================= Dependencies =============================*/
const gulp = require("gulp-help")(require("gulp")),
config = require("./config"),
concat = require("gulp-concat"),
rename = require("gulp-rename"),
lineEC = require("gulp-line-ending-corrector"),
sourcemaps = require("gulp-sourcemaps"), // Write inline source maps
browserSync = 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 =================================*/
gulp.task("init", false, () => {
console.log("-------------------------------------------");
console.log("<<<<<-------- WP Job Openings -------->>>>>");
console.log("-------------------------------------------");
});
/* --- Tasks: Browsersync --- */
gulp.task(
"browser-sync",
`Initialize Browsersync and proxy ${config.previewURL}`,
() => {
browserSync.init({
ghostMode: false,
proxy: config.previewURL,
notify: false
});
}
);
/* --- Tasks: CSS --- */
function minifyStyles(type) {
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;
let stream = gulp.src(src);
if (config.debug) {
stream = stream.pipe(sourcemaps.init());
}
stream = stream
.pipe(concat(outputName))
.pipe(autoprefixer())
.pipe(cleanCSS({compatibility: "ie9"}))
.pipe(rename({suffix: ".min"}))
.pipe(lineEC());
if (config.debug) {
stream = stream.pipe(sourcemaps.write()).pipe(lineEC());
}
return stream.pipe(gulp.dest(dest));
}
function loadStyles(type) {
let src = config.style[type].dest;
return gulp.src(src + "*.css").pipe(browserSync.stream());
}
for (let type in config.style) {
gulp.task(`${type}-style`, `Concatenate ${type} styles and minify it`, () => {
minifyStyles(type);
});
gulp.task(`load-${type}-styles`, false, [`${type}-style`], () => {
loadStyles(type);
});
}
/* --- Tasks: JS --- */
function minifyScripts(type) {
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);
if (config.debug) {
stream = stream.pipe(sourcemaps.init());
} else {
stream = stream.pipe(stripDebug());
}
stream = stream
.pipe(concat(outputName))
.pipe(uglify())
.pipe(rename({suffix: ".min"}))
.pipe(lineEC());
if (config.debug) {
stream = stream.pipe(sourcemaps.write()).pipe(lineEC());
}
return stream.pipe(gulp.dest(dest));
}
for (let type in config.scripts) {
gulp.task(
`${type}-scripts`,
`Concatenate ${type} js files and minify it`,
() => {
minifyScripts(type);
}
);
gulp.task(`load-${type}-scripts`, false, [`${type}-scripts`], () => {
browserSync.reload();
});
}
/* --- Tasks: i18n --- */
gulp.task("translate", "Generates pot file for plugin localization", () => {
return gulp
.src(["./**/*.php", "!./build/**/*.php"])
.pipe(sort())
.pipe(
wpPot({
domain: config.translation.domain,
package: config.translation.package,
team: config.translation.team
})
)
.pipe(gulp.dest(config.translation.dest));
});
/* --- Tasks: Watch files for any change --- */
gulp.task(
"watch",
"Watch PHP, JS and CSS files for any change",
["init", "browser-sync"],
function() {
gulp.watch("./**/*.php", function() {
browserSync.reload();
});
for (let type in config.style) {
gulp.watch(config.style[type].src + "**/*.css", [`load-${type}-styles`]);
}
for (let type in config.scripts) {
gulp.watch(config.scripts[type].src + "**/*.js", [`load-${type}-scripts`]);
}
}
);
/* --- Tasks: Default tasks --- */
gulp.task("default", false, ["init", "help"]);
/* --- Tasks: Build tasks --- */
gulp.task("build", "Generate CSS and JS files to be included in the plugin", [
"init",
"general-style",
"public-style",
"admin-style",
"public-scripts",
"admin-scripts"
]);