File size: 802 Bytes
202b514 | 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 | import { spawn } from "node:child_process";
const children = [
spawn(process.execPath, ["server/index.mjs"], {
stdio: "inherit",
env: process.env,
}),
spawn(process.platform === "win32" ? "npm.cmd" : "npm", ["run", "dev"], {
stdio: "inherit",
env: process.env,
}),
];
let shuttingDown = false;
for (const child of children) {
child.on("exit", (code) => {
if (shuttingDown) return;
shuttingDown = true;
for (const other of children) {
if (other !== child && !other.killed) other.kill("SIGTERM");
}
process.exit(code ?? 0);
});
}
for (const signal of ["SIGINT", "SIGTERM"]) {
process.on(signal, () => {
shuttingDown = true;
for (const child of children) {
if (!child.killed) child.kill(signal);
}
process.exit(0);
});
}
|