-
Notifications
You must be signed in to change notification settings - Fork 73
/
Jakefile
144 lines (119 loc) · 4.17 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
var util = require('util'),
fs = require('fs'),
childProcess = require('child_process'),
path = require("path"),
rexp_minified = new RegExp("\\.min\\.js$"),
rexp_src = new RegExp('\\.js$');
// HELPERS
// Iterates over a directory
function forEachFile(root, cbFile, cbDone) {
var count = 0;
function scan(name) {
++count;
fs.stat(name, function (err, stats) {
if (err) cbFile(err);
if (stats.isDirectory()) {
fs.readdir(name, function (err, files) {
if (err) cbFile(err);
files.forEach(function (file) {
scan(path.join(name, file));
});
done();
});
} else if (stats.isFile()) {
cbFile(null, name, stats, done);
} else {
done();
}
});
}
function done() {
--count;
if (count === 0 && cbDone) cbDone();
}
scan(root);
}
desc("runs build");
task('default', ['build','test'], function () {});
desc("clean");
task('clean', ['set-cwd'], function () {
var DEPLOY = path.join(__dirname,"pkg");
var cmd = 'rm -rf ' + DEPLOY + ' && ' +
'mkdir ' + DEPLOY;
childProcess.exec(cmd,complete);
}, true);
desc("compiles the source files for all extensions");
task('build', ['clean', 'hint'], function () {
var packager = require("./build/packager");
var commitId = "";
childProcess.exec("git log -1",function(err,stdout,stderr) {
var stdoutLines = stdout.split("\n");
if(stdoutLines.length > 0) {
commitId = stdoutLines[0];
}
console.log("building " + commitId);
packager.generate("blackberry",commitId);
packager.generate("playbook",commitId);
packager.generate("ios",commitId);
packager.generate("wp7",commitId);
packager.generate("android",commitId);
packager.generate("bada",commitId);
packager.generate("errgen",commitId);
packager.generate("test",commitId);
complete();
});
}, true);
desc("prints a dalek");
task('dalek', ['set-cwd'], function () {
util.puts(fs.readFileSync("build/dalek", "utf-8"));
});
desc("runs the unit tests in node");
task('test', ['set-cwd'], require('./test/runner').node);
desc("starts a webserver to point at to run the unit tests");
task('btest', ['set-cwd'], require('./test/runner').browser);
desc("make sure we're in the right directory");
task('set-cwd', [], function() {
if (__dirname != process.cwd()) {
process.chdir(__dirname);
}
});
desc('check sources with JSHint');
task('hint', ['fixwhitespace'], function () {
var knownWarnings = ["Redefinition of 'FileReader'", "Redefinition of 'require'", "Read only"];
var filterKnownWarnings = function(el, index, array) {
var wut = true;
// filter out the known warnings listed out above
knownWarnings.forEach(function(e) {
wut = wut && (el.indexOf(e) == -1);
});
wut = wut && (!el.match(/\d+ errors/));
return wut;
};
childProcess.exec("jshint lib",function(err,stdout,stderr) {
var exs = stdout.split('\n');
console.log(exs.filter(filterKnownWarnings).join('\n'));
complete();
});
}, true);
desc('converts tabs to four spaces, eliminates trailing white space, converts newlines to proper form - enforcing style guide ftw!');
task('fixwhitespace', function() {
forEachFile('lib', function(err, file, stats, cbDone) {
//if (err) throw err;
if (rexp_minified.test(file) || !rexp_src.test(file)) {
cbDone();
} else {
var origsrc = src = fs.readFileSync(file, 'utf8');
// tabs -> four spaces
if (src.indexOf('\t') >= 0) {
src = src.split('\t').join(' ');
}
// eliminate trailing white space
src = src.replace(/ +\n/g, '\n');
if (origsrc !== src) {
// write it out yo
fs.writeFileSync(file, src, 'utf8');
}
cbDone();
}
}, complete);
}, true);