-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcli.js
executable file
·55 lines (48 loc) · 1.14 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import waitForLocalhost from 'wait-for-localhost';
const cli = meow(`
Usage
$ wait-for-localhost [port]
Options
--use-get Use the HTTP-method GET instead of HEAD to test if the server is ready.
--path Use a custom path. For example, /health for a health-check endpoint.
--status-codes Define status codes indicating the server is ready. [Default: 200]
Examples
$ wait-for-localhost 8080 && echo 'Server is ready'
$ wait-for-localhost 8080 --status-codes 200,201 && echo 'Server is ready'
`, {
importMeta: import.meta,
input: {
type: 'number',
default: 80,
},
flags: {
useGet: {
type: 'boolean',
},
path: {
type: 'string',
default: '/',
},
statusCodes: {
type: 'string',
default: '200',
},
},
});
const [port] = cli.input;
(async () => {
cli.flags.statusCodes = cli.flags.statusCodes.split(',').map(statusCode => Number.parseInt(statusCode, 10));
try {
await waitForLocalhost({
port,
...cli.flags,
});
process.exit();
} catch (error) {
console.error(error);
process.exit(2);
}
})();