generated from Mechanika-Design/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
47 lines (39 loc) · 1.64 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
'use strict';
const program = require('commander');
const start = require('.');
const { DEFAULT_REPEAT_TIMES, DEFAULT_OUTPUT_FORMAT, DEFAULT_VIEWPORT_SIZE } = require('./src/constants');
program
.description('Measures web application loading metrics')
.usage('<url> [options] ')
.arguments('<url>')
.action((url) => {
program.url = url;
})
.option('-r, --repeat [n]', 'The number of times the page metrics are measured', DEFAULT_REPEAT_TIMES)
.option('-w, --width [width]', "The viewport's width to set", DEFAULT_VIEWPORT_SIZE.WIDTH)
.option('-H, --height [height]', "The viewport's height to set", DEFAULT_VIEWPORT_SIZE.HEIGHT)
.option('-c, --custom-path [custom-path]', 'Path to custom path configuration file')
.option('-o, --output-format [output-format]', 'The desired output format', DEFAULT_OUTPUT_FORMAT.CLI)
.option('--wait-until [wait-until]', 'The waitUntil value of the Page.reload options accepted by puppeteer')
.option('--with-redirects', 'Whether we want to test the timings of the whole redirect chain')
.option('--output-file [output-file]', 'Whether we want to export data in a file, and the desired path to the file')
.option('--no-headless', 'Defines if we dont want to use puppeteer headless mode')
.option('--no-sandbox', 'Disable chrome sandbox mode, mandatory in some systems')
.parse(process.argv);
const errorHandler = (error) => {
console.error(error);
process.exit(1);
};
if (!program.url) {
program.help();
process.exit(1);
} else {
try {
start(program, errorHandler).then((output) => {
console.log(output);
});
} catch (error) {
errorHandler(error);
}
}