cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [07/43] git commit: part of the way there to refactor output into eventemitter.
Date Thu, 11 Jul 2013 21:50:07 GMT
part of the way there to refactor output into eventemitter.


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

Branch: refs/heads/plugman-registry
Commit: ce7a21efea3c386ad431c6f085b39d1e136184af
Parents: 7c9e7f8
Author: Fil Maj <maj.fil@gmail.com>
Authored: Tue Jul 2 10:48:35 2013 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Wed Jul 3 10:12:40 2013 -0700

----------------------------------------------------------------------
 FUTURE.md      | 42 ------------------------------------------
 main.js        |  6 +++++-
 plugman.js     | 18 ++++++++++++------
 src/events.js  |  3 +++
 src/fetch.js   | 15 ++++++++++++---
 src/help.js    |  2 +-
 src/install.js |  5 ++---
 7 files changed, 35 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/FUTURE.md
----------------------------------------------------------------------
diff --git a/FUTURE.md b/FUTURE.md
deleted file mode 100644
index 41c2c62..0000000
--- a/FUTURE.md
+++ /dev/null
@@ -1,42 +0,0 @@
-# The Future of Plugman and CLI
-
-In this branch, Plugman is undergoing major changes to make the split of responsibilities
between plugman and cordova-cli clear.
-
-## Responsibilities
-
-* cordova-cli is responsible for handling multiple platforms. That means it has the separate
`platforms/{ios,android,etc}` directories, a top-level `www/` and so on.
-* plugman is responsible for everything to do with plugins: fetching them, installing native
code, installing JS code, keeping track of which ones are installed, removing them.
-
-## High-level changes
-
-Plugman now holds onto the code of the plugin, instead of cloning it into a temporary folder
and throwing it away. By default it uses the `cordova/plugins` directory, but this can be
overridden with `--plugins_dir=some/path`. This enables cordova-cli to use its top-level `plugins/`
directory.
-
-See the next section for the changes to the commands and arguments.
-
-## Commands
-
-### `--fetch`
-
-Does the actual downloading of the plugin, from Github, the repository or the local disk.
-
-This supports cordova-cli, which will want to `--fetch` once into its top-level `plugins/`
directory and then `--install` once for each platform.
-
-### `--install`
-
-Takes the previously fetched plugin files and installs them into a project. Needs a path
to the plugin directory, the path to the project, and the platform, similar to now.
-
-Installs the native code and makes the necessary configuration changes.
-
-### `--uninstall`
-
-Removes the native code and undoes the configuration changes and so on.
-
-Care is required here not to remove permissions that are still needed by other plugins. (Read:
config changes should be cleared and recreated from the currently installed plugins every
time. This applies to permissions, `<plugin>` tags and so on.)
-
-### `--prepare`
-
-Takes over part of cordova-cli's `prepare` command. Copies all plugins' Javascript files
(more precisely, those specified in `<js-module>` tags rather than `<asset>` tags)
into `www/plugins/com.plugin.id/whatever/path/file.js` and constructs the `cordova_plugins.json`
file.
-
-`cordova.js` in this new model will have code that reads this `cordova_plugins.json` file
via XHR, loads the JS files for the plugins, and does their clobbers and merges.
-
-This is something of a change from the current cordova-cli method, but necessary because
we won't be working with a fresh `cordova.js` file on each run anymore.

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/main.js
----------------------------------------------------------------------
diff --git a/main.js b/main.js
index 28a3358..159f97e 100755
--- a/main.js
+++ b/main.js
@@ -60,11 +60,15 @@ process.on('uncaughtException', function(error){
     process.exit(1);
 });
 
