You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ge...@apache.org on 2015/02/23 23:29:54 UTC

[2/8] cordova-lib git commit: Organize save logic some more

Organize save logic some more


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

Branch: refs/heads/master
Commit: 885cebccf050cc0640c93a81f8a595eea3118934
Parents: 9f26088
Author: Gorkem Ercan <go...@gmail.com>
Authored: Fri Feb 13 11:22:38 2015 -0500
Committer: Gorkem Ercan <go...@gmail.com>
Committed: Thu Feb 19 12:53:00 2015 -0500

----------------------------------------------------------------------
 cordova-lib/src/cordova/plugin.js | 60 ++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/885cebcc/cordova-lib/src/cordova/plugin.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/plugin.js b/cordova-lib/src/cordova/plugin.js
index 8c0d420..11be975 100644
--- a/cordova-lib/src/cordova/plugin.js
+++ b/cordova-lib/src/cordova/plugin.js
@@ -60,7 +60,7 @@ module.exports = function plugin(command, targets, opts) {
     var hooksRunner = new HooksRunner(projectRoot);
     var config_json = config.read(projectRoot);
     var platformList = cordova_util.listPlatforms(projectRoot);
-
+    var autosave =  config_json.auto_save_plugins || false;
     // Massage plugin name(s) / path(s)
     var pluginPath, plugins;
     pluginPath = path.join(projectRoot, 'plugins');
@@ -120,7 +120,7 @@ module.exports = function plugin(command, targets, opts) {
                         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)){
+                        if(!autosave && opts.save && !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);
 
@@ -135,6 +135,35 @@ module.exports = function plugin(command, targets, opts) {
                         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});
                     })
+                    .then(function(dir){
+                      // save to config.xml 
+
+                      if(autosave || opts.save){
+                        var pluginInfo =  pluginInfoProvider.get(dir);
+                        var existingFeature = cfg.getFeature(pluginInfo.id);
+                        if(!existingFeature){
+                          var params = [{name:'id', value:pluginInfo.id}];
+                          params.push({ name: 'version', value: pluginInfo.version});
+                          var url = require('url');
+
+                          var uri = url.parse(target);
+                          if ( uri.protocol && uri.protocol != 'file:' && uri.protocol[1] != ':' && !target.match(/^\w+:\\/)) {
+                            params.push({name:'url', value:target});
+                          }else{
+                            var plugin_dir = cordova_util.fixRelativePath(path.join(target,  (opts.subdir || '.') ));
+                            if (fs.existsSync(plugin_dir)) {
+                              params.push({name:'installPath', value:target});
+                            }
+                          }
+                          cfg.addFeature(pluginInfo.name, params);
+                          cfg.write();
+                          events.emit('results', 'Saved plugin info for "'+pluginInfo.id+'" to config.xml');
+                        }else{
+                          events.emit('results', 'Plugin info for "'+pluginInfo.id+'" already exists in config.xml');
+                        }
+                      }
+                      return dir;
+                    })
                     .then(function(dir) {
                         // Validate top-level required variables
                         var pluginVariables = pluginInfoProvider.get(dir).getPreferences(),
@@ -146,32 +175,6 @@ module.exports = function plugin(command, targets, opts) {
                             events.emit('results', 'Variable(s) missing (use: --variable ' + missingVariables.join('=value --variable ') + '=value).');
                             return;
                         }
-                        // save to config.xml 
-                       var autosave =  config_json.auto_save_plugins || false;
-                       if(autosave || opts.save){
-                         var pluginInfo =  pluginInfoProvider.get(dir);
-                         var existingFeature = cfg.getFeature(pluginInfo.id);
-                         if(!existingFeature){
-                           var params = [{name:'id', value:pluginInfo.id}];
-                           params.push({ name: 'version', value: pluginInfo.version});
-                           var url     = require('url');
-
-                           var uri = url.parse(target);
-                           if ( uri.protocol && uri.protocol != 'file:' && uri.protocol[1] != ':' && !target.match(/^\w+:\\/)) {
-                             params.push({name:'url', value:target});
-                           }else{
-                             var plugin_dir = cordova_util.fixRelativePath(path.join(target,  (opts.subdir || '.') ));
-                             if (fs.existsSync(plugin_dir)) {
-                               params.push({name:'installPath', value:target});
-                             }
-                           }
-                           cfg.addFeature(pluginInfo.name, params);
-                           cfg.write();
-                           events.emit('results', 'Saved plugin info for "'+pluginInfo.id+'" to config.xml');
-                         }else{
-                           events.emit('results', 'Plugin info for "'+pluginInfo.id+'" already exists in config.xml');
-                         }
-                       }
                         // Iterate (in serial!) over all platforms in the project and install the plugin.
                         return platformList.reduce(function(soFar, platform) {
                             return soFar.then(function() {
@@ -243,7 +246,6 @@ module.exports = function plugin(command, targets, opts) {
                         return plugman.raw.uninstall.uninstallPlugin(target, path.join(projectRoot, 'plugins'));
                     }).then(function(){
                       //remove plugin from config.xml
-                      var autosave =  config_json.auto_save_plugins || false;
                       if(autosave || opts.save){
                         var configPath = cordova_util.projectConfig(projectRoot);
                         if(fs.existsSync(configPath)){//should not happen with real life but needed for tests


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