-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·46 lines (39 loc) · 902 Bytes
/
index.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
#!/usr/bin/env node
import ip from "ip";
import meow from "meow";
import qr from "qrcode-terminal";
const cyan = (str) => {
return `\x1b[36m${str}\x1b[0m`;
};
const cli = meow(
`
Description
Shows QR code of server url
Usage
$ npx server-qr-code
Options
--port, -p A port number (default: 3000)
--hostname, -H Hostname
--help Displays this message
`,
{
importMeta: import.meta,
flags: {
port: {
type: "number",
default: 3000,
shortFlag: "p",
},
hostname: {
type: "string",
shortFlag: "H",
},
},
}
);
const address = cli.flags.hostname ?? ip.address();
const port = cli.flags.port;
const url = `http://${address}:${port}/`;
qr.generate(url, { small: true }, (result) => {
console.log(` ${cyan(url)}\n ${result.replace(/\n/g, "\n ")}`);
});