-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.esm.js
More file actions
66 lines (52 loc) · 1.67 KB
/
gulpfile.esm.js
File metadata and controls
66 lines (52 loc) · 1.67 KB
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
import { src, dest, series, watch, task, lastRun } from "gulp";
import ts from "gulp-typescript";
import { ChildProcess, spawn } from "child_process";
import color from "cli-color";
const tsProject = ts.createProject("tsconfig.json");
function transpileTS() {
return src("src/**/*.ts", { since: lastRun(transpileTS) })
.pipe(tsProject())
.pipe(dest("build"))
}
function transpileData() {
return src("src/data/**/*.json", { since: lastRun(transpileData) })
.pipe(dest("build/data"))
}
function transpile(cb) {
series(transpileTS, transpileData)(() => { cb() })
}
/**
* @type {undefined | ChildProcess}
*/
let process = undefined;
let i = 1;
function runServer(cb, rerun = true) {
process = spawn("node", ["build/index.js"], { stdio: 'inherit' });
process.on("spawn", () => {
console.clear();
console.log(`${color.green("Process output")}` + (rerun ? ` (iteration ${color.green(i++)})` : ""));
console.log("");
});
process.on("exit", (code) => {
const c = code === 0 ? color.green : color.red;
console.log(`Process ${c("exited")} with code ${c(code || "undefined")}`)
});
cb();
}
function killServer(cb) {
if (process !== undefined) {
process.on("exit", () => { cb() })
process.kill();
process = undefined;
} else {
cb();
}
}
const dev = () => {
series(transpile, runServer)(() => { });
watch("src/**/*.ts", series(killServer, transpileTS, runServer));
watch("src/data/**/*.json", series(killServer, transpileData, runServer));
};
exports.start = exports.default = (cb) => runServer(cb, false);
exports.build = transpile;
exports.dev = dev;