-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
executable file
·47 lines (37 loc) · 1.05 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
#!/usr/bin/env node
import { readFile } from 'fs/promises';
import minimist from 'minimist';
import { createHar } from './index.js';
const pkg = JSON.parse(await readFile(
new URL('./package.json', import.meta.url),
'utf8',
));
const { _: args, ...opts } = minimist(process.argv.slice(2));
const help = `Usage: haribo <url> [ options ]
Options:
--delay=0 Milliseconds to wait after page loads to get rendered
source and screenshots.
--screenshots Include screenshots.
-h, --help Show this help.
-v, --version Show version.`;
if (args[0] === 'help' || opts.h || opts.help) {
console.log(help);
process.exit(0);
}
if (opts.v || opts.version) {
console.log(pkg.version);
process.exit(0);
}
if (!args[0]) {
console.error(help);
process.exit(1);
}
createHar(args[0], {
delay: opts.delay ? parseInt(opts.delay, 10) : 0,
screenshots: opts.screenshots,
})
.then(har => console.log(JSON.stringify(har, null, 2)))
.catch((error) => {
console.error(error);
process.exit(1);
});