forked from traveloka-archive/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·65 lines (57 loc) · 1.61 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
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const updateNotifier = require('update-notifier');
const meow = require('meow');
const pretty = require('eslint-formatter-pretty');
const marlint = require('./');
const cli = meow(
{
help: [
'Usage',
' $ marlint [<file|glob> ...]',
'',
'Options',
' --quiet Disable warning errors',
' --fix Automagically fixes code',
' --json Output JSON result to be consumed in other app',
' --jsonOutputFile Specify filename to store the JSON result',
'',
'Examples',
' $ marlint',
' $ marlint --fix',
' $ marlint --quiet --json --jsonOutputFile lint-result.json',
'',
'Tips',
' Put options in package.json instead of using flags so other tools can read it.',
],
},
{
boolean: ['json'],
}
);
updateNotifier({ pkg: cli.pkg }).notify();
const input = cli.input;
const opts = cli.flags;
marlint
.lintFiles(input, opts)
.then(report => {
if (opts.fix) {
marlint.outputFixes(report);
}
const output = pretty(report.results);
if (opts.json) {
const eslintJson = require.resolve('eslint-json');
const result = marlint.getFormatter(eslintJson)(report.results);
if (opts.jsonOutputFile) {
fs.writeFileSync(opts.jsonOutputFile, result);
process.stdout.write(`Test results written to: ${opts.jsonOutputFile}`);
}
}
process.stdout.write(output);
process.exit(report.errorCount === 0 ? 0 : 1);
})
.catch(err => {
console.error(err.stack);
process.exit(1);
});