-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.js
executable file
·56 lines (45 loc) · 1.55 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
#!/usr/bin/env node
var extensionChecker = require('./libs/ext-checker');
var extensionConverter = require('./libs/ext-converter');
var cliReporter = require('./libs/reporters/cli-reporter');
var jsonReporter = require('./libs/reporters/json-reporter');
var argv = require('minimist')(process.argv.slice(2));
if (!argv._.length) {
return console.error("Provide a command to run.");
}
var commands = ['analyse', 'convert'];
var command = argv._[0];
if (commands.indexOf(command) === -1) {
return console.error("Unknown command: " + command);
}
if (argv._.length === 1) {
return console.error("Provide the path or id of the extension to be processed.");
}
var excludeGlob = argv['exclude-glob'] || null;
if (command === 'analyse') {
if (argv.reporter && argv.reporter.match(/^(cli|json)$/) === null) {
return console.error("Reporter can only be 'cli' or 'json'.");
}
return extensionChecker(argv._[1], excludeGlob, function (error, report) {
if (error) {
return console.error(error);
}
if (argv.reporter === 'json') {
var jsonPath = argv['report-file'] || null;
return jsonReporter(report, jsonPath)
}
return cliReporter(report);
});
} else {
var opts = {
outputPath: argv.output,
extensionId: argv.id,
excludeGlob: excludeGlob,
proxy: 'proxy' in argv ? argv.proxy : true,
};
return extensionConverter(argv._[1], opts, function (error) {
if (error) {
return console.error(error);
}
});
}