forked from cyteon/the-watcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprod.js
More file actions
35 lines (27 loc) · 966 Bytes
/
Copy pathprod.js
File metadata and controls
35 lines (27 loc) · 966 Bytes
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
import { spawn, spawnSync } from "child_process";
import { fileURLToPath } from "url";
import path from "path";
const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm";
async function run() {
const buildProcess = spawnSync(npmCommand, ["run", "build"], { stdio: "inherit", shell: true });
if (buildProcess.error) {
console.error("Error during the build process:", buildProcess.error.message);
return;
}
const prodProcess = spawn(npmCommand, ["run", "start"], { stdio: "inherit", shell: true });
try {
const { default: start } = await import("./src/loop.js");
await start();
} catch (error) {
console.error("Error during start function:", error);
prodProcess.kill();
return;
}
prodProcess.on("close", (code) => {
console.log(`Production process exited with code ${code}`);
});
prodProcess.on("error", (error) => {
console.error("Error running npm command:", error.message);
});
}
run();