-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·47 lines (40 loc) · 968 Bytes
/
Copy pathcli.js
File metadata and controls
executable file
·47 lines (40 loc) · 968 Bytes
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
#!/usr/bin/env node
import fs from "fs";
import { createServer } from "http";
import { fileURLToPath } from "url";
import meow from "meow";
import sirv from "sirv";
const urlToPath = (url) => new URL(url, import.meta.url);
const loadJson = (url) => JSON.parse(fs.readFileSync(urlToPath(url)));
const dir = fileURLToPath(urlToPath("./dist"));
const pkg = loadJson("./package.json");
const cli = meow(
`
Usage
$ burnchart <options>
Options
--port, -p Specify port (number)
`,
{
importMeta: import.meta,
flags: {
port: {
shortFlag: "p",
type: "number",
default: 8080,
},
host: {
shortFlag: "h",
type: "string",
},
},
}
);
const { port } = cli.flags;
const handler = sirv(dir, { single: true });
const server = createServer(handler).listen(port);
server.on("listening", () => {
console.log(
`burnchart/${pkg.version} started on port ${server.address().port}`
);
});