-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
169 lines (149 loc) · 3.85 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
const gulp = require("gulp");
const del = require("del");
const rename = require("gulp-rename");
const { resolve } = require("path");
const { ENV } = require("./gulp-tasks/helpers.js");
const buildStylesTask = require("./gulp-tasks/build-styles.js");
const { buildScripts, watchScripts } = require("./gulp-tasks/build-scripts.js");
const devServerTask = require("./gulp-tasks/dev-server.js");
const lintTask = require("./gulp-tasks/lint.js");
const liveReloadTask = require("./gulp-tasks/live-reload.js");
const {
compileCommonPartials,
compileTemplates,
} = require("./gulp-tasks/templates.js");
const isProd = process.env.NODE_ENV === ENV.PROD;
//#region clean
const clean = () =>
del([
"build",
"src/scripts/common/partials/index.js", // removes compiled index file of common partials
"src/scripts/**/*.tmpl", // removes compiled hbs templates
]);
exports.clean = clean;
//#endregion
//#region html:build
const htmlBuild = () => gulp.src("src/index.html").pipe(gulp.dest("build"));
exports.htmlBuild = htmlBuild;
//#endregion
//#region icons:build
const iconsBuild = () =>
gulp
.src("node_modules/feather-icons/dist/feather-sprite.svg")
.pipe(rename("icons.svg"))
.pipe(gulp.dest("build/assets"));
exports.iconsBuild = iconsBuild;
//#endregion
//#region html:watch
const htmlWatch = () => gulp.watch("src/index.html", gulp.series(htmlBuild));
exports.htmlWatch = htmlWatch;
//#endregion
//#region styles:build
const stylesBuild = () => buildStylesTask({ isProd });
exports.stylesBuild = stylesBuild;
//#endregion
//#region styles:watch
const stylesWatch = () =>
gulp.watch("src/styles/**/*.scss", gulp.series(stylesBuild));
exports.stylesWatch = stylesWatch;
//#endregion
//#region templates:build
const templatesBuild = gulp.series(compileCommonPartials, compileTemplates);
exports.templatesBuild = templatesBuild;
//#endregion
//#region scripts:build-js|build-all
const scriptsBuild = async (done) => {
try {
await buildScripts({ isProd });
} catch (err) {
console.error(err); // eslint-disable-line
} finally {
done();
}
};
exports.scriptsBuild = scriptsBuild;
const scriptsBuildWithTemplates = gulp.series(templatesBuild, scriptsBuild);
exports.scriptsBuildWithTemplates = scriptsBuildWithTemplates;
//#endregion
//#region scripts:watch
const scriptsWatch = async (done) => {
try {
await watchScripts();
} catch (err) {
console.error(err); // eslint-disable-line
} finally {
done();
}
};
exports.scriptsWatch = scriptsWatch;
//#endregion
//#region templates:watch
const partialsWatch = () =>
gulp.watch(
"src/scripts/common/partials/**/*.hbs",
gulp.series(compileCommonPartials)
);
const templatesWatch = () =>
gulp.watch(
["src/scripts/**/*.hbs", "!src/scripts/common/partials/**/*.hbs"],
gulp.series(compileTemplates)
);
const watchAllTemplates = gulp.parallel(partialsWatch, templatesWatch);
exports.watchAllTemplates = watchAllTemplates;
//#endregion
//#region watch:all
const watchAll = gulp.parallel(
htmlWatch,
stylesWatch,
watchAllTemplates,
scriptsWatch
);
exports.watchAll = watchAll;
//#endregion
//#region reload
const reload = async () => {
liveReloadTask({
target: resolve("build"),
delay: 300, // ms
});
};
exports.reload = reload;
//#endregion
//#region lint
const lint = () => lintTask({ isProd });
exports.lint = lint;
//#endregion
//#region build
const build = gulp.series(
lint,
clean,
htmlBuild,
iconsBuild,
stylesBuild,
templatesBuild
);
exports.build = build;
//#endregion
//#region dev:server
const devServer = async () => {
devServerTask({
port: 4379,
staticFolder: resolve("build"),
});
};
exports.devServer = devServer;
//#endregion
//#region dev
const dev = gulp.series(
clean,
htmlBuild,
iconsBuild,
stylesBuild,
templatesBuild,
reload,
devServer,
watchAll
);
exports.dev = dev;
//#endregion
exports.default = gulp.series(dev);