import { spawn } from "node:child_process"; import { fileURLToPath } from "node:url"; import path from "node:path"; const scriptsDir = path.dirname(fileURLToPath(import.meta.url)); const projectRoot = path.resolve(scriptsDir, ".."); const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm"; const processes = [ spawn(npmCommand, ["run", "dev"], { cwd: path.join(projectRoot, "web"), stdio: "inherit" }), spawn(npmCommand, ["run", "dev:linux", "--", "--force"], { cwd: path.join(projectRoot, "admin"), stdio: "inherit" }), ]; let stopping = false; function stopAll(exitCode = 0) { if (stopping) return; stopping = true; for (const child of processes) { if (!child.killed) child.kill("SIGTERM"); } setTimeout(() => process.exit(exitCode), 100); } for (const child of processes) { child.on("exit", (code, signal) => { if (stopping) return; const exitCode = typeof code === "number" && code !== 0 ? code : signal ? 1 : 0; stopAll(exitCode); }); } process.on("SIGINT", () => stopAll(0)); process.on("SIGTERM", () => stopAll(0));