Repository navigation
Expand file tree
/
Copy pathcli.js
More file actions
68 lines (48 loc) · 1.59 KB
/
Copy pathcli.js
File metadata and controls
68 lines (48 loc) · 1.59 KB
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
#!/usr/bin/env node
var debug = require('debug')('ylt:cli');
var meow = require('meow');
var path = require('path');
var ylt = require('../lib/index');
var cli = meow({
help: [
'Usage',
' yellowlabtools <url> <options>',
'',
'Options:',
' --screenshot Will take a screenshot and use this value as the output path. It needs to end with ".png".',
''
].join('\n'),
pkg: '../package.json'
});
// Check parameters
if (cli.input.length < 1) {
console.error('Incorrect parameters: url not provided');
process.exit(1);
}
var url = cli.input[0];
var options = {};
// Screenshot option
var screenshot = cli.flags.screenshot;
if (screenshot && (typeof screenshot !== 'string' || screenshot.toLowerCase().indexOf('.png', screenshot.length - 4) === -1)) {
console.error('Incorrect parameters: screenshot must be a path that ends with ".png"');
process.exit(1);
}
if (screenshot) {
if (path.resolve(screenshot) !== path.normalize(screenshot)) {
// It is not an absolute path, so it is relative to the current command-line directory
screenshot = path.join(process.cwd(), screenshot);
}
options.screenshot = cli.flags.screenshot;
}
(function execute(url, options) {
'use strict';
ylt(url, options).
then(function(data) {
debug('Success');
console.log(JSON.stringify(data, null, 2));
}).fail(function(err) {
debug('Test failed for %s', url);
console.error(err);
});
debug('Test launched...');
})(url, options);