forked from flaviait/ng2-jspm-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint-scripts.js
46 lines (39 loc) · 1.03 KB
/
lint-scripts.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
"use strict";
const _ = require("lodash");
const program = require("commander");
const utils = require("../dev/utils");
const lintScripts = require("../dev/scripts").lint;
program
.usage('[options] <files-glob>')
.option("-w, --watch", "Watch the scripts")
.option("-e, --exclude <files-glob>", "Exclude pattern")
.parse(process.argv);
program.files = program.args[0];
const printError = e => {
if (e.code === "ELINT") {
console.error(`There are ${e.count} linting errors:`);
console.error(e.output);
} else {
console.error(e.stack);
}
};
utils.getFiles(program.files, {ignore: program.exclude})
.then(lintScripts)
.then(
() => console.log("No script linting errors"),
e => {
printError(e);
if (!program.watch) {
process.exit(1);
}
}
);
if (program.watch) {
const watch = require("../dev/watch");
watch(program.files, files => {
lintScripts(files).then(
() => console.log("No script linting errors"),
printError
)
}, {events: ["change", "unlink"]});
}