-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
198 lines (185 loc) · 4.88 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
// External packages.
const gulp = require("gulp"),
rename = require("gulp-rename"),
sass = require('gulp-sass')(require('sass')),
wpPot = require("gulp-wp-pot"),
babel = require("gulp-babel"),
uglify = require("gulp-uglify"),
uglifycss = require("gulp-uglifycss"),
zip = require("gulp-zip");
// Paths.
const paths = {
styles: {
frontend: {
src: "assets/src/scss/frontend/",
dist: "assets/dist/css/frontend/"
},
admin: {
src: "assets/src/scss/admin/",
dist: "assets/dist/css/admin/"
}
},
scripts: {
frontend: {
src: "assets/src/js/frontend/",
dist: "assets/dist/js/frontend/"
},
admin: {
src: "assets/src/js/admin/",
dist: "assets/dist/js/admin/"
}
},
locale: "languages/",
node: "node_modules/"
};
const copyBootstrapCss = () => {
return gulp.src(paths.node + 'bootstrap/dist/css/*.*')
.pipe(gulp.dest(paths.styles.admin.dist));
};
const copyBootstrapJs = () => {
return gulp.src(paths.node + 'bootstrap/dist/js/*.*')
.pipe(gulp.dest(paths.scripts.admin.dist));
};
const copyJqueryValidationJs = () => {
return gulp.src(paths.node + 'jquery-validation/dist/*.js')
.pipe(gulp.dest(paths.scripts.admin.dist));
};
const copyJqueryBsWizardJs = () => {
return gulp.src(paths.node + 'jquery-bootstrap-wizard/jquery.bootstrap.wizard*.js')
.pipe(gulp.dest(paths.scripts.admin.dist));
};
// Task: compile public styles.
const compileScss = () => {
return gulp
.src([paths.styles.frontend.src + "**/*.scss"])
.pipe(sass().on('error', sass.logError))
.pipe(rename({ extname: ".css" }))
.pipe(gulp.dest(paths.styles.frontend.dist));
};
// Task: minify public styles.
const minifyCss = () => {
return gulp
.src([
paths.styles.frontend.dist + "**/*.css",
"!" + paths.styles.frontend.dist + "**/*.min.css"
])
.pipe(
uglifycss({
uglyComments: true
})
)
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest(paths.styles.frontend.dist));
};
// Task: compile public scripts.
const compileJs = () => {
return gulp
.src([paths.scripts.frontend.src + "**/*.js"])
.pipe(
babel({
presets: ["@babel/env"]
})
)
.pipe(gulp.dest(paths.scripts.frontend.dist));
};
// Task: minify public scripts.
const minifyJs = () => {
return gulp
.src([
paths.scripts.frontend.dist + "**/*.js",
"!" + paths.scripts.frontend.dist + "**/*.min.js"
])
.pipe(uglify())
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest(paths.scripts.frontend.dist));
};
// Task: compile admin styles.
const compileAdminScss = () => {
return gulp
.src([paths.styles.admin.src + "**/*.scss"])
.pipe(sass().on('error', sass.logError))
.pipe(rename({ extname: ".css" }))
.pipe(gulp.dest(paths.styles.admin.dist));
};
// Task: minify admin styles.
const minifyAdminCss = () => {
return gulp
.src([
paths.styles.admin.dist + "**/*.css",
"!" + paths.styles.admin.dist + "**/*.min.css"
])
.pipe(
uglifycss({
uglyComments: true
})
)
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest(paths.styles.admin.dist));
};
// Task: compile admin scripts.
const compileAdminJs = () => {
return gulp
.src([paths.scripts.admin.src + "**/*.js"])
.pipe(
babel({
presets: ["@babel/env"]
})
)
.pipe(gulp.dest(paths.scripts.admin.dist));
};
// Task: minify admin scripts.
const minifyAdminJs = () => {
return gulp
.src([
paths.scripts.admin.dist + "**/*.js",
"!" + paths.scripts.admin.dist + "**/*.min.js"
])
.pipe(uglify())
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest(paths.scripts.admin.dist));
};
// Generate localization file.
const generatePot = () => {
return gulp
.src(["**/*.php", "!vendor/", "!tests/", "!docker/"])
.pipe(
wpPot({
domain: "trackmage",
package: "TrackMage"
})
)
.pipe(gulp.dest(paths.locale + "trackmage.pot"));
};
gulp.task("generatePot", generatePot);
// Watch for changes.
const watchChanges = () => {
gulp.watch(
[paths.styles.frontend.src + "**/*.scss"],
gulp.series(compileScss, minifyCss)
);
gulp.watch(
paths.styles.admin.src + "**/*.scss",
gulp.series(compileAdminScss, minifyAdminCss)
);
gulp.watch(
[paths.scripts.frontend.src + "**/*.js"],
gulp.series(compileJs, minifyJs)
);
gulp.watch(
paths.scripts.admin.src + "**/*.js",
gulp.series(compileAdminJs, minifyAdminJs)
);
};
watchChanges.description = "Watch for changes to all sources.";
gulp.task("watch", watchChanges);
// Build everything.
gulp.task(
"build",
gulp.parallel(
// generatePot,
gulp.series(compileScss, minifyCss, copyBootstrapCss),
gulp.series(compileAdminScss, minifyAdminCss, copyBootstrapJs),
gulp.series(compileJs, minifyJs, copyJqueryValidationJs),
gulp.series(compileAdminJs, minifyAdminJs, copyJqueryBsWizardJs)
)
);