-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
66 lines (62 loc) · 2.23 KB
/
build.js
File metadata and controls
66 lines (62 loc) · 2.23 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const { spawnSync, spawn } = require("child_process");
const process = require("process");
const { program } = require("commander");
program
.option("-n, --ngrok", "Use ngrok to expose the server to the internet", false)
.parse(process.argv);
const { ngrok: useNgrok } = program.opts(process.argv.slice(2));
process.on("SIGINT", function () {
api.kill();
front.kill();
process.exit(1);
});
const buildApi = spawnSync("npm run build:api", { stdio: "inherit", shell: true });
if (buildApi.status !== 0) {
console.log("API build failed");
process.exit(1);
}
(async () => {
const api = spawn(`npm run start:api${useNgrok ? ":ngrok" : ""}`, { stdio: "inherit", shell: true})
let front;
let admin;
let close = false;
api.on("close", (code) => {
console.log(`API process exited with code ${code}`);
try {
front.kill();
close = true;
} catch (e) {}
try {
admin.kill();
close = true;
} catch (e) {}
});
if (close) return;
console.log("Front build started");
front = spawn("npm run build:front", { stdio: "inherit", shell: true });
front.on("close", (code) => {
console.log(`Front process exited with code ${code}`);
if (code === 0) {
console.log("Front build successful");
if(close) return;
console.log("Admin build started");
admin = spawn(`npm run build:admin`, { stdio: "inherit", shell: true })
admin.on("close", (code) => {
console.log(`Admin process exited with code ${code}`);
if (code === 0) {
console.log("Admin build successful");
spawnSync("npm run stop:api", { stdio: "inherit", shell: true });
process.exit(0);
} else {
console.log("Admin build failed");
spawnSync("npm run stop:api", { stdio: "inherit", shell: true });
process.exit(1);
}
});
} else {
console.log("Front build failed");
spawnSync("npm run stop:api", { stdio: "inherit", shell: true });
process.exit(1);
}
});
})();