-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstart-expo-managed.mjs
More file actions
93 lines (81 loc) · 2.13 KB
/
start-expo-managed.mjs
File metadata and controls
93 lines (81 loc) · 2.13 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { spawn, spawnSync } from "node:child_process";
import path from "node:path";
const EXPO_PORT = "8081";
function killProcessTree(pid) {
return new Promise((resolve) => {
if (!pid) {
resolve();
return;
}
if (process.platform === "win32") {
const killer = spawn("cmd", ["/c", "taskkill", "/PID", String(pid), "/T", "/F"], {
stdio: "ignore",
});
killer.on("close", () => resolve());
return;
}
try {
process.kill(pid, "SIGTERM");
} catch {
// Ignore: process may already be gone.
}
resolve();
});
}
function killProcessTreeSync(pid) {
if (!pid) return;
if (process.platform === "win32") {
spawnSync("cmd", ["/c", "taskkill", "/PID", String(pid), "/T", "/F"], {
stdio: "ignore",
});
return;
}
try {
process.kill(pid, "SIGTERM");
} catch {
// Ignore: process may already be gone.
}
}
async function main() {
const expoCliPath = path.resolve(process.cwd(), "node_modules", "expo", "bin", "cli");
const vercelCliPath = path.resolve(process.cwd(), "node_modules", "vercel", "dist", "index.js");
const expo = spawn(process.execPath, [expoCliPath, "start", "--port", EXPO_PORT], {
stdio: "inherit",
env: process.env,
});
const vercel = spawn(process.execPath, [vercelCliPath, "dev", "--yes"], {
stdio: "inherit",
env: {
...process.env,
TS_NODE_PROJECT: "api/tsconfig.json",
},
});
const children = [expo, vercel];
let shuttingDown = false;
const shutdown = async (exitCode = 0) => {
if (shuttingDown) return;
shuttingDown = true;
await Promise.all(children.map((child) => killProcessTree(child.pid)));
process.exit(exitCode);
};
process.on("exit", () => {
for (const child of children) {
killProcessTreeSync(child.pid);
}
});
process.on("SIGINT", () => {
void shutdown(130);
});
process.on("SIGTERM", () => {
void shutdown(143);
});
expo.on("exit", (code) => {
if (shuttingDown) return;
void shutdown(code ?? 0);
});
vercel.on("exit", (code) => {
if (shuttingDown) return;
void shutdown(code ?? 0);
});
}
void main();