1 | #!/usr/bin/env node
|
2 |
|
3 | const commander = require('commander');
|
4 | const CLIEngine = require('eslint').CLIEngine;
|
5 | const path = require('path');
|
6 | const os = require('os');
|
7 | const tsmlb = require('tsmlb');
|
8 | const filterer = require('./filterer');
|
9 | const ignores = require('./ignores');
|
10 | const pkg = require(path.join(__dirname, 'package.json'));
|
11 |
|
12 | commander.
|
13 | version(pkg.version).
|
14 | option('-e, --errors', 'Produces a report that only includes errors; not warnings.').
|
15 | option('-w, --warnings', 'Produces a report that only includes warnings; not errors.').
|
16 | option('--format', 'Formats files where possible to comply with videojs-standard.').
|
17 | arguments('[targets...]').
|
18 | action(targets => {
|
19 | commander.targets = targets;
|
20 | }).
|
21 | parse(process.argv);
|
22 |
|
23 |
|
24 | if (!commander.targets) {
|
25 | commander.targets = ['.'];
|
26 | }
|
27 |
|
28 | const cli = new CLIEngine({
|
29 | cwd: process.cwd(),
|
30 | configFile: path.join(__dirname, 'eslintrc.json'),
|
31 | fix: Boolean(commander.format),
|
32 | ignorePattern: ignores(process.cwd())
|
33 | });
|
34 |
|
35 | const report = filterer(cli.executeOnFiles(commander.targets),
|
36 | commander.errors,
|
37 | commander.warnings);
|
38 |
|
39 | if (commander.format) {
|
40 | CLIEngine.outputFixes(report);
|
41 |
|
42 | const applied = report.results.
|
43 | map(result => result.output ? result.filePath : '').
|
44 | filter(Boolean);
|
45 |
|
46 | if (applied.length) {
|
47 | console.log(tsmlb`
|
48 | Applied fixes to ${applied.length} files:
|
49 | ${applied.join(os.EOL + ' ')}
|
50 | `);
|
51 | }
|
52 |
|
53 | if (applied.length < report.results.length) {
|
54 | console.log(tsmlb`
|
55 | Could not apply fixes to ${applied.length ? report.results.length - applied.length : 'any'} files!
|
56 | `);
|
57 | }
|
58 | } else {
|
59 | const formatter = cli.getFormatter();
|
60 |
|
61 | console.log(formatter(report.results));
|
62 | }
|
63 |
|
64 |
|
65 | process.exit(report.errorCount ? 1 : 0);
|