You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2015/11/20 02:08:50 UTC
[3/9] cordova-lib git commit: CB-9987 Adds compatibility layer for
cordova.raw.* methods
CB-9987 Adds compatibility layer for cordova.raw.* methods
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/e6712b75
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/e6712b75
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/e6712b75
Branch: refs/heads/5.4.x
Commit: e6712b756f1e771ff5c85ed4b6a474551a2ed56f
Parents: 4f054b2
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Fri Nov 13 16:34:14 2015 +0300
Committer: Steve Gill <st...@gmail.com>
Committed: Thu Nov 19 16:38:41 2015 -0800
----------------------------------------------------------------------
cordova-lib/package.json | 1 +
cordova-lib/spec-cordova/build.spec.js | 19 ++++++++--
cordova-lib/spec-cordova/compile.spec.js | 17 +++++++++
cordova-lib/spec-cordova/emulate.spec.js | 17 +++++++++
cordova-lib/spec-cordova/run.spec.js | 18 ++++++++++
cordova-lib/src/cordova/build.js | 9 -----
cordova-lib/src/cordova/prepare.js | 2 +-
cordova-lib/src/cordova/util.js | 50 ++++++++++++++++++++++++++-
8 files changed, 120 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e6712b75/cordova-lib/package.json
----------------------------------------------------------------------
diff --git a/cordova-lib/package.json b/cordova-lib/package.json
index 88a3493..090ef0c 100644
--- a/cordova-lib/package.json
+++ b/cordova-lib/package.json
@@ -27,6 +27,7 @@
"elementtree": "0.1.6",
"glob": "4.0.6",
"init-package-json": "^1.2.0",
+ "nopt": "^3.0.6",
"npm": "^2.10.x",
"npmconf": "^2.1.x",
"opener": "1.4.1",
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e6712b75/cordova-lib/spec-cordova/build.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/build.spec.js b/cordova-lib/spec-cordova/build.spec.js
index 973e961..b521156 100644
--- a/cordova-lib/spec-cordova/build.spec.js
+++ b/cordova-lib/spec-cordova/build.spec.js
@@ -72,13 +72,28 @@ describe('build command', function() {
});
});
it('should pass down options', function(done) {
- cordova.raw.build({platforms: ['android'], options: ['--release']}).then(function() {
- var opts = {platforms: ['android'], options: ['--release'], verbose: false};
+ cordova.raw.build({platforms: ['android'], options: {release: true}}).then(function() {
+ var opts = {platforms: ['android'], options: {release: true}, verbose: false};
expect(prepare_spy).toHaveBeenCalledWith(opts);
expect(compile_spy).toHaveBeenCalledWith(opts);
done();
});
});
+
+ it('should convert options from old format and warn user about this', function (done) {
+ function warnSpy(message) {
+ expect(message).toMatch('The format of cordova.raw.* methods "options" argument was changed');
+ }
+
+ cordova.on('warn', warnSpy);
+ cordova.raw.build({platforms:['android'], options:['--release', '--cdvBuildOpt=opt']}).then(function () {
+ var opts = {platforms: ['android'], options: jasmine.objectContaining({release: true, argv: ['--cdvBuildOpt="opt"']}), verbose: false};
+ expect(prepare_spy).toHaveBeenCalledWith(opts);
+ expect(compile_spy).toHaveBeenCalledWith(opts);
+ cordova.off('warn', warnSpy);
+ done();
+ });
+ });
});
describe('hooks', function() {
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e6712b75/cordova-lib/spec-cordova/compile.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/compile.spec.js b/cordova-lib/spec-cordova/compile.spec.js
index 67a8968..7f4e8f6 100644
--- a/cordova-lib/spec-cordova/compile.spec.js
+++ b/cordova-lib/spec-cordova/compile.spec.js
@@ -79,6 +79,23 @@ describe('compile command', function() {
.fail(fail)
.fin(done);
});
+
+ it('should convert options from old format and warn user about this', function (done) {
+ function warnSpy(message) {
+ expect(message).toMatch('The format of cordova.raw.* methods "options" argument was changed');
+ }
+
+ cordova.on('warn', warnSpy);
+ cordova.raw.compile({platforms:['blackberry10'], options:['--release']}).then(function () {
+ expect(getPlatformApi).toHaveBeenCalledWith('blackberry10');
+ expect(platformApi.build).toHaveBeenCalledWith({release: true, argv: []});
+ })
+ .fail(fail)
+ .fin(function () {
+ cordova.off('warn', warnSpy);
+ done();
+ });
+ });
});
describe('hooks', function() {
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e6712b75/cordova-lib/spec-cordova/emulate.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/emulate.spec.js b/cordova-lib/spec-cordova/emulate.spec.js
index e38715f..4bf20b7 100644
--- a/cordova-lib/spec-cordova/emulate.spec.js
+++ b/cordova-lib/spec-cordova/emulate.spec.js
@@ -82,6 +82,23 @@ describe('emulate command', function() {
.fail(fail)
.fin(done);
});
+ it('should convert options from old format and warn user about this', function (done) {
+ function warnSpy(message) {
+ expect(message).toMatch('The format of cordova.raw.* methods "options" argument was changed');
+ }
+
+ cordova.on('warn', warnSpy);
+ cordova.raw.emulate({platforms:['ios'], options:['--optionTastic']}).then(function () {
+ expect(prepare_spy).toHaveBeenCalledWith(['ios']);
+ expect(getPlatformApi).toHaveBeenCalledWith('ios');
+ expect(platformApi.run).toHaveBeenCalledWith(jasmine.objectContaining({emulator: true, argv: ['--optionTastic']}));
+ })
+ .fail(fail)
+ .fin(function () {
+ cordova.off('warn', warnSpy);
+ done();
+ });
+ });
});
describe('hooks', function() {
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e6712b75/cordova-lib/spec-cordova/run.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/run.spec.js b/cordova-lib/spec-cordova/run.spec.js
index 627451b..bf260e9 100644
--- a/cordova-lib/spec-cordova/run.spec.js
+++ b/cordova-lib/spec-cordova/run.spec.js
@@ -84,6 +84,24 @@ describe('run command', function() {
expect(err).toBeUndefined();
}).fin(done);
});
+ it('should convert parameters from old format and warn user about this', function (done) {
+ function warnSpy(message) {
+ expect(message).toMatch('The format of cordova.raw.* methods "options" argument was changed');
+ }
+
+ cordova.on('warn', warnSpy);
+ cordova.raw.run({platforms: ['blackberry10'], options:['--password=1q1q']}).then(function() {
+ expect(prepare_spy).toHaveBeenCalledWith({ platforms: [ 'blackberry10' ],
+ options: jasmine.objectContaining({argv:['--password="1q1q"']}), verbose: false });
+ expect(platformApi.run).toHaveBeenCalledWith(jasmine.objectContaining({argv:['--password="1q1q"']}));
+ }, function(err) {
+ expect(err).toBeUndefined();
+ })
+ .fin(function () {
+ cordova.off('warn', warnSpy);
+ done();
+ });
+ });
});
describe('hooks', function() {
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e6712b75/cordova-lib/src/cordova/build.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/build.js b/cordova-lib/src/cordova/build.js
index a35ba46..d734d1a 100644
--- a/cordova-lib/src/cordova/build.js
+++ b/cordova-lib/src/cordova/build.js
@@ -23,15 +23,6 @@ var cordovaUtil = require('./util'),
// Returns a promise.
module.exports = function build(options) {
var projectRoot = cordovaUtil.cdProjectRoot();
-
- if (!options) {
- options = {
- verbose: false,
- platforms: [],
- options: []
- };
- }
-
options = cordovaUtil.preProcessOptions(options);
// fire build hooks
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e6712b75/cordova-lib/src/cordova/prepare.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/prepare.js b/cordova-lib/src/cordova/prepare.js
index c791c9b..38c2e4d 100644
--- a/cordova-lib/src/cordova/prepare.js
+++ b/cordova-lib/src/cordova/prepare.js
@@ -32,7 +32,7 @@ exports = module.exports = prepare;
function prepare(options) {
var projectRoot = cordova_util.cdProjectRoot();
var config_json = config.read(projectRoot);
- options = options || { verbose: false, platforms: [], options: [] };
+ options = options || { verbose: false, platforms: [], options: {} };
var hooksRunner = new HooksRunner(projectRoot);
return hooksRunner.fire('before_prepare', options)
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e6712b75/cordova-lib/src/cordova/util.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/util.js b/cordova-lib/src/cordova/util.js
index da1d208..67f9b69 100644
--- a/cordova-lib/src/cordova/util.js
+++ b/cordova-lib/src/cordova/util.js
@@ -20,10 +20,12 @@
/* jshint sub:true */
var fs = require('fs'),
path = require('path'),
+ events = require('cordova-common').events,
CordovaError = require('cordova-common').CordovaError,
shell = require('shelljs'),
url = require('url'),
npm = require('npm'),
+ nopt = require('nopt'),
Q = require('q'),
semver = require('semver');
@@ -233,7 +235,7 @@ function preProcessOptions (inputOptions) {
}
result.verbose = result.verbose || false;
result.platforms = result.platforms || [];
- result.options = result.options || {};
+ result.options = ensurePlatformOptionsCompatible(result.options);
var projectRoot = this.isCordova();
@@ -255,6 +257,52 @@ function preProcessOptions (inputOptions) {
return result;
}
+/**
+ * Converts options, which is passed to platformApi from old format (array of
+ * plain strings) to new - nopt-parsed object + array of platform-specific
+ * options. If options are already in new the format - returns them unchanged.
+ *
+ * @param {Object|String[]} platformOptions A platform options (array of
+ * strings or object) which is passed down to platform scripts/platformApi
+ * polyfill.
+ *
+ * @return {Object} Options, converted to new format
+ */
+function ensurePlatformOptionsCompatible (platformOptions) {
+ var opts = platformOptions || {};
+
+ if (!Array.isArray(opts))
+ return opts;
+
+ events.emit('warn', 'The format of cordova.raw.* methods "options" argument was changed in 5.4.0. ' +
+ '"options.options" property now should be an object instead of an array of plain strings. Though the old format ' +
+ 'is still supported, consider updating your cordova.raw.* method calls to use new argument format.');
+
+ var knownArgs = [
+ 'debug',
+ 'release',
+ 'device',
+ 'emulator',
+ 'nobuild',
+ 'list',
+ 'buildConfig',
+ 'target',
+ 'archs'
+ ]
+
+ opts = nopt({}, {}, opts, 0);
+ opts.argv = Object.keys(opts)
+ .filter(function (arg) {
+ return arg !== 'argv' && knownArgs.indexOf(arg) === -1;
+ }).map(function (arg) {
+ return opts[arg] === true ?
+ '--' + arg :
+ '--' + arg + '="' + opts[arg].toString() + '"';
+ });
+
+ return opts;
+}
+
function isDirectory(dir) {
try {
return fs.lstatSync(dir).isDirectory();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org