You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2013/07/11 22:29:21 UTC

[14/22] git commit: adding fetch and fixing cli interface

adding fetch and fixing cli interface


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/587808c2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/587808c2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/587808c2

Branch: refs/heads/plugman-registry
Commit: 587808c24830b297216f4e093d0bfa8bc3a70ef2
Parents: 9beb41b
Author: Anis Kadri <an...@apache.org>
Authored: Mon Jun 17 15:30:31 2013 -0700
Committer: Anis Kadri <an...@apache.org>
Committed: Thu Jul 11 13:12:38 2013 -0700

----------------------------------------------------------------------
 main.js      | 11 ++++++-----
 package.json |  2 +-
 src/fetch.js | 52 ++++++++++++++++++++++++++++++++++------------------
 3 files changed, 41 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/587808c2/main.js
----------------------------------------------------------------------
diff --git a/main.js b/main.js
index 4602711..a4bac95 100755
--- a/main.js
+++ b/main.js
@@ -25,6 +25,7 @@ var path = require('path')
     , nopt = require('nopt')
     , plugins = require('./src/util/plugins')
     , registry = require('plugman-registry')
+    , config = require('./config')
     , plugman = require('./plugman');
 
 var known_opts = { 'platform' : [ 'ios', 'android', 'blackberry10', 'wp7', 'wp8' ]
@@ -68,14 +69,14 @@ process.on('uncaughtException', function(error){
 if (cli_opts.v) {
     console.log(package.name + ' version ' + package.version);
 }
-else if ((cli_opts.install || cli_opts.uninstall) && (!cli_opts.platform || !cli_opts.project || !cli_opts.plugin)) {
+else if ((cli_opts.install || cli_opts.uninstall || cli_opts.argv.original.length == 0) && (!cli_opts.platform || !cli_opts.project || !cli_opts.plugin)) {
     plugman.help();
 }
 else if (cli_opts.uninstall) {
     plugman.uninstall(cli_opts.platform, cli_opts.project, cli_opts.plugin, plugins_dir, { www_dir: cli_opts.www });
 }
 else if (cli_opts.adduser) {
-  registry.use(null, function(err) {
+  registry.use(config.registry, function(err) {
     registry.adduser(null, function(err) {
       if(err) return console.log(err);
       console.log('user added');
@@ -83,7 +84,7 @@ else if (cli_opts.adduser) {
   });
 }
 else if (cli_opts.publish) {
-  registry.use(null, function(err) {
+  registry.use(config.registry, function(err) {
     registry.publish([cli_opts.plugin], function(err, d) {
       if(err) return console.log('Error publishing plugin'); 
       console.log('plugin published');
@@ -91,7 +92,7 @@ else if (cli_opts.publish) {
   });
 }
 else if (cli_opts.unpublish) {
-  registry.use(null, function(err) {
+  registry.use(config.registry, function(err) {
     registry.unpublish([cli_opts.plugin, '--force'], function(err, d) {
       if(err) return console.log('Error unpublishing plugin'); 
       console.log('plugin unpublished');
@@ -99,7 +100,7 @@ else if (cli_opts.unpublish) {
   });
 }
 else if (cli_opts.search) {
-  registry.use(null, function(err) {
+  registry.use(config.registry, function(err) {
     registry.search(cli_opts.search.split(','), function(err, d) {
       if(err) return console.log(err); 
     });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/587808c2/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index f78d2ee..9e8cac7 100644
--- a/package.json
+++ b/package.json
@@ -24,7 +24,7 @@
     "underscore":"1.4.4",
     "dep-graph":"1.1.0",
     "semver": "1.x.x",
-    "plugman-registry": "0.0.1"
+    "plugman-registry": "0.0.2"
   },
   "devDependencies": {
     "jasmine-node": "1.7.0"

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/587808c2/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index 476d138..0589fb5 100644
--- a/src/fetch.js
+++ b/src/fetch.js
@@ -3,7 +3,8 @@ var shell   = require('shelljs'),
     plugins = require('./util/plugins'),
     xml_helpers = require('./util/xml-helpers'),
     metadata = require('./util/metadata'),
-    path    = require('path');
+    path    = require('path'),
+    registry    = require('plugman-registry');
 
 // possible options: link, subdir, git_ref
 module.exports = function fetchPlugin(plugin_dir, plugins_dir, options, callback) {
@@ -44,27 +45,42 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options, callback
         // Copy from the local filesystem.
         // First, read the plugin.xml and grab the ID.
         plugin_dir = path.join(plugin_dir, options.subdir);
-        var xml = xml_helpers.parseElementtreeSync(path.join(plugin_dir, 'plugin.xml'));
-        var plugin_id = xml.getroot().attrib.id;
 
-        var dest = path.join(plugins_dir, plugin_id);
+        var movePlugin = function(plugin_dir, linkable) {
+          var xml = xml_helpers.parseElementtreeSync(path.join(plugin_dir, 'plugin.xml'));
+          var plugin_id = xml.getroot().attrib.id;
 
-        shell.rm('-rf', dest);
-        if (options.link) {
-            fs.symlinkSync(plugin_dir, dest, 'dir');
-        } else {
-            shell.mkdir('-p', dest);
-            shell.cp('-R', path.join(plugin_dir, '*') , dest);
-        }
+          var dest = path.join(plugins_dir, plugin_id);
+
+          shell.rm('-rf', dest);
+          if (options.link && linkable) {
+              fs.symlinkSync(plugin_dir, dest, 'dir');
+          } else {
+              shell.mkdir('-p', dest);
+              shell.cp('-R', path.join(plugin_dir, '*') , dest);
+          }
+
+          var data = {
+              source: {
+                  type: 'local',
+                  path: plugin_dir
+              }
+          };
+          metadata.save_fetch_metadata(dest, data);
+
+          if (callback) callback(null, dest);
 
-        var data = {
-            source: {
-                type: 'local',
-                path: plugin_dir
-            }
         };
-        metadata.save_fetch_metadata(dest, data);
 
-        if (callback) callback(null, dest);
+        
+        if(!fs.existsSync(plugin_dir)) {
+          registry.use(null, function() {
+            registry.fetch(plugin_dir, function(err, plugin_dir) {
+              movePlugin(plugin_dir, false);
+            });
+          })
+        } else {
+          movePlugin(plugin_dir, true);
+        }
     }
 };