-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
start.js
79 lines (72 loc) · 1.82 KB
/
start.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
import concurrently from "concurrently";
import kill from "tree-kill";
import fs from "fs";
const args = process.argv ? process.argv.slice(2) : [];
const standalone = args && args[0] === "standalone";
let commands = [
{
"command": "cd shared && npm run build",
"name": "shared",
"prefixColor": "blue",
"env": { "cables_standalone": standalone }
},
{
"command": "cd cables && npm run start",
"name": "core",
"prefixColor": "yellow",
"env": { "cables_standalone": standalone }
},
{
"command": "cd cables_ui && npm run start",
"name": "gui",
"prefixColor": "green",
"env": { "cables_standalone": standalone }
},
];
if (!standalone)
{
let apiExists = true;
try
{
if (!fs.statSync("cables_api").isDirectory() || !fs.existsSync("cables_api/src/cables.js"))
{
apiExists = false;
}
}
catch (e)
{
apiExists = false;
}
if (apiExists)
{
commands.splice(2, 0, {
"command": "cd cables_api && npm run start",
"name": "api",
"prefixColor": "cyan",
"env": { "cables_standalone": standalone }
});
}
else
{
console.warn("FATAL: running `npm run start`, but cables_api/ dir does not exist!");
console.info("are you trying to run `npm run watch:standalone`?");
process.exit(1);
}
}
const { result } = concurrently(
commands,
{
"prefix": "name",
"killOthers": ["failure"],
"restartTries": 3,
},
);
result.then(() =>
{
console.log("stopped!");
kill(process.pid, "SIGHUP");
}, () => { console.log("WTF!!!!!!"); }).catch((err) => { return console.log("error", err); });
process.on("SIGINT", () =>
{
kill(process.pid, "SIGHUP");
});