cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/2] git commit: CB-4494 adding info command and storing engine data in registry
Date Tue, 03 Sep 2013 22:48:55 GMT
Updated Branches:
  refs/heads/master 73c3aa720 -> c97c4cbe1


CB-4494 adding info command and storing engine data in registry


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

Branch: refs/heads/master
Commit: 07d2a49edb26e7e91ec30e6681218e476bb31068
Parents: 479d339
Author: Anis Kadri <anis@apache.org>
Authored: Tue Sep 3 15:48:58 2013 -0700
Committer: Anis Kadri <anis@apache.org>
Committed: Tue Sep 3 15:48:58 2013 -0700

----------------------------------------------------------------------
 doc/help.txt                   |  5 +++
 plugman.js                     |  4 ++
 spec/info.spec.js              | 10 +++++
 spec/registry/registry.spec.js |  9 ++--
 src/info.js                    | 19 +++++++++
 src/registry/manifest.js       | 83 ++++++++++++++++++++-----------------
 src/registry/registry.js       | 20 ++++++++-
 7 files changed, 109 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/07d2a49e/doc/help.txt
----------------------------------------------------------------------
diff --git a/doc/help.txt b/doc/help.txt
index 00ce7fb..51eb43d 100644
--- a/doc/help.txt
+++ b/doc/help.txt
@@ -61,6 +61,11 @@ Search for a plugin
 
     $ plugman search plugin,keywords
 
