Refactor development script to use dedicated module
This commit is contained in:
@@ -4,12 +4,9 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"workspaces": ["apps/*"],
|
"workspaces": ["apps/*"],
|
||||||
"scripts": {
|
"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",
|
"build": "npm run build -w @mitwirkung/api && npm run build -w @mitwirkung/web",
|
||||||
"test": "npm run test -w @mitwirkung/api",
|
"test": "npm run test -w @mitwirkung/api",
|
||||||
"start": "npm run start -w @mitwirkung/api"
|
"start": "npm run start -w @mitwirkung/api"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"concurrently": "^9.1.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
scripts/dev.mjs
Normal file
25
scripts/dev.mjs
Normal 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);
|
||||||
Reference in New Issue
Block a user