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/ca2bec10 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/ca2bec10 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/ca2bec10 Branch: refs/heads/master Commit: ca2bec1081a17bbb518857547ab387e7a0ec7f51 Parents: ccee1ac Author: Anis Kadri <[email protected]> Authored: Mon Jun 17 15:30:31 2013 -0700 Committer: Anis Kadri <[email protected]> Committed: Thu Jul 11 13:52:18 2013 -0700 ---------------------------------------------------------------------- main.js | 12 ++++++------ package.json | 2 +- src/fetch.js | 57 +++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 43 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ca2bec10/main.js ---------------------------------------------------------------------- diff --git a/main.js b/main.js index fa08057..94d0f2a 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' ] @@ -75,15 +76,14 @@ plugman.on('error', console.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)) { console.log(plugman.help()); - 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'); @@ -91,7 +91,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'); @@ -99,7 +99,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'); @@ -107,7 +107,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/ca2bec10/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index 5fef741..1eeeeb2 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "underscore":"1.4.4", "dep-graph":"1.1.0", "semver": "2.0.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/ca2bec10/src/fetch.js ---------------------------------------------------------------------- diff --git a/src/fetch.js b/src/fetch.js index 28d9994..71f8785 100644 --- a/src/fetch.js +++ b/src/fetch.js @@ -4,7 +4,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) { @@ -47,31 +48,45 @@ 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(uri.href, options.subdir); - var plugin_xml_path = path.join(plugin_dir, 'plugin.xml'); - require('../plugman').emit('log', 'Fetch is reading plugin.xml from location "' + plugin_xml_path + '"...'); - var xml = xml_helpers.parseElementtreeSync(plugin_xml_path); - var plugin_id = xml.getroot().attrib.id; - var dest = path.join(plugins_dir, plugin_id); + var movePlugin = function(plugin_dir, linkable) { + var plugin_xml_path = path.join(plugin_dir, 'plugin.xml'); + require('../plugman').emit('log', 'Fetch is reading plugin.xml from location "' + plugin_xml_path + '"...'); + var xml = xml_helpers.parseElementtreeSync(plugin_xml_path); + var plugin_id = xml.getroot().attrib.id; - shell.rm('-rf', dest); - if (options.link) { - require('../plugman').emit('log', 'Symlinking from location "' + plugin_dir + '" to location "' + dest + '"'); - fs.symlinkSync(plugin_dir, dest, 'dir'); - } else { - shell.mkdir('-p', dest); - require('../plugman').emit('log', 'Copying from location "' + plugin_dir + '" to location "' + dest + '"'); - shell.cp('-R', path.join(plugin_dir, '*'), dest); - } + var dest = path.join(plugins_dir, plugin_id); - var data = { - source: { - type: 'local', - path: plugin_dir + shell.rm('-rf', dest); + if (options.link && linkable) { + require('../plugman').emit('log', 'Symlinking from location "' + plugin_dir + '" to location "' + dest + '"'); + fs.symlinkSync(plugin_dir, dest, 'dir'); + } else { + shell.mkdir('-p', dest); + require('../plugman').emit('log', 'Copying from location "' + plugin_dir + '" to location "' + 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); }; - 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); + } } };
