-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
39 lines (35 loc) · 1 KB
/
cli.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
#!/usr/bin/env node
import child_process from "child_process";
import path, { dirname } from "path";
import process from "process";
import { fileURLToPath } from "url";
import os from "os";
// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const cwd = path.join(__dirname, "static");
const { spawn } = child_process;
const npx = "npx";
const execfile = os.platform() === "win32" ? npx + ".cmd" : npx;
const cmd = execfile;
const args = [
"live-server",
...["--no-browser", "--verbose"],
...process.argv.slice(2),
];
const sp = spawn(cmd, args, { cwd });
console.log("cwd: " + cwd);
console.log("\n");
console.log("cmd: " + cmd);
console.log("\n");
console.log("args: ", args);
console.log("\n");
sp.stdout.on("data", (data) => {
console.log(` \n` + String(data) + ` \n`);
});
sp.stderr.on("data", (data) => {
console.error(` \n` + String(data) + ` \n`);
});
sp.on("close", (code) => {
console.log(`child process exited with code ${code}`);
});