+Display plugin information
+-----------------------
+
+    $ plugman info plugin
+
 Manage registry configuration
 -----------------------------
 

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/07d2a49e/plugman.js
----------------------------------------------------------------------
diff --git a/plugman.js b/plugman.js
index b921f4d..4ca7846 100755
--- a/plugman.js
+++ b/plugman.js
@@ -32,6 +32,7 @@ plugman = {
     publish:            require('./src/publish'),
     unpublish:          require('./src/unpublish'),
     search:             require('./src/search'),
+    info:               require('./src/info'),
     config_changes:     require('./src/util/config-changes'),
     on:                 emitter.addListener,
     off:                emitter.removeListener,
@@ -75,6 +76,9 @@ plugman.commands =  {
     'search'   : function(cli_opts) {
         plugman.search(cli_opts.argv.remain);
     },
+    'info'     : function(cli_opts) {
+        plugman.info(cli_opts.argv.remain);
+    },
 
     'publish'  : function(cli_opts) {
         var plugin_path = cli_opts.argv.remain; 

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/07d2a49e/spec/info.spec.js
----------------------------------------------------------------------
diff --git a/spec/info.spec.js b/spec/info.spec.js
new file mode 100644
index 0000000..1327c65
--- /dev/null
+++ b/spec/info.spec.js
@@ -0,0 +1,10 @@
+var search = require('../src/info'),
+    registry = require('../src/registry/registry');
+
+describe('info', function() {
+    it('should show plugin info', function() {
+        var sSearch = spyOn(registry, 'info');
+        search(new Array('myplugin'));
+        expect(sSearch).toHaveBeenCalledWith(['myplugin'], jasmine.any(Function));
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/07d2a49e/spec/registry/registry.spec.js
----------------------------------------------------------------------
diff --git a/spec/registry/registry.spec.js b/spec/registry/registry.spec.js
index 68c930b..a4f0688 100644
--- a/spec/registry/registry.spec.js
+++ b/spec/registry/registry.spec.js
@@ -8,7 +8,7 @@ describe('registry', function() {
     describe('manifest', function() {
         var pluginDir, packageJson;
         beforeEach(function() {
-            pluginDir = __dirname + '/../plugins/DummyPlugin';
+            pluginDir = __dirname + '/../plugins/EnginePlugin';
             packageJson = path.resolve(pluginDir, 'package.json');
         });
         afterEach(function() {
@@ -18,8 +18,11 @@ 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('com.phonegap.plugins.dummyplugin');
-            expect(JSON.parse(fs.readFileSync(packageJson)).version).toEqual('0.6.0');
+            expect(JSON.parse(fs.readFileSync(packageJson)).name).toEqual('com.cordova.engine');
+            expect(JSON.parse(fs.readFileSync(packageJson)).version).toEqual('1.0.0');
+            expect(JSON.parse(fs.readFileSync(packageJson)).engines).toEqual(
+            [ { name : 'cordova', version : '>=2.3.0' }, { name : 'cordova-plugman', version
: '>=0.10.0' }, { name : 'mega-fun-plugin', version : '>=1.0.0' }, { name : 'mega-boring-plugin',
version : '>=3.0.0' } ]
+            );
         });
     });
     describe('actions', function() {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/07d2a49e/src/info.js
----------------------------------------------------------------------
diff --git a/src/info.js b/src/info.js
new file mode 100644
index 0000000..b8fecb7
--- /dev/null
+++ b/src/info.js
@@ -0,0 +1,19 @@
+var registry = require('./registry/registry')
+
+module.exports = function(plugin, callback) {
+    registry.info(plugin, function(err, plugin_info) {
+        if(callback) {
+            if(err) return callback(err);
+            callback(null, plugins);
+        } else {
+            if(err) return console.log(err);
+            console.log('name:', plugin_info.name);
+            console.log('version:', plugin_info.version);
+            if(plugin_info.engines) {
+                for(var i = 0, j = plugin_info.engines.length ; i < j ; i++) {
+                    console.log(plugin_info.engines[i].name, 'version:', plugin_info.engines[i].version);
+                }
+            }
+        }
+    });
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/07d2a49e/src/registry/manifest.js
----------------------------------------------------------------------
diff --git a/src/registry/manifest.js b/src/registry/manifest.js
index 0aa70e3..61f1bb1 100644
--- a/src/registry/manifest.js
+++ b/src/registry/manifest.js
@@ -11,43 +11,52 @@ function handleError(err, cb) {
 
 // Java world big-up!
 function generatePackageJsonFromPluginXml(plugin_path, cb) {
-  var package_json = {};
-  var pluginXml = xml_helpers.parseElementtreeSync(path.join(plugin_path, 'plugin.xml'));
-  
-  if(!pluginXml) return handleError(new Error('invalid plugin.xml document'), 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,
-      cordova_name = pluginElm.findtext('name'),
-      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;
-
-  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();
-
-  if(cordova_name) package_json.cordova_name = cordova_name;
-  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');
-  fs.writeFileSync(package_json_path, JSON.stringify(package_json, null, 4), 'utf8');
-  return package_json;
+    var package_json = {};
+    var pluginXml = xml_helpers.parseElementtreeSync(path.join(plugin_path, 'plugin.xml'));
+
+    if(!pluginXml) return handleError(new Error('invalid plugin.xml document'), cb);
+
+    var pluginElm = pluginXml.getroot();
+
+    if(!pluginElm) return handleError(new Error('invalid plugin.xml document'), cb);
+
+    // REQUIRED: name, version REQUIRED
+    // OPTIONAL: description, license, keywords, engine
+    var name = pluginElm.attrib.id,
+        version = pluginElm.attrib.version,
+        cordova_name = pluginElm.findtext('name'),
+        description = pluginElm.findtext('description'),
+        license = pluginElm.findtext('license'),
+        keywords = pluginElm.findtext('keywords'),
+        engines = pluginElm.findall('engines/engine');
+
+    if(!version) return handleError(new Error('`version` required'), cb)
+        package_json.version = version;
+
+    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();
+
+    if(cordova_name) package_json.cordova_name = cordova_name;
+    if(description)  package_json.description  = description;
+    if(license)      package_json.license      = license;
+    if(keywords)     package_json.keywords     = keywords.split(',');
+
+    // adding engines
+    if(engines) {
+        package_json.engines = [];
+        for(var i = 0, j = engines.length ; i < j ; i++) {
+            package_json.engines.push({name: engines[i].attrib.name, version: engines[i].attrib.version});
+        }
+    }
+
+    // write package.json
+    var package_json_path = path.resolve(plugin_path, 'package.json');
+    fs.writeFileSync(package_json_path, JSON.stringify(package_json, null, 4), 'utf8');
+    return package_json;
 }
 
 module.exports.generatePackageJsonFromPluginXml = generatePackageJsonFromPluginXml;

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/07d2a49e/src/registry/registry.js
----------------------------------------------------------------------
diff --git a/src/registry/registry.js b/src/registry/registry.js
index ba22520..ec662ad 100644
--- a/src/registry/registry.js
+++ b/src/registry/registry.js
@@ -193,10 +193,28 @@ module.exports = {
         initSettings(function(err, settings) {
             if(err) return handleError(err, cb);
             getPackageInfo(args, function(err, info) {
-                if(err) return handleError(err, cb)
+                if(err) return handleError(err, cb);
                 fetchPackage(info, cb);
             });
         });
+    },
+    /**
+     * @method info
+     * @param {String} name Plugin name
+     * @param {Function} cb Command callback
+     */
+    info: function(args, cb) {
+        initSettings(function(err, settings) {
+            if(err) return handleError(err, cb);
+            getPackageInfo(args, function(err, info) {
+                if(err) return handleError(err, cb);
+                if(cb) {
+                    cb(null, info);
+                } else {
+                    console.log(info);
+                }
+            });
+        });
     }
 }
 


Mime
View raw message