import { spawn } from "node:child_process"; const commands = [ ["API", ["run", "dev", "-w", "@mitwirkung/api"]], ["WEB", ["run", "dev", "-w", "@mitwirkung/web"]], ]; const children = commands.map(([name, args]) => { const child = spawn("npm", args, { stdio: ["inherit", "pipe", "pipe"] }); const forward = (stream, target) => stream.on("data", (data) => { for (const line of data.toString().split("\n")) { if (line) target.write(`[${name}] ${line}\n`); } }); forward(child.stdout, process.stdout); forward(child.stderr, process.stderr); return child; }); const stop = () => children.forEach((child) => child.kill("SIGTERM")); process.on("SIGINT", stop); process.on("SIGTERM", stop); const results = await Promise.all(children.map((child) => new Promise((resolve) => child.on("exit", resolve)))); process.exit(results.some((code) => code !== 0 && code !== null) ? 1 : 0);