cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/5] git commit: adding fetch and fixing cli interface
Date Mon, 17 Jun 2013 23:17:14 GMT
Updated Branches:
  refs/heads/plugman-registry 92584416a -> bd1559899


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/79f14886
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/79f14886
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/79f14886

Branch: refs/heads/plugman-registry
Commit: 79f14886cd9ba2ec63252abbf8590f4654553ba1
Parents: 9258441
Author: Anis Kadri <anis@apache.org>
Authored: Mon Jun 17 15:30:31 2013 -0700
Committer: Anis Kadri <anis@apache.org>
Committed: Mon Jun 17 15:30:31 2013 -0700

----------------------------------------------------------------------
 main.js      | 15 ++++++++-------
 package.json |  2 +-
 src/fetch.js | 52 ++++++++++++++++++++++++++++++++++------------------
 3 files changed, 43 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/79f14886/main.js
----------------------------------------------------------------------
diff --git a/main.js b/main.js
index a07f335..77a6725 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' ]
@@ -64,14 +65,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)) {
     printUsage();
 }
 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');
@@ -79,7 +80,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');
@@ -87,7 +88,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');
@@ -95,7 +96,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); 
     });
@@ -120,10 +121,10 @@ else {
 
 function printUsage() {
     platforms = known_opts.platform.join('|');
-    console.log('Usage\n---------');
+    console.log('Usage\n-----');
     console.log('Install a plugin (will fetch if cannot be found):\n\t' + package.name +
' --platform <'+ platforms +'> --project <directory> --plugin <name|path|url>
[--www <directory>] [--plugins_dir <directory>] [--variable <name>=<value>]\n');
     console.log('Uninstall a plugin:\n\t' + package.name + ' --uninstall --platform <'+
platforms +'> --project <directory> --plugin <id> [--www <directory>]
[--plugins_dir <directory>]\n');
-    console.log('\n\t--plugins_dir defaults to <project>/cordova/plugins, but can be
any directory containing a subdirectory for each plugin');
+    console.log('\t--plugins_dir defaults to <project>/cordova/plugins, but can be
any directory containing a subdirectory for each plugin');
     console.log('\n\t--www defaults to the project\'s www folder, but can be any directory
where web assets should be installed into\n');
     console.log('Add a user account to the registry:\n\t' + package.name + ' --adduser\n');
     console.log('Publish a plugin:\n\t' + package.name + ' --publish --plugin plugin_directory\n');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/79f14886/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 7631b7e..1d0ea74 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/79f14886/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index 68f5113..992e5af 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) {
@@ -43,27 +44,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);
+        }
     }
 };


Mime
View raw message