cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/2] git commit: removing xmldom dependency and using elementtree
Date Mon, 29 Jul 2013 22:59:45 GMT
removing xmldom dependency and using elementtree


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/f658f701
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/f658f701
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/f658f701

Branch: refs/heads/master
Commit: f658f70148784334f029b04681728ace62e8869d
Parents: 0d2e391
Author: Anis Kadri <anis@apache.org>
Authored: Mon Jul 29 15:59:41 2013 -0700
Committer: Anis Kadri <anis@apache.org>
Committed: Mon Jul 29 15:59:41 2013 -0700

----------------------------------------------------------------------
 package.json                   |  3 +-
 spec/registry/registry.spec.js |  2 +-
 src/registry/manifest.js       | 59 +++++++++++++------------------------
 3 files changed, 22 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f658f701/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 82e2448..a1db45e 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "author": "Andrew Lunny <alunny@gmail.com>",
   "name": "plugman",
   "description": "install/uninstall Cordova plugins",
-  "version": "0.9.23",
+  "version": "0.9.24",
   "repository": {
     "type": "git",
     "url": "git://git-wip-us.apache.org/repos/asf/cordova-plugman.git"
@@ -31,7 +31,6 @@
     "semver": "2.0.x",
     "npm": "1.3.4",
     "rc": "0.3.0",
-    "xmldom": "0.1.16",
     "tar.gz": "0.1.1"
   },
   "devDependencies": {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f658f701/spec/registry/registry.spec.js
----------------------------------------------------------------------
diff --git a/spec/registry/registry.spec.js b/spec/registry/registry.spec.js
index 8b26c1f..68c930b 100644
--- a/spec/registry/registry.spec.js
+++ b/spec/registry/registry.spec.js
@@ -18,7 +18,7 @@ describe('registry', function() {
         it('should generate a package.json from a plugin.xml', function() {
             manifest.generatePackageJsonFromPluginXml(pluginDir);
             expect(fs.existsSync(packageJson));
-            expect(JSON.parse(fs.readFileSync(packageJson)).name).toEqual('dummyplugin');
+            expect(JSON.parse(fs.readFileSync(packageJson)).name).toEqual('com.phonegap.plugins.dummyplugin');
             expect(JSON.parse(fs.readFileSync(packageJson)).version).toEqual('0.6.0');
         });
     });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f658f701/src/registry/manifest.js
----------------------------------------------------------------------
diff --git a/src/registry/manifest.js b/src/registry/manifest.js
index 9a6e66c..129a828 100644
--- a/src/registry/manifest.js
+++ b/src/registry/manifest.js
@@ -1,4 +1,4 @@
-var DOMParser = require('xmldom').DOMParser,
+var xml_helpers = require('../util/xml-helpers'),
     path = require('path'),
     fs = require('fs');
 
@@ -12,54 +12,35 @@ function handleError(err, cb) {
 // Java world big-up!
 function generatePackageJsonFromPluginXml(plugin_path, cb) {
   var package_json = {};
-  var plugin_xml = fs.readFileSync(path.resolve(plugin_path, 'plugin.xml'), "utf8");
-  var doc = new DOMParser().parseFromString(plugin_xml);
+  var pluginXml = xml_helpers.parseElementtreeSync(path.join(plugin_path, 'plugin.xml'));
   
-  if(!doc || !doc.documentElement) {
-    throw new Error('invalid plugin.xml document');
-  }
+  if(!pluginXml) return handleError(new Error('invalid plugin.xml document'), cb);
 
-  // name, version REQUIRED
-  // setting version
-  var version = doc.documentElement.getAttribute('version')
-  if(!version) {
-    var e = new Error('`version` required');
-    return handleError(e, cb)
-  }
+  var pluginElm = pluginXml.getroot();
+  
+  if(!pluginElm) return handleError(new Error('invalid plugin.xml document'), cb);
+  
+  // REQUIRED: name, version REQUIRED
+  // OPTIONAL: description, license, keywords
+  var name = pluginElm.attrib.id,
+      version = pluginElm.attrib.version,
+      description = pluginElm.findtext('description'),
+      license = pluginElm.findtext('license'),
+      keywords = pluginElm.findtext('keywords');
+
+  if(!version) return handleError(new Error('`version` required'), cb)
   package_json.version = version;
 
-  // setting name
-  if(doc.documentElement.getElementsByTagName('name').length != 1 ||
-     !doc.documentElement.getElementsByTagName('name').item(0).firstChild) {
-    var e = new Error('`name` is required');
-    return handleError(e, cb)
-  }
-  var name = doc.documentElement.getElementsByTagName('name').item(0).firstChild.nodeValue;
+  if(!name) return handleError(new Error('`name` is required'), cb)
   if(!name.match(/^\w+|-*$/)) {
       var e = new Error('`name` can only contain alphanumberic characters and -')
       return handleError(e, cb);
   }
   package_json.name = name.toLowerCase();
 
-  // OPTIONAL fields: description, license, keywords. TODO: add more!
-  if(doc.documentElement.getElementsByTagName('description').length == 1 &&
-     doc.documentElement.getElementsByTagName('description').item(0).firstChild) {
-    package_json.description = doc.documentElement
-                                  .getElementsByTagName('description')
-                                  .item(0).firstChild.nodeValue;
-  }
-  if(doc.documentElement.getElementsByTagName('license').length == 1 &&
-     doc.documentElement.getElementsByTagName('license').item(0).firstChild) {
-    package_json.license = doc.documentElement
-                              .getElementsByTagName('license')
-                              .item(0).firstChild.nodeValue;
-  }
-  if(doc.documentElement.getElementsByTagName('keywords').length == 1 &&
-     doc.documentElement.getElementsByTagName('keywords').item(0).firstChild) {
-    package_json.keywords = doc.documentElement
-                               .getElementsByTagName('keywords')
-                               .item(0).firstChild.nodeValue.split(',');
-  }
+  if(description) package_json.description = description;
+  if(license)     package_json.license     = license  
+  if(keywords)    package_json.keywords    = keywords.split(',');
 
   // write package.json
   var package_json_path = path.resolve(plugin_path, 'package.json');


Mime
View raw message