forked from jshint/jshint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.js
executable file
·132 lines (106 loc) · 2.58 KB
/
make.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env node
/*global ls, target, find, echo, cat, exit, exec, mkdir, test */
"use strict";
require("shelljs/make");
var cli = require("cli");
var pkg = require("./package.json");
var TESTS = [
"tests/",
"tests/stable/unit/",
"tests/stable/regression/",
"tests/next/unit/",
];
var OPTIONS = JSON.parse(cat("./jshint.json"));
target.all = function () {
target.lint();
target.test();
};
target.lint = function () {
var jshint = require("jshint").JSHINT;
var files = find("src")
.filter(function (file) {
return file.match(/\.js$/);
})
.concat(
ls(__dirname + "/*.js").filter(function (file) {
return file !== __dirname + "/demo.js";
})
);
TESTS.forEach(function (dir) {
ls(dir + "*.js").forEach(function (file) {
files.push(file);
});
});
echo("Linting files...", "\n");
var failures = {};
files.forEach(function (file) {
var passed = jshint(cat(file), OPTIONS);
process.stdout.write(passed ? "." : "F");
if (!passed) {
failures[file] = jshint.data();
}
});
echo("\n");
if (Object.keys(failures).length === 0) {
cli.ok("All files passed.");
echo("\n");
return;
}
var outputError = function (err) {
if (!err) {
return;
}
var line = "[L" + err.line + "]";
while (line.length < 10) {
line += " ";
}
echo(line, err.reason);
echo("\n");
};
for (var key in failures) {
cli.error(key);
failures[key].errors.forEach(outputError);
}
exit(1);
};
target.test = function () {
var nodeunit = require("nodeunit").reporters.minimal;
var files = [];
TESTS.forEach(function (dir) {
ls(dir + "*.js").forEach(function (file) {
files.push(file);
});
});
echo("Running tests...", "\n");
nodeunit.run(files, null, function (err) {
exit(err ? 1 : 0);
});
};
target.build = function () {
var browserify = require("browserify");
var bundle = browserify("./src/stable/jshint.js");
if (!test("-e", "./dist")) {
mkdir("./dist");
}
echo("Building into dist/...", "\n");
bundle.require("./src/stable/jshint.js", { expose: "jshint" });
bundle.bundle({}, function (err, src) {
[
"//" + pkg.version,
"var JSHINT;",
"(function () {",
"var require;",
src,
"JSHINT = require('jshint').JSHINT;",
"}());"
].join("\n").to("./dist/jshint-" + pkg.version + ".js");
cli.ok("Bundle");
// Rhino
var rhino = cat("./dist/jshint-" + pkg.version + ".js", "./src/platforms/rhino.js");
rhino = "#!/usr/bin/env rhino\n\n" + "var window = {};" + rhino;
rhino.to("./dist/jshint-rhino-" + pkg.version + ".js");
exec("chmod +x dist/jshint-rhino-" + pkg.version + ".js");
cli.ok("Rhino");
echo("\n");
});
};