34 lines
772 B
JavaScript
34 lines
772 B
JavaScript
import { spawn } from "node:child_process";
|
|
|
|
const run = (name, command, args, env = {}) => {
|
|
const child = spawn(command, args, {
|
|
stdio: "inherit",
|
|
shell: process.platform === "win32",
|
|
env: { ...process.env, ...env },
|
|
});
|
|
|
|
child.on("exit", (code, signal) => {
|
|
if (signal) {
|
|
console.log(`${name} stopped with ${signal}`);
|
|
return;
|
|
}
|
|
if (code !== 0) {
|
|
console.log(`${name} exited with code ${code}`);
|
|
process.exitCode = code;
|
|
}
|
|
});
|
|
|
|
return child;
|
|
};
|
|
|
|
const api = run("api", "node", ["server/index.js"], { API_PORT: "4174" });
|
|
const vite = run("vite", "node_modules/.bin/vite", []);
|
|
|
|
const stop = () => {
|
|
api.kill("SIGTERM");
|
|
vite.kill("SIGTERM");
|
|
};
|
|
|
|
process.on("SIGINT", stop);
|
|
process.on("SIGTERM", stop);
|