File size: 932 Bytes
476094d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env node

import { spawn } from "node:child_process";

function npmCommand() {
  return process.platform === "win32" ? "npm.cmd" : "npm";
}

function start(label, args) {
  const child = spawn(npmCommand(), args, {
    stdio: "inherit",
    env: process.env,
  });
  child.on("exit", (code) => {
    if (code && code !== 0) {
      console.error(`${label} exited with code ${code}`);
      process.exitCode = code;
    }
  });
  return child;
}

async function main() {
  const backend = start("ui:server", ["run", "ui:server"]);
  const frontend = start("ui:client", ["run", "ui:client", "--", "--host", "127.0.0.1"]);

  const cleanup = () => {
    if (!backend.killed) backend.kill("SIGTERM");
    if (!frontend.killed) frontend.kill("SIGTERM");
  };

  process.on("SIGINT", cleanup);
  process.on("SIGTERM", cleanup);
}

main().catch((error) => {
  console.error(error?.message || error);
  process.exitCode = 1;
});