-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
cli.js
executable file
·48 lines (40 loc) · 1004 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
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import findReadmeFile from './lib/find-readme-file.js';
import awesomeLint from './index.js';
const getReporter = async name => {
// Check if reporter is an npm package.
try {
const {report} = await import(name);
return 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 cli = meow(`
Usage
$ awesome-lint [url|filename]
Options
--reporter, -r Use a custom reporter
`, {
importMeta: import.meta,
flags: {
reporter: {
type: 'string',
shortFlag: 'r',
},
},
});
const input = cli.input[0];
const options = {};
options.filename = input ?? findReadmeFile(process.cwd());
const reporterName = cli.flags.reporter;
if (reporterName) {
options.reporter = await getReporter(reporterName);
}
await awesomeLint.report(options);