1 | #!/usr/bin/env node
|
2 |
|
3 | const globby = require('globby')
|
4 | const path = require('path')
|
5 | const lintFiles = require('.').lintFiles
|
6 | const cwd = process.cwd()
|
7 | let patterns = [
|
8 | '!**/.git/**',
|
9 | '!**/coverage/**',
|
10 | '!**/dist/**',
|
11 | '!**/node_modules/**',
|
12 | '!**/vendor/**',
|
13 | '!*.min.js',
|
14 | '!bundle.js'
|
15 | ]
|
16 | const userPattern = process.argv.slice(2)[0]
|
17 |
|
18 | if (userPattern) {
|
19 | patterns.unshift(userPattern)
|
20 | } else {
|
21 | patterns.unshift('**/*.md', '**/*.markdown')
|
22 | }
|
23 |
|
24 | const files = globby.sync(patterns, {cwd: cwd})
|
25 | .map(file => path.resolve(cwd, file))
|
26 |
|
27 | lintFiles(files, function (err, results) {
|
28 | if (err) throw err
|
29 |
|
30 |
|
31 | if (results.every(result => result.errors.length === 0)) {
|
32 | process.exit(0)
|
33 | }
|
34 |
|
35 |
|
36 | results.forEach(result => {
|
37 | result.errors.forEach(error => {
|
38 | let filepath = path.relative(cwd, result.file)
|
39 | console.log(`${filepath}:${error.line}:${error.column}: ${error.message}`)
|
40 | })
|
41 | })
|
42 | process.exit(1)
|
43 | })
|