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/03/06 01:26:56 UTC

[20/27] cordova-lib git commit: CB-8551 split up changePluginId into two functions

CB-8551 split up changePluginId into two functions


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

Branch: refs/heads/master
Commit: 1cae265e5107df801e765f2217780d2cb0283cff
Parents: aac6a1b
Author: Steve Gill <st...@gmail.com>
Authored: Wed Mar 4 13:34:35 2015 -0800
Committer: Steve Gill <st...@gmail.com>
Committed: Wed Mar 4 13:34:35 2015 -0800

----------------------------------------------------------------------
 cordova-lib/src/plugman/registry/registry.js | 56 ++++++++++++++---------
 cordova-lib/src/plugman/uninstall.js         |  2 +-
 2 files changed, 35 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/1cae265e/cordova-lib/src/plugman/registry/registry.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/registry/registry.js b/cordova-lib/src/plugman/registry/registry.js
index ed0e221..b4773fc 100644
--- a/cordova-lib/src/plugman/registry/registry.js
+++ b/cordova-lib/src/plugman/registry/registry.js
@@ -167,7 +167,17 @@ module.exports = {
      */
     fetch: function(plugin, client) {
         plugin = plugin.shift();
-        return checkPluginID(plugin)
+        return Q()
+        .then(function() {
+            //check to see if pluginID is reverse domain name style
+            if(isValidCprName(plugin)){
+                return Q();
+            } else {
+                //fetch from npm
+                events.emit('verbose', 'Skipping CPR');
+                return Q.reject();
+            }
+        })
         .then(function() {
             return fetchPlugReg(plugin, client);
         })
@@ -399,31 +409,33 @@ function fetchPlugReg(plugin, client) {
 }
 
 /**
- * @method checkPluginID
  * @param {Array} with one element - the plugin id or "id@version"
- * @return {Promise.<string>} Promised path to fetched package.
+ * @return {Boolean} if pluginID is reverse domain name style.
  */
-function checkPluginID(plugin) {
+function isValidCprName(plugin) {
     //if plugin id is not reverse domain name style, skip CPR and fetch from npm
 
-    //Create regex to for digits, words and dashes and three dots in plugin ids which excludes @VERSION.
-    var re = /([\w-]*\.[\w-]*\.[\w-]*\.[\w-]*[^@])/;
-    var pluginID = plugin.match(re);
-    //If pluginID equals null, plugin is not reverse domain name style
-    if(pluginID === null) { 
-        events.emit('verbose', 'Skipping CPR');
-        //Q.reject will send us straight to the fail method which is where fetchNPM gets called.
-        return Q.reject();
+    //Create regex that checks for at least two dots with any characters except @ to determine if it is reverse domain name style.
+    var matches = /([^@]*\.[^@]*\.[^@]*)/.exec(plugin)
+
+    //If matches equals null, plugin is not reverse domain name style
+    if(matches === null) { 
+        return false;
     } else {
-        //Reverse domain name style plugin ID
-        //Check if a mapping exists for the pluginID
-        //if it does, warn the users to use package-name
-        var packageName = pluginMapper[pluginID[0]];
-        if(packageName) {
-            events.emit('log', 'WARNING: ' + plugin + ' has been renamed to ' + 
-                    packageName + '. You may not be getting the latest version! We suggest you `cordova plugin rm ' + 
-                    plugin + '` and `cordova plugin add ' + packageName + '`.');
-        }
+        warnIfIdInMapper(plugin, matches);
+    }
+    return true 
+}
+
+/**
+ * @param {Array} - the plugin id or "id@version"
+ */
+function warnIfIdInMapper(plugin, pluginID) {
+    //Reverse domain name style plugin ID
+    //Check if a mapping exists for the pluginID
+    //if it does, warn the users to use package-name
+    var packageName = pluginMapper[pluginID[0]];
+    if(packageName) {
+        events.emit('log', 'WARNING: ' + plugin + ' has been renamed to ' + packageName + '. You may not be getting the latest version! We suggest you `cordova plugin rm ' + plugin + '` and `cordova plugin add ' + packageName + '`.');
     }
-    return Q(); 
 }

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/1cae265e/cordova-lib/src/plugman/uninstall.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/uninstall.js b/cordova-lib/src/plugman/uninstall.js
index 6a84ea1..4d09996 100644
--- a/cordova-lib/src/plugman/uninstall.js
+++ b/cordova-lib/src/plugman/uninstall.js
@@ -47,7 +47,7 @@ function uninstall(platform, project_dir, id, plugins_dir, options) {
     options.is_top_level = true;
     options.pluginInfoProvider = options.pluginInfoProvider || new PluginInfoProvider();
     plugins_dir = plugins_dir || path.join(project_dir, 'cordova', 'plugins');
-    
+
     // Allow `id` to be a path to a file.
     var xml_path = path.join(id, 'plugin.xml');
     if ( fs.existsSync(xml_path) ) {


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