-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathrun-docusaurus.mjs
More file actions
48 lines (39 loc) · 1.2 KB
/
run-docusaurus.mjs
File metadata and controls
48 lines (39 loc) · 1.2 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
#!/usr/bin/env node
import { spawn } from "node:child_process";
const commandName = process.argv[2];
const defaultPorts = {
serve: "3000",
start: "3001",
};
if (!Object.hasOwn(defaultPorts, commandName)) {
console.error("Usage: node scripts/run-docusaurus.mjs <start|serve>");
process.exit(1);
}
// Docusaurus defaults to localhost, which is right for direct local runs.
// Dev containers set DOCUSAURUS_BIND_HOST=0.0.0.0 so VS Code/Docker can
// forward container ports for both the dev server and static preview server.
const host = process.env.DOCUSAURUS_BIND_HOST || "localhost";
const port = process.env.DOCUSAURUS_PORT || defaultPorts[commandName];
const command = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
console.log(`Starting Docusaurus ${commandName} on ${host}:${port}`);
const child = spawn(
command,
["exec", "docusaurus", commandName, "--host", host, "--port", port],
{
stdio: "inherit",
},
);
for (const signal of ["SIGINT", "SIGTERM"]) {
process.on(signal, () => {
if (!child.killed) {
child.kill(signal);
}
});
}
child.on("exit", (code, signal) => {
if (signal) {
process.kill(process.pid, signal);
return;
}
process.exit(code ?? 1);
});