-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
executable file
·84 lines (72 loc) · 2.16 KB
/
index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
'use strict';
const pkg = require('./package.json');
const meow = require('meow');
const twiglint = require('./lib/twig');
const reporter = require('./lib/reporter');
const twiglintConfig = require('./.twiglintrc');
const appliedPlugins = twiglintConfig.plugins.map(singlePluginName =>
require(`./plugins/twiglint-plugin-${singlePluginName}`)
);
const cli = meow(
`
Usage
$ twiglint <filename>
Options
-f, --format Use a specific output format - default: stylish [compact]
-s, --silent Show only errors
-v, --version Show current version of the module
-d, --debug Write debug file, and prepend every check with filename
-h, --help This help
`,
{
alias: {
f: 'format',
s: 'silent',
d: 'debug'
}
}
);
const filePath = cli.input;
if (cli.flags.h) {
// eslint-disable-next-line
console.log(cli.help);
process.exit(1);
}
if (cli.flags.v) {
// eslint-disable-next-line
console.log(pkg.version);
process.exit(1);
}
if (!filePath.length) {
// eslint-disable-next-line
console.error('Please provide file path');
process.exit(1);
}
const allReports = filePath.map(singleFilePath => {
if (cli.flags.d) {
// eslint-disable-next-line
console.log(`Processing file: ${singleFilePath}`);
}
return twiglint(singleFilePath, cli.flags).then(result => {
const allTheErorrs = appliedPlugins
.reduce((allErrorsArray, singlePlugin) => {
return allErrorsArray.concat(
singlePlugin(result, singleFilePath, twiglintConfig)
);
}, [])
.map(singleError => {
if (cli.flags.silent) {
singleError.messages = singleError.messages.filter(
singleMessage => singleMessage.fatal
);
}
return singleError;
});
return allTheErorrs;
});
});
Promise.all(allReports).then(allReportsResolved => {
var all = allReportsResolved.reduce((acc, el) => acc.concat(el), []);
reporter(all, cli.flags.format);
});