cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [10/12] cordova-lib git commit: CB-8420 Make `cordova plugin add FOO` use version from config.xml (close #162)
Date Fri, 13 Feb 2015 00:54:06 GMT
CB-8420 Make `cordova plugin add FOO` use version from config.xml (close #162)


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/629b8867
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/629b8867
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/629b8867

Branch: refs/heads/CB-8416
Commit: 629b8867cd44a4d89b5dadd17e1b33f8cbf8b120
Parents: 36194fa
Author: Omar Mefire <ommenjik@microsoft.com>
Authored: Fri Feb 6 18:03:46 2015 -0800
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Feb 11 15:44:03 2015 -0500

----------------------------------------------------------------------
 cordova-lib/src/cordova/platform.js | 18 ++----------------
 cordova-lib/src/cordova/plugin.js   | 23 +++++++++++++++++++++++
 cordova-lib/src/cordova/util.js     | 18 +++++++++++++++++-
 3 files changed, 42 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/629b8867/cordova-lib/src/cordova/platform.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js
index 214dd61..a1eee41 100644
--- a/cordova-lib/src/cordova/platform.js
+++ b/cordova-lib/src/cordova/platform.js
@@ -17,7 +17,6 @@
     under the License.
 */
 
-var url = require('url');
 var config            = require('./config'),
     cordova           = require('./cordova'),
     cordova_util      = require('./util'),
@@ -103,7 +102,7 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
                 }
                 if (version) {
                     var maybeDir = cordova_util.fixRelativePath(version);
-                    if (isDirectory(maybeDir)) {
+                    if (cordova_util.isDirectory(maybeDir)) {
                         return getPlatformDetailsFromDir(maybeDir, platform);
                     }
                 }
@@ -175,25 +174,12 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
     });
 }
 
-function isDirectory(dir) {
-    try {
-	return fs.lstatSync(dir).isDirectory();
-    } catch(e) {
-	return false;
-    }
-}
-
-function isUrl(value) {
-    var u = value && url.parse(value);
-    return !!(u && u.protocol && u.protocol.length > 1); // Account for
windows c:/ paths
-}
-
 // Downloads via npm or via git clone (tries both)
 // Returns a Promise
 function downloadPlatform(projectRoot, platform, version, opts) {
     var target = version ? (platform + '@' + version) : platform;
     return Q().then(function() {
-        if (isUrl(version)) {
+        if (cordova_util.isUrl(version)) {
             events.emit('log', 'git cloning: ' + version);
             return lazy_load.git_clone(version);
         }

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/629b8867/cordova-lib/src/cordova/plugin.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/plugin.js b/cordova-lib/src/cordova/plugin.js
index b044a2f..7f34ddd 100644
--- a/cordova-lib/src/cordova/plugin.js
+++ b/cordova-lib/src/cordova/plugin.js
@@ -91,6 +91,8 @@ module.exports = function plugin(command, targets, opts) {
                 return Q.reject(new CordovaError('No plugin specified. Please specify a plugin
to add. See `'+cordova_util.binname+' plugin search`.'));
             }
 
+            var xml = cordova_util.projectConfig(projectRoot);
+            var cfg = new ConfigParser(xml);
             var config_json = config.read(projectRoot);
             var searchPath = config_json.plugin_search_path || [];
             if (typeof opts.searchpath == 'string') {
@@ -114,6 +116,22 @@ module.exports = function plugin(command, targets, opts) {
                             target = target.substring(0, target.length - 1);
                         }
 
+                        var parts = target.split('@');
+                        var id = parts[0];
+                        var version = parts[1];
+
+                        // If no version is specified, retrieve the version from config.xml
+                        if(!version && !cordova_util.isUrl(id) && !cordova_util.isDirectory(id)){
+                            events.emit('verbose', 'no version specified, retrieving version
from config.xml');
+                            var ver = getVersionFromConfigFile(id, cfg);
+
+                            if( cordova_util.isUrl(ver) || cordova_util.isDirectory(ver)
){
+                                target = ver;
+                            } else {
+                                target = ver ? (id + '@' + ver) : target;
+                            }
+                        }
+
                         // Fetch the plugin first.
                         events.emit('verbose', 'Calling plugman.fetch on plugin "' + target
+ '"');
                         return plugman.raw.fetch(target, pluginsDir, { searchpath: searchPath,
noregistry: opts.noregistry, link: opts.link, pluginInfoProvider: pluginInfoProvider});
@@ -230,6 +248,11 @@ module.exports = function plugin(command, targets, opts) {
     }
 };
 
+function getVersionFromConfigFile(plugin, cfg){
+    var feature = cfg.getFeature(plugin);
+    return feature && feature.params.version; 
+}
+
 function list(projectRoot, hooksRunner) {
     var pluginsList = [];
     return hooksRunner.fire('before_plugin_ls')

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/629b8867/cordova-lib/src/cordova/util.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/util.js b/cordova-lib/src/cordova/util.js
index 700f77a..4382b66 100644
--- a/cordova-lib/src/cordova/util.js
+++ b/cordova-lib/src/cordova/util.js
@@ -21,7 +21,8 @@
 var fs            = require('fs'),
     path          = require('path'),
     CordovaError  = require('../CordovaError'),
-    shell         = require('shelljs');
+    shell         = require('shelljs'),
+    url           = require('url');
 
 // Global configuration paths
 var global_config_path = process.env['CORDOVA_HOME'];
@@ -52,6 +53,13 @@ exports.preProcessOptions = preProcessOptions;
 exports.addModuleProperty = addModuleProperty;
 exports.getOrigWorkingDirectory = getOrigWorkingDirectory;
 exports.fixRelativePath = fixRelativePath;
+exports.isDirectory = isDirectory;
+exports.isUrl = isUrl;
+
+function isUrl(value) {
+    var u = value && url.parse(value);
+    return !!(u && u.protocol && u.protocol.length > 1); // Account for
windows c:/ paths
+}
 
 function isRootDir(dir) {
     if (fs.existsSync(path.join(dir, 'www'))) {
@@ -228,6 +236,14 @@ function preProcessOptions (inputOptions) {
     return result;
 }
 
+function isDirectory(dir) {
+    try {
+	return fs.lstatSync(dir).isDirectory();
+    } catch(e) {
+	return false;
+    }
+}
+
 // opt_wrap is a boolean: True means that a callback-based wrapper for the promise-based
function
 // should be created.
 function addModuleProperty(module, symbol, modulePath, opt_wrap, opt_obj) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message