import { spawn } from "node:child_process"; const processes = [ spawn("node", ["server/dist/server.js"], { stdio: "inherit" }), spawn("pnpm", ["--filter", "client", "start"], { stdio: "inherit" }) ]; let stopping = false; function stopAll(signal = "SIGTERM") { stopping = true; for (const child of processes) { if (!child.killed) { child.kill(signal); } } } for (const signal of ["SIGINT", "SIGTERM"]) { process.on(signal, () => { stopAll(signal); }); } for (const child of processes) { child.on("exit", (code, signal) => { if (stopping) return; stopping = true; stopAll(); process.exit(code ?? (signal ? 1 : 0)); }); }