| 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); | |
| }); | |
| } | |