-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
79 lines (59 loc) · 1.66 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
const gulp = require("gulp");
const browserify = require("browserify");
const source = require("vinyl-source-stream");
const exec = require("child_process").exec;
const browserSync = require("browser-sync").create();
const destDir = "./dist/";
const srcDir = "./src/";
const mainJs = "main.js";
const to_copy =
[
// "./src/main.js",
"./src/index.html",
"./src/style.css"
];
function gen_parser(callback) {
exec(
"npx nearleyc " + srcDir + "grammar.ne -o " + srcDir + "grammar.js",
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
callback(err);
}
);
}
function copy(file) {
return gulp.src(file).pipe(gulp.dest(destDir));
}
async function copy_all() {
to_copy.forEach(file => {
copy(file);
});
await Promise.resolve("ignore");
}
// https://github.com/browserify/browserify#usage
// https://coderwall.com/p/0vlbxq/using-gulp-with-browserify-and-watchify
function my_browserify() {
return browserify({
entries: [mainJs],
// require: "./dist/grammar.js",
basedir: srcDir,
fullPaths: true,
debug: true
})
.bundle()
.pipe(source("bundle.js"))
.pipe(gulp.dest(destDir));
}
function watch() {
gulp.series([copy_all, gen_parser, my_browserify])
gulp.watch(srcDir + "*.ne", gulp.series([gen_parser, my_browserify]));
gulp.watch(srcDir + "*.js", gulp.series(copy_all, my_browserify));
gulp.watch([srcDir + "*.html", srcDir + "*.css"], gulp.series(copy_all));
}
exports.rebuild = gulp.series(copy_all, gen_parser, my_browserify)
exports.copy_all = copy_all;
exports.copy = copy;
exports.my_browserify = my_browserify;
exports.gen_parser = gen_parser;
exports.watch = watch;