Refactor development script to use dedicated module

This commit is contained in:
2026-06-12 10:10:53 +02:00
parent 0b7c33fce1
commit a9d717a351
2 changed files with 26 additions and 4 deletions

View File

@@ -4,12 +4,9 @@
"version": "1.0.0",
"workspaces": ["apps/*"],
"scripts": {
"dev": "concurrently -n API,WEB -c blue,green \"npm run dev -w @mitwirkung/api\" \"npm run dev -w @mitwirkung/web\"",
"dev": "node scripts/dev.mjs",
"build": "npm run build -w @mitwirkung/api && npm run build -w @mitwirkung/web",
"test": "npm run test -w @mitwirkung/api",
"start": "npm run start -w @mitwirkung/api"
},
"devDependencies": {
"concurrently": "^9.1.2"
}
}

25
scripts/dev.mjs Normal file
View File

@@ -0,0 +1,25 @@
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);