-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJakefile.js
97 lines (78 loc) · 2.68 KB
/
Jakefile.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
var _ = require('./configs/underscore-1.4.4');
var spawn = require('child_process').spawn;
var supportedPlatform = ['ios', 'android', 'blackberry'];
desc('Initialize the application after cordova create');
task('init', function() {
process.chdir('src');
console.log('Installing dependencies');
var npm = spawn('npm', ['install']);
npm.on('close', function (code) {
handleResources();
});
});
namespace('brunch', function() {
desc('Launch platform aware brunch watch');
task('watch', {async: true}, function() {
if(!_.contains(supportedPlatform, process.env.platform)) {
fail('Missing parameter platform=' + supportedPlatform.join('|'));
}
process.chdir('src');
var brunchArgs = ['w'];
brunchArgs.push('-c', '../configs/' + process.env.platform + '.js');
if('prod' == process.env.e) {
brunchArgs.push('-o');
}
var brunch = spawn('brunch', brunchArgs);
handleProcessEvents(brunch);
});
desc('Launch platform aware brunch build');
task('build', {async: true}, function() {
if(!_.contains(supportedPlatform, process.env.platform)) {
fail('Platform must be one of ' + supportedPlatform.join('|'));
}
process.chdir('src');
var brunchArgs = ['build'];
brunchArgs.push('-c', '../configs/' + process.env.platform + '.js');
if('prod' == process.env.e) {
brunchArgs.push('-o');
}
var brunch = spawn('brunch', brunchArgs);
handleProcessEvents(brunch);
});
});
desc('Run list of commands');
task('default', function() {
var child = spawn('jake', ['-T']);
handleProcessEvents(child);
});
handleResources = function() {
console.log('Updating resources');
process.chdir('../');
var fs = require('fs');
var wrench = require('./configs/wrench');
fs.mkdir('plugins', function() {
console.log('Plugins folder created');
});
var stream = fs.createReadStream('./www/config.xml');
stream.pipe(fs.createWriteStream('./src/app/assets/config.xml'));
wrench.copyDirRecursive('./www/res', './src/app/assets/res', function() {
wrench.rmdirRecursive('./www/', function() {
console.log('Generating www');
process.chdir('src');
var brunch = spawn('brunch', ['build']);
handleProcessEvents(brunch);
});
});
}
handleProcessEvents = function(child) {
child.stdout.on('data', function(stdout) {
process.stdout.write(stdout);
});
child.on('exit', function(code) {
if (code !== 0) {
fail(code);
} else {
complete();
}
});
};