cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [60/91] [abbrv] git commit: Issue #16 first test
Date Mon, 04 Mar 2013 19:32:51 GMT
Issue #16 first test


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

Branch: refs/heads/master
Commit: 604c7713b6dd9a99f04b715ce466e9dad13b5d52
Parents: 3f6a4f6
Author: Anis Kadri <anis.kadri@gmail.com>
Authored: Mon Jan 7 10:43:43 2013 -0800
Committer: Anis Kadri <anis.kadri@gmail.com>
Committed: Mon Jan 7 10:43:43 2013 -0800

----------------------------------------------------------------------
 plugman.js      |   62 ++++++++++++++++++++++++++++---------------------
 util/plugins.js |   54 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/604c7713/plugman.js
----------------------------------------------------------------------
diff --git a/plugman.js b/plugman.js
index 556b5c6..a69521d 100755
--- a/plugman.js
+++ b/plugman.js
@@ -1,13 +1,13 @@
 #!/usr/bin/env node
 
-// copyright (c) 2012 Andrew Lunny, Adobe Systems
-var shell = require('shelljs')
-  , osenv = require('osenv')
-  , fs = require('fs')
+// copyright (c) 2013 Andrew Lunny, Adobe Systems
+var fs = require('fs')
   , path = require('path')
+  , url = require('url')
   , package = require(path.join(__dirname, 'package'))
   , et = require('elementtree')
   , nopt = require('nopt')
+  , plugins = require('./util/plugins')
   , platform_modules = {
         'android': require('./platforms/android'),
         'ios': require('./platforms/ios'),
@@ -16,7 +16,7 @@ var shell = require('shelljs')
 
 var known_opts = { 'platform' : [ 'ios', 'android', 'www' ]
             , 'project' : path
-            , 'plugin' : path
+            , 'plugin' : [String, path, url]
             , 'remove' : Boolean
             , 'v' : Boolean
             , 'debug' : Boolean
@@ -51,40 +51,48 @@ function printUsage() {
     console.log('Usage\n---------');
     console.log('Add a plugin:\n\t' + package.name + ' --platform <'+ platforms +'>
--project <directory> --plugin <directory>\n');
     console.log('Remove a plugin:\n\t' + package.name + ' --remove --platform <'+ platforms
+'> --project <directory> --plugin <directory>\n');
-} 
+}
+
+function execAction(action, platform, project_dir, plugin_dir) {
+    var xml_path     = path.join(plugin_dir, 'plugin.xml')
+      , xml_text     = fs.readFileSync(xml_path, 'utf-8')
+      , plugin_et   = new et.ElementTree(et.XML(xml_text));
+    
+    // run the platform-specific function
+    platform_modules[platform].handlePlugin(action, project_dir, plugin_dir, plugin_et);
+    
+    console.log('plugin ' + action + 'ed');
+}
 
 function handlePlugin(action, platform, project_dir, plugin_dir) {
-    var plugin_git_url, plugin_xml_path;
+    var plugin_xml_path, async = false;
 
     // clone from git repository
     if(plugin_dir.indexOf('https://') == 0 || plugin_dir.indexOf('git://') == 0) {
-        if(!shell.which('git')) {
-            throw new Error('git command line is not installed');
-        }
-        // use osenv to get a temp directory in a portable way
-        plugin_git_url = plugin_dir; 
-        plugin_dir = path.join(osenv.tmpdir(), 'plugin');
-
-        if(shell.exec('git clone ' + plugin_url + ' ' + plugin_dir).code != 0) {
-            throw new Error('failed to get the plugin via git URL', plugin_url);
-        }
+        plugin_dir = plugins.clonePluginGitRepo(plugin_dir);
     }
 
     plugin_xml_path = path.join(plugin_dir, 'plugin.xml');
     if (!fs.existsSync(plugin_xml_path)) {
-        throw new Error(action + ' failed. "' + plugin_xml_path + '" not found');
+        // try querying the plugin database
+        async = true;
+        plugins.getPluginInfo(plugin_dir,
+            function(plugin_dir) {
+                execAction(action, platform, project_dir, plugin_dir);
+            },
+            function(e) {
+                throw new Error(action + ' failed. "' + plugin_xml_path + '" not found');
+            }
+        );
     }
 
-    if (!platform_modules[platform])
+    if (!platform_modules[platform]) {
         throw { name: "Platform Error", message: platform + " not supported" }
+    }
 
     // check arguments and resolve file paths
-    var xml_path     = path.join(plugin_dir, 'plugin.xml')
-      , xml_text     = fs.readFileSync(xml_path, 'utf-8')
-      , plugin_et   = new et.ElementTree(et.XML(xml_text));
-
-    // run the platform-specific function
-    platform_modules[platform].handlePlugin(action, project_dir, plugin_dir, plugin_et);
-
-    console.log('plugin ' + action + 'ed');
+    if(!async) {
+        execAction(action, platform, project_dir, plugin_dir);
+    }
 }
+

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/604c7713/util/plugins.js
----------------------------------------------------------------------
diff --git a/util/plugins.js b/util/plugins.js
new file mode 100644
index 0000000..ce6ab7a
--- /dev/null
+++ b/util/plugins.js
@@ -0,0 +1,54 @@
+#!/usr/bin/env node
+// FIXME: change this quickly
+var url = "http://ec2-184-72-173-33.compute-1.amazonaws.com:5984";
+var http = require('http'),
+    osenv = require('osenv'),
+    path = require('path'),
+    fs = require('fs'),
+    shell = require('shelljs');
+
+// Fetches plugin information from remote server
+exports.getPluginInfo = function(plugin_name, success, error) {
+    http.get(url + "/cordova_plugins/_design/cordova_plugins/_view/by_name?key=\""+plugin_name+"\"",
function(res) {
+      var str = '';
+      res.on('data', function (chunk) {
+        str += chunk;
+      });
+      res.on('end', function () {
+          var response, plugin_info;
+          if((response = JSON.parse(str)).rows.length == 1) {
+            plugin_info = response.rows[0].value;
+            success(exports.clonePluginGitRepo(plugin_info.url));
+          } else {
+            error("Could not find information on "+plugin_dir+" plugin");
+          }
+      });
+      
+    }).on('error', function(e) {
+      console.log("Got error: " + e.message);
+      error(e.message);
+    });
+}
+
+exports.clonePluginGitRepo = function(plugin_dir) {
+    if(!shell.which('git')) {
+        throw new Error('git command line is not installed');
+    }
+    // use osenv to get a temp directory in a portable way
+    plugin_git_url = plugin_dir; 
+    plugin_dir = path.join(osenv.tmpdir(), 'plugin');
+
+    if(shell.exec('git clone ' + plugin_git_url + ' ' + plugin_dir + ' 2>&1 1>/dev/null').code
!= 0) {
+        throw new Error('failed to get the plugin via git URL', plugin_git_url);
+    }
+    
+    process.on('exit', function() {
+        console.log('cleaning up...');
+        // clean up
+        if(fs.existsSync(plugin_dir)) {
+            shell.rm('-rf', plugin_dir);
+        }
+    });
+
+    return plugin_dir;
+}


Mime
View raw message