+if (cli_opts.debug) {
+    plugman.on('log', console.log);
+}
+
 if (cli_opts.v) {
     console.log(package.name + ' version ' + package.version);
 }
 else if (!cli_opts.platform || !cli_opts.project || !cli_opts.plugin) {
-    plugman.help();
+    console.log(plugman.help());
 }
 else if (cli_opts.uninstall) {
     plugman.uninstall(cli_opts.platform, cli_opts.project, cli_opts.plugin, plugins_dir,
{ www_dir: cli_opts.www });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/plugman.js
----------------------------------------------------------------------
diff --git a/plugman.js b/plugman.js
index 23128ed..072d9b9 100755
--- a/plugman.js
+++ b/plugman.js
@@ -18,11 +18,17 @@
 */
 
 // copyright (c) 2013 Andrew Lunny, Adobe Systems
+
+var emitter = require('./src/events');
+
 module.exports = {
-    help:     require('./src/help'),
-    install:  require('./src/install'),
-    uninstall:require('./src/uninstall'),
-    fetch:    require('./src/fetch'),
-    prepare:  require('./src/prepare'),
-    config_changes:require('./src/util/config-changes')
+    help:           require('./src/help'),
+    install:        require('./src/install'),
+    uninstall:      require('./src/uninstall'),
+    fetch:          require('./src/fetch'),
+    prepare:        require('./src/prepare'),
+    config_changes: require('./src/util/config-changes'),
+    on:             emitter.addListener,
+    off:            emitter.removeListener,
+    removeAllListeners: emitter.removeAllListeners,
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/src/events.js
----------------------------------------------------------------------
diff --git a/src/events.js b/src/events.js
new file mode 100644
index 0000000..1cec85a
--- /dev/null
+++ b/src/events.js
@@ -0,0 +1,3 @@
+var emitter = new (require('events').EventEmitter)();
+
+module.exports = emitter;

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index c0ce5f1..f712b0a 100644
--- a/src/fetch.js
+++ b/src/fetch.js
@@ -4,10 +4,12 @@ var shell   = require('shelljs'),
     plugins = require('./util/plugins'),
     xml_helpers = require('./util/xml-helpers'),
     metadata = require('./util/metadata'),
+    events  = require('./events'),
     path    = require('path');
 
 // possible options: link, subdir, git_ref
 module.exports = function fetchPlugin(plugin_dir, plugins_dir, options, callback) {
+    events.emit('log', 'Fetching plugin from location "' + plugin_dir + '"...');
     // Ensure the containing directory exists.
     shell.mkdir('-p', plugins_dir);
 
@@ -32,7 +34,10 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options,
callback
             };
 
             plugins.clonePluginGitRepo(plugin_dir, plugins_dir, options.subdir, options.git_ref,
function(err, dir) {
-                if (!err) {
+                if (err) {
+                    if (callback) callback(err);
+                    else throw err;
+                } else {
                     metadata.save_fetch_metadata(dir, data);
                     if (callback) callback(null, dir);
                 }
@@ -43,17 +48,21 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options,
callback
         // Copy from the local filesystem.
         // First, read the plugin.xml and grab the ID.
         plugin_dir = path.join(uri.path, options.subdir);
-        var xml = xml_helpers.parseElementtreeSync(path.join(plugin_dir, 'plugin.xml'));
+        var plugin_xml_path = path.join(plugin_dir, 'plugin.xml');
+        events.emit('log', 'Fetch is reading plugin.xml from location "' + plugin_xml_path
+ '"...');
+        var xml = xml_helpers.parseElementtreeSync(plugin_xml_path);
         var plugin_id = xml.getroot().attrib.id;
 
         var dest = path.join(plugins_dir, plugin_id);
 
         shell.rm('-rf', dest);
         if (options.link) {
+            events.emit('log', 'Symlinking from location "' + plugin_dir + '" to location
"' + dest + '"');
             fs.symlinkSync(plugin_dir, dest, 'dir');
         } else {
             shell.mkdir('-p', dest);
-            shell.cp('-R', path.join(plugin_dir, '*') , dest);
+            events.emit('log', 'Copying from location "' + plugin_dir + '" to location "'
+ dest + '"');
+            shell.cp('-R', path.join(plugin_dir, '*'), dest);
         }
 
         var data = {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/src/help.js
----------------------------------------------------------------------
diff --git a/src/help.js b/src/help.js
index 210cc48..775ea65 100644
--- a/src/help.js
+++ b/src/help.js
@@ -3,5 +3,5 @@ var fs = require('fs'),
 var doc_txt = path.join(__dirname, '..', 'doc', 'help.txt');
 
 module.exports = function help() {
-    console.log(fs.readFileSync(doc_txt, 'utf-8'));
+    return fs.readFileSync(doc_txt, 'utf-8');
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 3f66fc1..179d228 100644
--- a/src/install.js
+++ b/src/install.js
@@ -22,7 +22,7 @@ var path = require('path'),
    3. runInstall
      a) checks if the plugin is already installed. if so, calls back (done).
      b) if possible, will check the version of the project and make sure it is compatible
with the plugin (checks <engine> tags)
-     c) makes sure that any variables required by the plugin are specified
+     c) makes sure that any variables required by the plugin are specified. if they are not
specified, plugman will throw or callback with an error.
      d) if dependencies are listed in the plugin, it will recurse for each dependent plugin
and call possiblyFetch (2) on each one. When each dependent plugin is successfully installed,
it will then proceed to call handleInstall (4)
    4. handleInstall
      a) queues up actions into a queue (asset, source-file, headers, etc)
@@ -34,9 +34,8 @@ var path = require('path'),
 module.exports = function installPlugin(platform, project_dir, id, plugins_dir, options,
callback) {
     if (!platform_modules[platform]) {
         var err = new Error(platform + " not supported.");
-        if (callback) callback(err);
+        if (callback) return callback(err);
         else throw err;
-        return;
     }
 
     var current_stack = new action_stack();


Mime
View raw message