forked from apache/cordova-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jakefile
215 lines (181 loc) · 6.63 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* Licensed to the Apache Software Foundation (ASF
* or more contributor license agreements. See th
* distributed with this work for additional infor
* regarding copyright ownership. The ASF license
* to you under the Apache License, Version 2.0 (t
* "License"); you may not use this file except in
* with the License. You may obtain a copy of the
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to
* software distributed under the License is distr
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* KIND, either express or implied. See the Licen
* specific language governing permissions and lim
* under the License.
*/
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 + ' && ' +
'mkdir ' + path.join(DEPLOY ,'debug');
childProcess.exec(cmd,complete);
}, true);
desc("compiles the source files for all extensions");
task('build', ['clean', 'hint', 'update-version'], 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("windows8",commitId);
packager.generate("blackberry",commitId);
packager.generate("ios",commitId);
packager.generate("windowsphone",commitId);
packager.generate("android",commitId);
packager.generate("bada",commitId);
packager.generate("tizen",commitId);
packager.generate("webos", commitId);
packager.generate("errgen",commitId);
packager.generate("test",commitId);
complete();
});
}, true);
desc("drops VERSION into JavaScript-based platforms");
task('update-version', ['set-cwd'], function() {
var version = fs.readFileSync("VERSION", "utf-8").toString().split(/\r?\n/).join('');
// List of files that need to be interpolated with matching regexes
var files = {
"lib/bada/plugin/bada/device.js":/(me\.cordova\s=\s").+(")/,
"lib/tizen/plugin/tizen/Device.js":/(this\.cordova\s=\s").+(")/,
"lib/blackberry/plugin/qnx/device.js":/(cordova:\s").+(")/,
"lib/blackberry/plugin/air/device.js":/(cordova:\s").+(")/
};
for (var f in files) if (files.hasOwnProperty(f)) {
var interpolatedContent = fs.readFileSync(f, "utf-8").toString().replace(files[f], "$1" + version + "$2");
fs.writeFileSync(f, interpolatedContent);
}
});
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', ['complainwhitespace'], function () {
var knownWarnings = [
"Redefinition of 'FileReader'",
"Redefinition of 'require'",
"Read only",
"Redefinition of 'console'"
];
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);
var complainedAboutWhitespace = false
desc('complain about what fixwhitespace would fix');
task('complainwhitespace', function() {
processWhiteSpace(function(file, newSource) {
if (!complainedAboutWhitespace) {
console.log("files with whitespace issues: (to fix: `jake fixwhitespace`)")
complainedAboutWhitespace = true
}
console.log(" " + file)
})
}, true);
desc('converts tabs to four spaces, eliminates trailing white space, converts newlines to proper form - enforcing style guide ftw!');
task('fixwhitespace', function() {
processWhiteSpace(function(file, newSource) {
if (!complainedAboutWhitespace) {
console.log("fixed whitespace issues in:")
complainedAboutWhitespace = true
}
fs.writeFileSync(file, newSource, 'utf8');
console.log(" " + file)
})
}, true);
function processWhiteSpace(processor) {
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
processor(file, src);
}
cbDone();
}
}, complete);
}