Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 941DBCD02 for ; Fri, 27 Jul 2012 00:29:18 +0000 (UTC) Received: (qmail 35480 invoked by uid 500); 27 Jul 2012 00:29:17 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 35391 invoked by uid 500); 27 Jul 2012 00:29:16 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 34610 invoked by uid 99); 27 Jul 2012 00:29:15 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Jul 2012 00:29:15 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 7DC8B192C4; Fri, 27 Jul 2012 00:29:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anis@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [19/78] [abbrv] git commit: plugin support! Message-Id: <20120727002915.7DC8B192C4@tyr.zones.apache.org> Date: Fri, 27 Jul 2012 00:29:15 +0000 (UTC) plugin support! Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/e878b35b Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/e878b35b Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/e878b35b Branch: refs/heads/cordova-client Commit: e878b35b87e493e9c1eae0a631b27c6016d9835d Parents: 3bcbcf0 Author: Fil Maj Authored: Tue Jul 17 16:52:42 2012 -0700 Committer: Fil Maj Committed: Tue Jul 17 16:52:42 2012 -0700 ---------------------------------------------------------------------- README.md | 2 - src/plugin.js | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/e878b35b/README.md ---------------------------------------------------------------------- diff --git a/README.md b/README.md index d5b7816..c2019bf 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,6 @@ launch for. ## TO-DO -- clean up build + emulate commands -- add plugin integration via pluginstall - `grep` through this project for 'TODO' - blackberry support - moar tests http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/e878b35b/src/plugin.js ---------------------------------------------------------------------- diff --git a/src/plugin.js b/src/plugin.js new file mode 100644 index 0000000..8de5c01 --- /dev/null +++ b/src/plugin.js @@ -0,0 +1,76 @@ +var cordova_util = require('./util'), + util = require('util'), + wrench = require('wrench'), + fs = require('fs'), + path = require('path'), + config_parser = require('./config_parser'), + exec = require('child_process').exec, + ls = fs.readdirSync; + +module.exports = function plugin(command, target) { + var projectRoot = cordova_util.isCordova(process.cwd()); + + if (!projectRoot) { + console.error('Current working directory is not a Cordova-based project.'); + return; + } + if (arguments.length === 0) command = 'ls'; + + // Grab config info for the project + var xml = path.join(projectRoot, 'www', 'config.xml'); + var cfg = new config_parser(xml); + var platforms = cfg.ls_platforms(); + + // Massage plugin name / path + var pluginPath = path.join(projectRoot, 'plugins'); + var plugins = ls(pluginPath); + var targetName = target.substr(target.lastIndexOf('/') + 1); + if (targetName[targetName.length-1] == '/') targetName = targetName.substr(0, targetName.length-1); + + switch(command) { + case 'ls': + if (plugins.length) { + plugins.map(function(plugin) { + console.log(plugin); + }); + } else console.log('No plugins added. Use `cordova plugin add .'); + break; + case 'add': + // Check if we already have the plugin. + if (plugins.indexOf(targetName) > -1) { + console.error('Plugin "' + targetName + '" already added to project.'); + return; + } + + // Check if the plugin has a plugin.xml in the root of the + // specified dir. + var pluginContents = ls(target); + if (pluginContents.indexOf('plugin.xml') == -1) { + console.error('Plugin "' + targetName + '" does not have a plugin.xml in the root. Plugin must support the Cordova Plugin Specification: https://github.com/alunny/cordova-plugin-spec'); + return; + } + + // Iterate over all platforms in the project and install the + // plugin. + var cli = path.join(__dirname, '..', 'node_modules', 'pluginstall', 'cli.js'); + platforms.map(function(platform) { + var cmd = util.format('%s %s "%s" "%s"', cli, platform, path.join(projectRoot, 'platforms', platform), target); + console.log(cmd); + exec(cmd, function(err, stderr, stdout) { + if (err) { + console.error('An error occured during plugin installation. ', err); + console.error(stderr); + } + }); + }); + + break; + case 'remove': + console.error('Plugin removal not supported yet! sadface'); + break; + default: + console.error('Unrecognized command "' + command + '". Use either `add`, `remove`, or `ls`.'); + break; + } + +};