You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ka...@apache.org on 2014/06/12 23:28:09 UTC
[2/2] git commit: Allow "cordova platform add platform@version"
Allow "cordova platform add platform@version"
This only works with --usenpm for now.
E.g.:
cordova platform add ios@3.5.0 --usenpm
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/4548595f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/4548595f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/4548595f
Branch: refs/heads/master
Commit: 4548595f1d5c40944d81098c6ea1b10d4e8d63aa
Parents: 8f63b94
Author: Mark Koudritsky <ka...@gmail.com>
Authored: Thu Jun 12 17:21:57 2014 -0400
Committer: Mark Koudritsky <ka...@gmail.com>
Committed: Thu Jun 12 17:21:57 2014 -0400
----------------------------------------------------------------------
cordova-lib/src/cordova/lazy_load.js | 14 +++++++++++--
cordova-lib/src/cordova/platform.js | 33 +++++++++++++++++++++++--------
2 files changed, 37 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4548595f/cordova-lib/src/cordova/lazy_load.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/lazy_load.js b/cordova-lib/src/cordova/lazy_load.js
index 69be060..875364e 100644
--- a/cordova-lib/src/cordova/lazy_load.js
+++ b/cordova-lib/src/cordova/lazy_load.js
@@ -76,10 +76,20 @@ function cordova_git(platform) {
}
function cordova_npm(platform) {
- if (!(platform in platforms)) {
+ var version;
+ // Check if platform looks like platform@version
+ if (platform.indexOf('@') != -1) {
+ var parts = platform.split('@');
+ platform = parts[0];
+ version = parts[1];
+ }
+ if ( !(platform in platforms) ) {
return Q.reject(new Error('Cordova library "' + platform + '" not recognized.'));
}
- var pkg = 'cordova-' + platform + '@' + platforms[platform].version;
+ // In most cases platfrom does not specify a version and we use
+ // the hard-coded default version from platforms.js
+ version = version || platforms[platform].version;
+ var pkg = 'cordova-' + platform + '@' + version;
return Q.nfcall( npm.load, {cache: path.join(util.libDirectory, 'npm_cache') })
.then(function() {
return Q.ninvoke(npm.commands, 'cache', ['add', pkg]);
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4548595f/cordova-lib/src/cordova/platform.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js
index 7890997..374b223 100644
--- a/cordova-lib/src/cordova/platform.js
+++ b/cordova-lib/src/cordova/platform.js
@@ -79,12 +79,18 @@ function add(hooks, projectRoot, targets, opts) {
throw new CordovaError('Unable to fetch platform ' + t + ': ' + err);
})
.then(function(libDir) {
- var template = config_json.lib && config_json.lib[t] && config_json.lib[t].template || null;
+ var platform = t;
+ if (platform.indexOf('@') != -1) {
+ // If platform contains @version part, strip it.
+ var parts = platform.split('@');
+ platform = parts[0];
+ }
+ var template = config_json.lib && config_json.lib[platform] && config_json.lib[platform].template || null;
var copts = null;
if ('spawnoutput' in opts) {
copts = opts.spawnoutput;
}
- return call_into_create(t, projectRoot, cfg, libDir, template, copts);
+ return call_into_create(platform, projectRoot, cfg, libDir, template, copts);
});
}))
.then(function() {
@@ -267,21 +273,32 @@ function list(hooks, projectRoot) {
module.exports = platform;
function platform(command, targets, opts) {
var projectRoot = cordova_util.cdProjectRoot();
-
+ var msg;
var hooks = new hooker(projectRoot);
if (arguments.length === 0) command = 'ls';
+
+ // Verify that targets look like platforms. Examples:
+ // - android
+ // - android@3.5.0
if (targets) {
if (!(targets instanceof Array)) targets = [targets];
var err;
targets.forEach(function(t) {
- if (!(t in platforms)) {
- err = new CordovaError('Platform "' + t + '" not recognized as a core cordova platform. See `'+cordova_util.binname+' platform list`.');
- }
+ // Trim the @version part if it's there.
+ var p = t.split('@')[0];
+ // OK if it's one of known platform names.
+ if ( p in platforms ) return;
+ var msg = 'Platform "' + t +
+ '" not recognized as a core cordova platform. See `' +
+ cordova_util.binname + ' platform list`.'
+ ;
+ throw new CordovaError(msg);
+
});
- if (err) return Q.reject(err);
} else if (command == 'add' || command == 'rm') {
- return Q.reject(new CordovaError('You need to qualify `add` or `remove` with one or more platforms!'));
+ msg = 'You need to qualify `add` or `remove` with one or more platforms!';
+ return Q.reject(new CordovaError(msg));
}