summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/android/cordova/lib/run.js
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/android/cordova/lib/run.js')
-rw-r--r--[-rwxr-xr-x]StoneIsland/platforms/android/cordova/lib/run.js99
1 files changed, 40 insertions, 59 deletions
diff --git a/StoneIsland/platforms/android/cordova/lib/run.js b/StoneIsland/platforms/android/cordova/lib/run.js
index 7f15448c..214a1e19 100755..100644
--- a/StoneIsland/platforms/android/cordova/lib/run.js
+++ b/StoneIsland/platforms/android/cordova/lib/run.js
@@ -25,63 +25,36 @@ var path = require('path'),
build = require('./build'),
emulator = require('./emulator'),
device = require('./device'),
- shell = require('shelljs'),
- Q = require('q');
+ Q = require('q'),
+ events = require('cordova-common').events;
-/*
- * Runs the application on a device if available.
- * If no device is found, it will use a started emulator.
- * If no started emulators are found it will attempt to start an avd.
- * If no avds are found it will error out.
- * Returns a promise.
- */
- module.exports.run = function(args) {
- var buildFlags = [];
+function getInstallTarget(runOptions) {
var install_target;
- var list = false;
-
- for (var i=2; i<args.length; i++) {
- if (build.isBuildFlag(args[i])) {
- buildFlags.push(args[i]);
- } else if (args[i] == '--device') {
- install_target = '--device';
- } else if (args[i] == '--emulator') {
- install_target = '--emulator';
- } else if (/^--target=/.exec(args[i])) {
- install_target = args[i].substring(9, args[i].length);
- } else if (args[i] == '--list') {
- list = true;
- } else {
- console.warn('Option \'' + args[i] + '\' not recognized (ignoring).');
- }
+ if (runOptions.target) {
+ install_target = runOptions.target;
+ } else if (runOptions.device) {
+ install_target = '--device';
+ } else if (runOptions.emulator) {
+ install_target = '--emulator';
}
- if (list) {
- var output = '';
- var temp = '';
- if (!install_target) {
- output += 'Available Android Devices:\n';
- temp = shell.exec(path.join(__dirname, 'list-devices'), {silent:true}).output;
- temp = temp.replace(/^(?=[^\s])/gm, '\t');
- output += temp;
- output += 'Available Android Virtual Devices:\n';
- temp = shell.exec(path.join(__dirname, 'list-emulator-images'), {silent:true}).output;
- temp = temp.replace(/^(?=[^\s])/gm, '\t');
- output += temp;
- } else if (install_target == '--emulator') {
- output += 'Available Android Virtual Devices:\n';
- temp = shell.exec(path.join(__dirname, 'list-emulator-images'), {silent:true}).output;
- temp = temp.replace(/^(?=[^\s])/gm, '\t');
- output += temp;
- } else if (install_target == '--device') {
- output += 'Available Android Devices:\n';
- temp = shell.exec(path.join(__dirname, 'list-devices'), {silent:true}).output;
- temp = temp.replace(/^(?=[^\s])/gm, '\t');
- output += temp;
- }
- console.log(output);
- return;
- }
+ return install_target;
+}
+
+/**
+ * Runs the application on a device if available. If no device is found, it will
+ * use a started emulator. If no started emulators are found it will attempt
+ * to start an avd. If no avds are found it will error out.
+ *
+ * @param {Object} runOptions various run/build options. See Api.js build/run
+ * methods for reference.
+ *
+ * @return {Promise}
+ */
+ module.exports.run = function(runOptions) {
+
+ var self = this;
+ var install_target = getInstallTarget(runOptions);
return Q()
.then(function() {
@@ -90,10 +63,10 @@ var path = require('path'),
return device.list()
.then(function(device_list) {
if (device_list.length > 0) {
- console.log('WARNING : No target specified, deploying to device \'' + device_list[0] + '\'.');
+ events.emit('warn', 'No target specified, deploying to device \'' + device_list[0] + '\'.');
install_target = device_list[0];
} else {
- console.log('WARNING : No target specified, deploying to emulator');
+ events.emit('warn', 'No target specified and no devices found, deploying to emulator');
install_target = '--emulator';
}
});
@@ -137,17 +110,25 @@ var path = require('path'),
});
});
}).then(function(resolvedTarget) {
- return build.run(buildFlags, resolvedTarget).then(function(buildResults) {
+ // Better just call self.build, but we're doing some processing of
+ // build results (according to platformApi spec) so they are in different
+ // format than emulator.install expects.
+ // TODO: Update emulator/device.install to handle this change
+ return build.run.call(self, runOptions, resolvedTarget)
+ .then(function(buildResults) {
if (resolvedTarget.isEmulator) {
- return emulator.install(resolvedTarget, buildResults);
+ return emulator.wait_for_boot(resolvedTarget.target)
+ .then(function () {
+ return emulator.install(resolvedTarget, buildResults);
+ });
}
return device.install(resolvedTarget, buildResults);
});
});
};
-module.exports.help = function(args) {
- console.log('Usage: ' + path.relative(process.cwd(), args[1]) + ' [options]');
+module.exports.help = function() {
+ console.log('Usage: ' + path.relative(process.cwd(), process.argv[1]) + ' [options]');
console.log('Build options :');
console.log(' --debug : Builds project in debug mode');
console.log(' --release : Builds project in release mode');