tweaking readme, added a plugin.xml parser module.
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/c2ceb9ad Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/c2ceb9ad Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/c2ceb9ad Branch: refs/heads/cordova-client Commit: c2ceb9ad90f935bd17fabf14c6dbbdf6f2b48da6 Parents: f55d0e8 Author: Fil Maj <maj....@gmail.com> Authored: Wed Sep 12 12:49:22 2012 -0700 Committer: Fil Maj <maj....@gmail.com> Committed: Wed Sep 12 12:49:22 2012 -0700 ---------------------------------------------------------------------- README.md | 4 ++-- spec/config_parser.spec.js | 2 +- spec/fixtures/plugins/test/plugin.xml | 6 ++++++ spec/plugin.spec.js | 6 +++--- spec/plugin_parser.spec.js | 25 +++++++++++++++++++++++++ src/plugin.js | 2 ++ src/plugin_parser.js | 13 +++++++++++++ 7 files changed, 52 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/c2ceb9ad/README.md ---------------------------------------------------------------------- diff --git a/README.md b/README.md index 27c0ed0..b615fac 100644 --- a/README.md +++ b/README.md @@ -138,12 +138,12 @@ Plugin integration hinges on: vice-versa) - npm package - bootstrapping the tests -- figure out versioning. for now: 2.1.0 minimum - properly extracting info from config.xml -- testing on machines other than Mac OS X - checking SDK compatibility - blackberry support - windows phone support +- testing on machines other than Mac OS X +- figure out versioning. for now: 2.1.0 minimum ### Bash Completions http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/c2ceb9ad/spec/config_parser.spec.js ---------------------------------------------------------------------- diff --git a/spec/config_parser.spec.js b/spec/config_parser.spec.js index e26d170..59a5f2b 100644 --- a/spec/config_parser.spec.js +++ b/spec/config_parser.spec.js @@ -9,7 +9,7 @@ var cordova = require('../cordova'), et = require('elementtree'), xml = path.join(tempDir, 'www', 'config.xml'); -describe('config parser', function () { +describe('config.xml parser', function () { beforeEach(function() { // Make a temp directory try { rmrf(tempDir); } catch(e) {} http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/c2ceb9ad/spec/fixtures/plugins/test/plugin.xml ---------------------------------------------------------------------- diff --git a/spec/fixtures/plugins/test/plugin.xml b/spec/fixtures/plugins/test/plugin.xml index ed33b8a..5d2a829 100644 --- a/spec/fixtures/plugins/test/plugin.xml +++ b/spec/fixtures/plugins/test/plugin.xml @@ -7,5 +7,11 @@ <name>Test Plugin</name> <asset src="www/test.js" target="test.js" /> + <platform name="android"> + </platform> + <platform name="ios"> + </platform> + <platform name="blackberry"> + </platform> </plugin> http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/c2ceb9ad/spec/plugin.spec.js ---------------------------------------------------------------------- diff --git a/spec/plugin.spec.js b/spec/plugin.spec.js index 6354f5c..54bbc4b 100644 --- a/spec/plugin.spec.js +++ b/spec/plugin.spec.js @@ -42,7 +42,7 @@ describe('plugin command', function() { }).toThrow(); }); - describe('ls', function() { + describe('`ls`', function() { var cwd = process.cwd(); beforeEach(function() { @@ -60,10 +60,10 @@ describe('plugin command', function() { }); }); - describe('add', function() { + describe('`add`', function() { }); - describe('remove', function() { + describe('`remove`', function() { }); }); http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/c2ceb9ad/spec/plugin_parser.spec.js ---------------------------------------------------------------------- diff --git a/spec/plugin_parser.spec.js b/spec/plugin_parser.spec.js new file mode 100644 index 0000000..46cac08 --- /dev/null +++ b/spec/plugin_parser.spec.js @@ -0,0 +1,25 @@ +var cordova = require('../cordova'), + path = require('path'), + fs = require('fs'), + plugin_parser = require('../src/plugin_parser'), + et = require('elementtree'), + xml = path.join(__dirname, 'fixtures', 'plugins', 'test', 'plugin.xml'); + +describe('plugin.xml parser', function () { + it('should read a proper plugin.xml file', function() { + var cfg; + expect(function () { + cfg = new plugin_parser(xml); + }).not.toThrow(); + expect(cfg).toBeDefined(); + expect(cfg.doc).toBeDefined(); + }); + it('should be able to figure out which platforms the plugin supports', function() { + var cfg = new plugin_parser(xml); + expect(cfg.platforms.length).toBe(3); + expect(cfg.platforms.indexOf('android') > -1).toBe(true); + expect(cfg.platforms.indexOf('ios') > -1).toBe(true); + expect(cfg.platforms.indexOf('blackberry') > -1).toBe(true); + }); +}); + http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/c2ceb9ad/src/plugin.js ---------------------------------------------------------------------- diff --git a/src/plugin.js b/src/plugin.js index bb6664f..eb1e71a 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -40,6 +40,8 @@ module.exports = function plugin(command, target, callback) { break; case 'add': // Check if we already have the plugin. + // TODO edge case: if a new platform is added, then you want + // to re-add the plugin to the new platform. if (plugins.indexOf(targetName) > -1) { throw 'Plugin "' + targetName + '" already added to project.'; } http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/c2ceb9ad/src/plugin_parser.js ---------------------------------------------------------------------- diff --git a/src/plugin_parser.js b/src/plugin_parser.js new file mode 100644 index 0000000..8a1c53d --- /dev/null +++ b/src/plugin_parser.js @@ -0,0 +1,13 @@ +var et = require('elementtree'), + platforms = require('./../platforms'), + fs = require('fs'); + +function plugin_parser(xmlPath) { + this.path = xmlPath; + this.doc = new et.ElementTree(et.XML(fs.readFileSync(xmlPath, 'utf-8'))); + this.platforms = this.doc.findall('platform').map(function(p) { + return p.attrib.name; + }); +} + +module.exports = plugin_parser;