forked from bkconrad/wasabi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jakefile
162 lines (135 loc) · 4.7 KB
/
Jakefile
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
task('doc', function () {
var options = {
paths: [ './src' ],
outdir: './doc'
};
var Y = require('yuidocjs');
var json = (new Y.YUIDoc(options)).run();
options = Y.Project.mix(json, options);
if (!options.parseOnly) {
var builder = new Y.DocBuilder(options, json);
builder.compile(function() {
var endtime = (new Date).getTime();
});
}
});
task('build', function () {
var fs = require('fs');
var path = require('path');
var browserify = require('browserify');
var b = browserify();
var UglifyJS = require('uglify-js');
b.add('./src/wasabi.js');
b.require('./src/wasabi');
b.bundle(function(err, src) {
var filename, result;
if(err) {
console.log(err);
process.exit(1);
}
if(!fs.existsSync('build')) {
fs.mkdirSync('build');
}
// write the browserified source
filename = path.join('build', 'wasabi_browser.js');
fs.writeFileSync(filename, src);
console.log('Wrote to ' + filename + '. Size: ' + src.length);
// write the browserified and minified source
filename = path.join('build', 'wasabi_browser_min.js');
result = UglifyJS.minify(src.toString(), {fromString: true});
fs.writeFileSync(filename, result.code);
// write the browserified debug source
filename = path.join('build', 'wasabi_browser_dbg.js');
fs.writeFileSync(filename, src.toString().replace(/\/\/dbg/g, ''));
console.log('Wrote to ' + filename + '. Size: ' + result.code.length);
});
});
task('test', function () {
var Mocha = require('mocha');
var fs = require('fs');
var path = require('path');
var testFiles = fs.readdirSync('test').map(function(x) { return path.join('test', x); });
var srcFiles = fs.readdirSync('src').map(function(x) { return path.join('src', x); });
var mocha = new Mocha();
var coverage = require('./coverage.js');
// make sure the library can survive Object.prototype modification
Object.prototype.foo = 'bar';
coverage.hookRequire();
srcFiles.forEach(function(name) {
if(name.indexOf('debug') < 0)
coverage.addInstrumentCandidate(name);
});
testFiles.forEach(function(name) {
mocha.addFile(name);
});
mocha.run(function(failures) {
coverage.writeReports('cov');
process.exit(failures);
});
});
task('bench', function () {
process.stdout.write("\nBenchmarks: \n");
require('./bench/cpu.js');
// require('./bench/net.js');
});
task('lint', function () {
var beautify = require('js-beautify').js_beautify;
var JSHINT = require('jshint').JSHINT;
var JSLINT = require('jslint').load();
var fs = require('fs');
var path = require('path');
var JSBEAUTIFY_OPTS = {
jslint_happy: true,
good_stuff: true,
indent_size: 4
};
var JSHINT_OPTS = {
};
var JSLINT_OPTS = {
bitwise: true,
nomen: true,
sloppy: true,
vars: true,
plusplus: true,
node: true,
white: true,
predef: ['it', 'describe', 'beforeEach']
};
var srcFiles = fs.readdirSync('src').map(function(x) { return path.join('src', x); });
var testFiles = fs.readdirSync('test').map(function(x) { return path.join('test', x); });
var files = srcFiles.concat(testFiles);
var totalErrors = 0;
files.forEach(function(name) {
process.stdout.write("Linting " + name + "\n");
var data = fs.readFileSync(name);
data = beautify(data.toString(), JSBEAUTIFY_OPTS)
fs.writeFileSync(name, data);
if(!JSHINT(data, JSHINT_OPTS)) {
process.stdout.write("jshint:\n");
var hintData = JSHINT.data();
for(var i = 0; i < hintData.errors.length; i++) {
var error = hintData.errors[i];
if(error) {
process.stdout.write(name + ":" + error.line + ":" + error.character + " " + error.reason + "\n");
totalErrors++;
}
}
}
if(!JSLINT(data, JSLINT_OPTS)) {
process.stdout.write("jslint:\n");
for(var i = 0; i < JSLINT.errors.length; i++) {
var error = JSLINT.errors[i];
if(error) {
process.stdout.write(name + ":" + error.line + ":" + error.character + " " + error.reason + "\n");
totalErrors++;
}
}
}
});
if(totalErrors > 0) {
process.stdout.write(totalErrors + " errors detected!\n");
process.exit(1);
} else {
process.stdout.write("Lint-free!\n");
}
});