You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/01/14 17:13:37 UTC
git commit: CB-5006 Plumb --searchpath into cordova plugin add
Updated Branches:
refs/heads/master 2f864ffc1 -> f183e9c61
CB-5006 Plumb --searchpath into cordova plugin add
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/f183e9c6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/f183e9c6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/f183e9c6
Branch: refs/heads/master
Commit: f183e9c617332928abd9e2edec69ce24eac70b41
Parents: 2f864ff
Author: Mark Koudritsky <ka...@chromium.org>
Authored: Fri Jan 10 16:31:11 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Jan 14 11:13:13 2014 -0500
----------------------------------------------------------------------
spec/cli.spec.js | 2 +-
src/cli.js | 6 +++---
src/plugin.js | 37 +++++++++++++++++++++++--------------
3 files changed, 27 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/f183e9c6/spec/cli.spec.js
----------------------------------------------------------------------
diff --git a/spec/cli.spec.js b/spec/cli.spec.js
index 1a00002..835e8eb 100644
--- a/spec/cli.spec.js
+++ b/spec/cli.spec.js
@@ -97,7 +97,7 @@ describe("cordova cli", function () {
it("will call command with all arguments passed through", function () {
new CLI(["node", "cordova", "plugin", "add", "facebook", "--variable", "FOO=foo"]);
- expect(cordova.raw.plugin).toHaveBeenCalledWith("add", ["facebook", "--variable", "FOO=foo"]);
+ expect(cordova.raw.plugin).toHaveBeenCalledWith("add", ["facebook", "--variable", "FOO=foo"], {searchpath: undefined});
});
});
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/f183e9c6/src/cli.js
----------------------------------------------------------------------
diff --git a/src/cli.js b/src/cli.js
index 2375337..8cabad8 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -49,6 +49,7 @@ module.exports = function CLI(inputArgs) {
.string('src')
.alias('src', 'source')
.string('link')
+ .string('searchpath')
.argv;
if (args.v || args.version) {
@@ -143,9 +144,8 @@ module.exports = function CLI(inputArgs) {
cordova.raw[cmd].call(this, args._[1], args._[2], args._[3], cfg).done();
} else {
// platform/plugins add/rm [target(s)]
- var invocation = tokens.slice(0,1); // this has the sub-command, i.e. "platform add" or "plugin rm"
+ var subcommand = tokens[0]; // this has the sub-command, like "add", "ls", "rm" etc.
var targets = tokens.slice(1); // this should be an array of targets, be it platforms or plugins
- invocation.push(targets);
- cordova.raw[cmd].apply(this, invocation).done();
+ cordova.raw[cmd].call(this, subcommand, targets, { searchpath: args.searchpath }).done();
}
};
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/f183e9c6/src/plugin.js
----------------------------------------------------------------------
diff --git a/src/plugin.js b/src/plugin.js
index d0edf78..3d04600 100644
--- a/src/plugin.js
+++ b/src/plugin.js
@@ -18,22 +18,37 @@
*/
// Returns a promise.
-module.exports = function plugin(command, targets) {
+module.exports = function plugin(command, targets, opts) {
var cordova_util = require('./util'),
path = require('path'),
hooker = require('./hooker'),
+ config = require('./config'),
Q = require('q'),
events = require('./events');
var projectRoot = cordova_util.cdProjectRoot(),
err;
- if (arguments.length === 0){
- command = 'ls';
- targets = [];
- } else {
+ // Dance with all the possible call signatures we've come up over the time. They can be:
+ // 1. plugin() -> list the plugins
+ // 2. plugin(command, Array of targets, maybe opts object)
+ // 3. plugin(command, target1, target2, target3 ... )
+ // The targets are not really targets, they can be a mixture of plugins and options to be passed to plugman.
+
+ command = command || 'ls';
+ targets = targets || [];
+ opts = opts || {};
+ if ( opts.length ) {
+ // This is the case with multiple targes as separate arguments and opts is not opts but another target.
targets = Array.prototype.slice.call(arguments, 1);
+ opts = {};
+ }
+ if ( !Array.isArray(targets) ) {
+ // This means we had a single target given as string.
+ targets = [targets];
}
+ opts.options = [];
+ opts.plugins = [];
var hooks = new hooker(projectRoot);
var platformList = cordova_util.listPlatforms(projectRoot);
@@ -50,14 +65,6 @@ module.exports = function plugin(command, targets) {
}
}
- var opts = {
- plugins: [],
- options: []
- };
-
- if (targets.length == 1 && Array.isArray(targets[0]))
- targets = targets[0];
-
//Split targets between plugins and options
//Assume everything after a token with a '-' is an option
var i;
@@ -76,6 +83,8 @@ module.exports = function plugin(command, targets) {
return Q.reject(new Error('No plugin specified. Please specify a plugin to add. See "plugin search".'));
}
+ var config_json = config(projectRoot, {});
+
return hooks.fire('before_plugin_add', opts)
.then(function() {
return opts.plugins.reduce(function(soFar, target) {
@@ -88,7 +97,7 @@ module.exports = function plugin(command, targets) {
// Fetch the plugin first.
events.emit('verbose', 'Calling plugman.fetch on plugin "' + target + '"');
var plugman = require('plugman');
- return plugman.raw.fetch(target, pluginsDir, {})
+ return plugman.raw.fetch(target, pluginsDir, { searchpath: opts.searchpath || config_json.plugin_search_path });
})
.fail(function(err) {
return Q.reject(new Error('Fetching plugin failed: ' + err));