CB-8310: Fix to cordova run wp8 to attempt to deploy to device before it tries to deploy to emulator
diff --git a/template/cordova/lib/run.js b/template/cordova/lib/run.js
index c179ced..e9d3be8 100644
--- a/template/cordova/lib/run.js
+++ b/template/cordova/lib/run.js
@@ -27,7 +27,7 @@
var ROOT = path.join(__dirname, '..', '..');
module.exports.run = function (argv) {
- if (!utils.isCordovaProject(ROOT)){
+ if (!utils.isCordovaProject(ROOT)) {
return Q.reject("Could not find project at " + ROOT);
}
@@ -46,20 +46,32 @@
// Get build/deploy options
var buildType = args.release ? "release" : "debug",
- buildArchs = args.archs ? args.archs.split(' ') : ["anycpu"],
- deployTarget = args.target ? args.target : args.device ? "device" : "emulator";
+ buildArchs = args.archs ? args.archs.split(' ') : ["anycpu"];
// if --nobuild isn't specified then build app first
var buildPackages = args.nobuild ? Q() : build.run(argv);
return buildPackages
- .then(function () {
- return packages.getPackage(buildType, buildArchs[0]);
- })
- .then(function(builtPackage) {
- console.log('\nDeploying package to ' + deployTarget);
- return builtPackage.deployTo(deployTarget);
- });
+ .then(function () {
+ return packages.getPackage(buildType, buildArchs[0]);
+ })
+ .then(function (builtPackage) {
+ // Get deploy options
+ var deployTarget = args.target ? args.target : args.device ? "device" :
+ args.emulator ? "emulator" : null;
+
+ if (deployTarget) {
+ console.log('\nDeploying package to ' + deployTarget);
+ return builtPackage.deployTo(deployTarget);
+ }
+ // no deploy target specified - try device first & then emulator
+ console.log("\nTrying to deploy to device");
+ return builtPackage.deployTo("device").catch(function (error) {
+ console.log(error);
+ console.log("\nFalling back to deploy to emulator instead");
+ return builtPackage.deployTo("emulator");
+ });
+ });
};
module.exports.help = function () {