2013-08-13 08:07:23 +08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
/*
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
or more contributor license agreements. See the NOTICE file
|
|
|
|
distributed with this work for additional information
|
|
|
|
regarding copyright ownership. The ASF licenses this file
|
|
|
|
to you under the Apache License, Version 2.0 (the
|
|
|
|
"License"); you may not use this file except in compliance
|
|
|
|
with the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing,
|
|
|
|
software distributed under the License is distributed on an
|
|
|
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
KIND, either express or implied. See the License for the
|
|
|
|
specific language governing permissions and limitations
|
|
|
|
under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var shell = require('shelljs'),
|
2014-01-16 00:41:03 +08:00
|
|
|
spawn = require('./spawn'),
|
|
|
|
Q = require('q'),
|
2013-08-13 08:07:23 +08:00
|
|
|
path = require('path'),
|
|
|
|
fs = require('fs'),
|
|
|
|
ROOT = path.join(__dirname, '..', '..');
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Builds the project with ant.
|
2013-09-27 23:48:55 +08:00
|
|
|
* Returns a promise.
|
2013-08-13 08:07:23 +08:00
|
|
|
*/
|
|
|
|
module.exports.run = function(build_type) {
|
|
|
|
//default build type
|
|
|
|
build_type = typeof build_type !== 'undefined' ? build_type : "--debug";
|
2014-01-20 12:08:05 +08:00
|
|
|
var args = ['debug', '-f', path.join(ROOT, 'build.xml'), '-Dout.dir=ant-build', '-Dgen.dir=ant-build/gen'];
|
2013-08-13 08:07:23 +08:00
|
|
|
switch(build_type) {
|
|
|
|
case '--debug' :
|
|
|
|
break;
|
|
|
|
case '--release' :
|
2014-01-20 12:08:05 +08:00
|
|
|
args[0] = 'release';
|
2013-08-13 08:07:23 +08:00
|
|
|
break;
|
|
|
|
case '--nobuild' :
|
|
|
|
console.log('Skipping build...');
|
2013-09-27 23:48:55 +08:00
|
|
|
return Q();
|
2013-08-13 08:07:23 +08:00
|
|
|
default :
|
2013-09-27 23:48:55 +08:00
|
|
|
return Q.reject('Build option \'' + build_type + '\' not recognized.');
|
2013-08-13 08:07:23 +08:00
|
|
|
}
|
2014-01-20 12:08:05 +08:00
|
|
|
return spawn('ant', args);
|
2013-08-13 08:07:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets the path to the apk file, if not such file exists then
|
|
|
|
* the script will error out. (should we error or just return undefined?)
|
|
|
|
*/
|
|
|
|
module.exports.get_apk = function() {
|
2014-01-20 12:08:05 +08:00
|
|
|
var binDir = path.join(ROOT, 'ant-build');
|
|
|
|
if (fs.existsSync(binDir)) {
|
|
|
|
var candidates = fs.readdirSync(binDir).filter(function(p) {
|
|
|
|
// Need to choose between release and debug .apk.
|
|
|
|
return path.extname(p) == '.apk';
|
|
|
|
}).map(function(p) {
|
|
|
|
p = path.join(binDir, p);
|
|
|
|
return { p: p, t: fs.statSync(p).mtime };
|
|
|
|
}).sort(function(a,b) {
|
|
|
|
return a.t > b.t ? -1 :
|
|
|
|
a.t < b.t ? 1 : 0;
|
|
|
|
});
|
|
|
|
if (candidates.length === 0) {
|
|
|
|
console.error('ERROR : No .apk found in \'ant-build\' directory');
|
|
|
|
process.exit(2);
|
2013-08-13 08:07:23 +08:00
|
|
|
}
|
2014-01-20 12:08:05 +08:00
|
|
|
console.log('Using apk: ' + candidates[0].p);
|
|
|
|
return candidates[0].p;
|
2013-08-13 08:07:23 +08:00
|
|
|
} else {
|
2014-01-20 12:08:05 +08:00
|
|
|
console.error('ERROR : unable to find project ant-build directory, could not locate .apk');
|
2013-08-13 08:07:23 +08:00
|
|
|
process.exit(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.help = function() {
|
2013-10-31 09:06:58 +08:00
|
|
|
console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'build')) + ' [build_type]');
|
2013-08-13 08:07:23 +08:00
|
|
|
console.log('Build Types : ');
|
|
|
|
console.log(' \'--debug\': Default build, will build project in using ant debug');
|
|
|
|
console.log(' \'--release\': will build project using ant release');
|
|
|
|
console.log(' \'--nobuild\': will skip build process (can be used with run command)');
|
|
|
|
process.exit(0);
|
2013-09-27 23:48:55 +08:00
|
|
|
}
|