forked from tonylukasavage/ti-mocha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
35 lines (28 loc) · 1.14 KB
/
build.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
var C = require('./constants'),
fs = require('fs'),
path = require('path'),
wrench = require('wrench');
function build() {
// read the mocha template
var content = fs.readFileSync(C.TEMPLATE_FILE, 'utf8');
// generate ti-mocha.js by adding the mocha.js.template
var index = content.search(/\}\)\(\);$/g);
if (index !== -1) {
var srcs = [];
// get all the reporters
wrench.readdirSyncRecursive(C.REPORTERS_DIR).forEach(function(reporter) {
srcs.push(fs.readFileSync(path.join(C.REPORTERS_DIR, reporter), 'utf8'));
});
// get the titanium-specific code
srcs.push(fs.readFileSync(C.UTIL_FILE, 'utf8'));
srcs.push(fs.readFileSync(C.TITANIUM_FILE, 'utf8'));
// add it to the end of the inner function containing mocha
content = content.slice(0, index) + srcs.join('\n') + content.slice(index);
} else {
throw new Error('Failed to find insertion point for titanium code in ' + C.TEMPLATE_FILE);
}
// write out the new file
wrench.mkdirSyncRecursive(C.BUILD_DIR, 0755);
fs.writeFileSync(C.BUILD_FILE, fs.readFileSync(C.LICENSE_FILE, 'utf8') + fs.readFileSync(C.MOCHA_LICENSE_FILE, 'utf8') + content);
}
module.exports = build;