-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.js
56 lines (50 loc) · 1.24 KB
/
dev.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
/**
* Runs tsc and nodemon for instant compilation and server restarts during development.
*/
const { spawn } = require("node:child_process");
const { exit, cwd } = require("node:process");
const kill = require("tree-kill");
const commands = [
{ command: "bash", options: ["npx", "tsc", "--watch"] },
{
command: "bash",
options: [
"npx",
"vite",
"build",
"--watch",
"--sourcemap",
"--mode",
"development",
],
},
{ command: "bash", options: ["npx", "nodemon"] },
];
const subprocesses = [];
for (let x of commands) {
const subprocess = spawn(x.command, x.options, { cwd: cwd() });
subprocess.stdout.on("data", (data) => {
console.log(`${data}`);
});
subprocess.stderr.on("data", (data) => {
console.error(`${data}`);
});
subprocess.on("close", (code) => {
console.log(`${subprocess.pid}: Exited with code ${code}`);
});
subprocess.on("error", (data) => {
console.error({ error: data });
exit();
});
console.log({
pid: subprocess.pid,
command: [x.command, ...x.options].join(" "),
});
subprocesses.push(subprocess);
}
process.on("SIGINT", () => {
subprocesses.forEach((p) => {
console.log(`Killing PID ${p.pid}`);
kill(p.pid);
});
});