-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·113 lines (89 loc) · 2.79 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env node
const meow = require('meow');
const updateNotifier = require('update-notifier');
const openUrl = require('./open-url');
const pkg = require('./package.json');
const parseCookieArg = require('./helpers/parse-cookie-arg');
const parseHeaderArg = require('./helpers/parse-header-arg');
const notifier = updateNotifier({ pkg, updateCheckInterval: 0 });
notifier.notify({
defer: true
});
const cli = meow({
help: `
Usage
$ page-coverage <url>
Options
--timeout, -t Navigation timeout (in seconds). Default 30s
--cookie, -b Set additional cookies for the page request (you can pass multiple params)
--header, -H Set additional headers for the page request (you can pass multiple params)
--post, -P Opens the page using POST request and sends the post data
--json, -j Output result in JSON format
--noHeadless, -nh Open browser (no headless mode)
--noClose, -nc Don't close browser window when finished (only with no headless mode)
Examples
$ page-coverage https://google.com
$ page-coverage https://google.com --no-headless
$ page-coverage https://google.com --no-headless --no-close
$ page-coverage https://google.com --timeout 45
$ page-coverage https://google.com --cookie "foo=bar"
$ page-coverage https://google.com --cookie "foo=bar" "moo=goo; domain=google.com; path=/ secure; httpOnly; expires=123456"
$ page-coverage https://google.com --header "MyHeader: Value"
$ page-coverage https://google.com --header "MyHeader: Value" --header "MyCustomHeader: some value"
$ page-coverage https://google.com --post "login=admin&password=secret" -H "Content-Type: application/x-www-form-urlencoded"
$ page-coverage https://google.com --json
`,
flags: {
noHeadless: {
type: 'boolean',
alias: 'nh',
default: false,
},
noClose: {
type: 'boolean',
alias: 'nc',
default: false,
},
timeout: {
type: 'number',
alias: 't',
default: 30,
},
cookie: {
type: 'string',
alias: 'c',
default: null,
},
header: {
type: 'string',
alias: 'H',
default: null,
},
post: {
type: 'string',
alias: 'P',
default: null,
},
json: {
type: 'boolean',
alias: 'j',
default: false,
},
}
});
if (cli.input.length < 1) {
cli.showHelp();
}
const [ url ] = cli.input;
const { noHeadless, noClose, timeout, header, cookie, post, json } = cli.flags;
const cookies = parseCookieArg(cookie, url);
const headers = parseHeaderArg(header);
openUrl(url, {
headless: !noHeadless,
closeBrowser: !noClose,
timeout,
headers,
cookies,
post,
json,
});