-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
70 lines (62 loc) · 1.93 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
// `Colors` doesn't need a local variable
require('colors');
// Imports
const gulp = require('gulp');
const nodemon = require('gulp-nodemon');
const htmlmin = require('gulp-htmlmin');
const watch = require('gulp-watch');
const buildTask = require('./scripts/gulp_build_task');
gulp.task("build-cargo", buildTask('cargo', 'cargo build --bin saemanga --color always'));
gulp.task("build-webpack", buildTask('webpack', 'npx webpack --colors'));
gulp.task("build-templates", (done) => {
var hbAttrWrapOpen = /\{\{#.*\}\}/;
var hbAttrWrapClose = /\{\{\/.*\}\}/;
var hbAttrWrapPair = [hbAttrWrapOpen, hbAttrWrapClose];
return gulp.src('assets/templates/**/*.html.hbs')
.pipe(htmlmin({
collapseWhitespace: true,
customAttrSurround: [hbAttrWrapPair],
}))
.pipe(gulp.dest('templates/'));
});
gulp.task('build', gulp.series(
"build-cargo",
"build-webpack"
));
gulp.task('dev-run', (() => {
let nodemonInstance = undefined;
return (done) => {
if (nodemonInstance) {
nodemonInstance.emit('restart');
} else {
nodemonInstance = nodemon({
done: done,
watch: ["--non-existing-folder--"],
exec: "cargo run",
});
}
}
})());
gulp.task('dev-watch', (done) => {
watch(['src/', 'assets/'], {
read: false,
}, (file) => {
const isRustChange = file.extname === '.rs';
const task = isRustChange ? "build-cargo" : "build-webpack";
// console.log(`${"[dev-watch]".cyan} Detected ${isRustChange ? "back-end" : "front-end"} changes. Rebuilding.`);
gulp.task(task)((err) => {
if (err) {
console.log(`${"[dev-watch]".red} Error detected. Waiting for changes...`);
} else {
gulp.task('dev-run')(done);
}
});
});
});
gulp.task('dev', (done) => {
gulp.task('build')((err) => {
if (err) console.log(`${"[dev]".red} Error detected. Waiting for changes...`);
else gulp.task('dev-run')(done);
gulp.task('dev-watch')(done);
});
});