-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.ts
More file actions
41 lines (37 loc) · 1.11 KB
/
dev.ts
File metadata and controls
41 lines (37 loc) · 1.11 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
#!/usr/bin/env node
/**
* Dev runner: spawns the Node server + the web watch build in parallel.
* Both processes inherit stdio. Ctrl-C kills both.
*/
import { spawn } from "node:child_process";
const procs = [
spawn("bun", ["build.ts", "--watch"], {
cwd: "web",
stdio: "inherit",
}),
spawn("./node_modules/.bin/tsx", ["--max-old-space-size=8192", "--env-file=.env", "server/index.ts"], {
stdio: "inherit",
env: { ...process.env },
}),
];
let shuttingDown = false;
const shutdown = async (code = 0) => {
if (shuttingDown) return;
shuttingDown = true;
for (const p of procs) if (!p.killed) p.kill("SIGTERM");
const killTimer = setTimeout(() => {
for (const p of procs) if (!p.killed) p.kill("SIGKILL");
}, 5000);
await Promise.all(
procs.map((p) => (p.exitCode !== null ? Promise.resolve() : new Promise((r) => p.once("exit", r)))),
);
clearTimeout(killTimer);
process.exit(code);
};
process.on("SIGINT", () => shutdown(0));
process.on("SIGTERM", () => shutdown(0));
for (const p of procs) {
p.on("exit", (code) => {
if (code !== 0 && code !== null) shutdown(code);
});
}