-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·50 lines (41 loc) · 981 Bytes
/
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
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const findReadmeFile = require('./lib/find-readme-file');
const awesomeLint = require('.');
const getReporter = name => {
// Check if reporter is an npm package
try {
return require(name).report;
} catch (error) {
if (error.code === 'MODULE_NOT_FOUND') {
console.error(`No reporter found matching \`${name}\`. Using default reporter (vfile-reporter-pretty).`);
} else {
throw error;
}
}
};
const main = async () => {
const cli = meow(`
Usage
$ awesome-lint [url|filename]
Options
--reporter, -r Use a custom reporter
`, {
flags: {
reporter: {
type: 'string',
alias: 'r'
}
}
});
const input = cli.input[0];
const options = {};
options.filename = input ? input : findReadmeFile(process.cwd());
const reporterName = cli.flags.reporter;
if (reporterName) {
options.reporter = getReporter(reporterName);
}
await awesomeLint.report(options);
};
main();