-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
executable file
·56 lines (48 loc) · 1.51 KB
/
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
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
const program = require('commander');
const urllib = require('url');
const package = require('./package.json');
function collect(val, list) {
let split = val.match(/^(\d+)x(\d+)$/);
if (!split) {
console.warn(`invalid dimensions "${val}", will be ignored.`);
} else {
list.push([
parseInt(split[1], 10),
parseInt(split[2], 10)
]);
}
return list;
}
program
.version(package.version)
.usage('[options] <url>')
.option('-c, --channel [channel]', 'Use specified channel [release]', 'release')
.option('-d, --dimension [size]', 'Capture at the specified dimensons [1024x768]', collect, [])
.option('-p, --prefix [prefix]', 'Output prefix e.g. prefix_[size].png [screenshot]', 'screenshot')
.parse(process.argv);
if (!program.dimension.length) {
console.error('no valid dimensions provided, defaulting to 1024x768');
program.dimension = [[1024, 768]];
}
const VALID_CHANNELS = ['nightly', 'beta', 'release'];
if (VALID_CHANNELS.indexOf(program.channel) === -1) {
console.error(`invalid channel "${program.channel}", using release`);
}
if (program.args[0]) {
const capture = require('./capture').capture;
let url = program.args[0];
let parsed = urllib.parse(url);
if (!parsed.protocol) {
console.error('no protocol provided, assuming http://');
url = 'http://' + url;
}
capture({
channel: program.channel,
dimensions: program.dimension,
url: url,
prefix: program.prefix || 'screenshot'
});
} else {
console.error('No URL provided.');
}