39 lines
1.0 KiB
JavaScript
Raw Normal View History

/* eslint-disable */
const { spawn } = require("child_process");
const chokidar = require("chokidar");
const kill = require("tree-kill");
const args = [...process.argv].splice(2);
let buildproc, runproc;
function run(changedFile) {
if (changedFile) {
console.log(`Change to ${changedFile} detected`);
}
if (buildproc) {
kill(buildproc.pid);
buildproc = undefined;
}
if (runproc) {
kill(runproc.pid);
runproc = undefined;
}
buildproc = spawn("npm", ["run", "build"], { stdio: "inherit", shell: true });
buildproc.on("exit", code => {
buildproc = undefined;
if (code === 0) {
runproc = spawn("npm", ["run", "start", "--", "--dev", ...args], { stdio: "inherit", shell: true });
runproc.on("exit", () => {
runproc = undefined;
});
}
});
}
run();
chokidar.watch("src").on("change", run);
chokidar.watch("static/fixed_responses").on("change", run);
chokidar.watch("static/webui").on("change", run);