CB-11478 Parse --archs option consistently Update arguments parsing logic to be consistent with build command where passing --archs as CLI argument (cordova build --archs) or platform arg, behind -- (cordova build -- --archs) doesn't make any difference
Project: http://git-wip-us.apache.org/repos/asf/cordova-windows/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-windows/commit/5e45d700 Tree: http://git-wip-us.apache.org/repos/asf/cordova-windows/tree/5e45d700 Diff: http://git-wip-us.apache.org/repos/asf/cordova-windows/diff/5e45d700 Branch: refs/heads/4.4.x Commit: 5e45d70063add74f6ca2a632b82cc677189c1131 Parents: 96533be Author: Vladimir Kotikov <v-vlk...@microsoft.com> Authored: Tue Aug 2 13:18:58 2016 +0300 Committer: daserge <v-ses...@microsoft.com> Committed: Thu Oct 20 20:54:53 2016 +0300 ---------------------------------------------------------------------- spec/unit/run.spec.js | 60 ++++++++++++++++++++++++++++++++++++++++ template/cordova/lib/run.js | 15 ++++++---- 2 files changed, 70 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/5e45d700/spec/unit/run.spec.js ---------------------------------------------------------------------- diff --git a/spec/unit/run.spec.js b/spec/unit/run.spec.js index 5a2cbd7..6ffcda0 100644 --- a/spec/unit/run.spec.js +++ b/spec/unit/run.spec.js @@ -16,6 +16,7 @@ specific language governing permissions and limitations under the License. */ + var Q = require('q'), path = require('path'), rewire = require('rewire'), @@ -23,6 +24,9 @@ var Q = require('q'), buildPath = path.join(platformRoot, 'cordova', 'build'), run = rewire(platformRoot + '/cordova/lib/run.js'); +var utils = require(path.join(platformRoot, 'cordova/lib/utils')); +var packages = require(path.join(platformRoot, 'cordova/lib/package')); + describe('run method', function() { var consoleLogOriginal, isCordovaProjectOriginal, @@ -244,4 +248,60 @@ describe('run method', function() { done(); }); }); + + it('spec.8 should accept --archs parameter either as cli or as platform arg', function(done) { + + spyOn(utils, 'isCordovaProject').andReturn(true); + spyOn(packages, 'getPackage').andReturn(Q({ arch: 'arm' })); + spyOn(packages, 'deployToDesktop').andReturn(Q()); + + var anyString = jasmine.any(String); + var expectedDeployOptions = jasmine.objectContaining({arch: 'arm'}); + + var fail = jasmine.createSpy('fail') + .andCallFake(function (err) { + console.error(err); + }); + + run.run({nobuild: true, argv: ['--archs=arm'] }) + .then(function () { + expect(packages.getPackage).toHaveBeenCalledWith(anyString, anyString, 'arm'); + expect(packages.deployToDesktop).toHaveBeenCalledWith(expectedDeployOptions, anyString, anyString); + }) + .then(function () { + return run.run({nobuild: true, archs: 'arm' }); + }) + .then(function () { + expect(packages.getPackage).toHaveBeenCalledWith(anyString, anyString, 'arm'); + expect(packages.deployToDesktop).toHaveBeenCalledWith(expectedDeployOptions, anyString, anyString); + }) + .catch(fail) + .finally(function() { + expect(fail).not.toHaveBeenCalled(); + done(); + }); + }); + + it('spec.9 should fall back to anycpu if --archs parameter is not specified', function(done) { + + spyOn(utils, 'isCordovaProject').andReturn(true); + spyOn(packages, 'getPackage').andReturn(Q({ arch: 'anycpu' })); + spyOn(packages, 'deployToDesktop').andReturn(Q()); + + var anyString = jasmine.any(String); + var expectedDeployOptions = jasmine.objectContaining({arch: 'anycpu'}); + + var fail = jasmine.createSpy('fail'); + + run.run({nobuild: true}) + .then(function () { + expect(packages.getPackage).toHaveBeenCalledWith(anyString, anyString, 'anycpu'); + expect(packages.deployToDesktop).toHaveBeenCalledWith(expectedDeployOptions, anyString, anyString); + }) + .catch(fail) + .finally(function() { + expect(fail).not.toHaveBeenCalled(); + done(); + }); + }); }); http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/5e45d700/template/cordova/lib/run.js ---------------------------------------------------------------------- diff --git a/template/cordova/lib/run.js b/template/cordova/lib/run.js index f67bd20..b2f362c 100644 --- a/template/cordova/lib/run.js +++ b/template/cordova/lib/run.js @@ -39,7 +39,7 @@ module.exports.run = function (options) { // parse arg var args = nopt({ - 'archs': String, + 'archs': [String], 'phone': Boolean, 'win': Boolean, 'appx': String, @@ -58,9 +58,14 @@ module.exports.run = function (options) { } // Get build/deploy options - var buildType = options.release ? 'release' : 'debug', - buildArchs = args.archs ? args.archs.split(' ') : ['anycpu'], - deployTarget = options.target ? options.target : (options.emulator ? 'emulator' : 'device'); + var buildType = options.release ? 'release' : 'debug'; + // CB-11478 Allow to specify 'archs' parameter as either cli or platform + // option i.e. 'cordova run --archs' vs. 'cordova run -- --archs' + var archs = options.archs || args.archs || ['anycpu']; + if (typeof archs === 'string') { archs = archs.split(' '); } + + var buildArchs = archs.map(function (arch) { return arch.toLowerCase(); }); + var deployTarget = options.target ? options.target : (options.emulator ? 'emulator' : 'device'); var buildTargets = build.getBuildTargets(args.win, args.phone, args.appx); @@ -73,7 +78,7 @@ module.exports.run = function (options) { var projectType = projFileToType(buildTargets[0]); // if --nobuild isn't specified then build app first - var buildPackages = options.nobuild ? packages.getPackage(projectType, buildType, buildArchs) : build.run.call(this, options); + var buildPackages = options.nobuild ? packages.getPackage(projectType, buildType, buildArchs[0]) : build.run.call(this, options); // buildPackages also deploys bundles return buildPackages --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org