Updated Branches: refs/heads/master 6b01af349 -> c0ddac946
0.8.2. Fixing event emitters. Require weirdness? Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/c0ddac94 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/c0ddac94 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/c0ddac94 Branch: refs/heads/master Commit: c0ddac946494ce213a8dfdca5365130c61d378ad Parents: 6b01af3 Author: Fil Maj <[email protected]> Authored: Wed Jul 3 11:30:19 2013 -0700 Committer: Fil Maj <[email protected]> Committed: Wed Jul 3 11:30:19 2013 -0700 ---------------------------------------------------------------------- package.json | 2 +- plugman.js | 1 + spec/install.spec.js | 3 +-- src/fetch.js | 9 ++++----- src/install.js | 17 ++++++++--------- src/prepare.js | 9 ++++----- src/uninstall.js | 7 +++---- src/util/action-stack.js | 19 +++++++++---------- src/util/config-changes.js | 1 - src/util/plugins.js | 11 +++++------ 10 files changed, 36 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0ddac94/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index e4180de..345fc06 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Andrew Lunny <[email protected]>", "name": "plugman", "description": "install/uninstall Cordova plugins", - "version": "0.8.1", + "version": "0.8.2", "repository": { "type": "git", "url": "git://git-wip-us.apache.org/repos/asf/cordova-plugman.git" http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0ddac94/plugman.js ---------------------------------------------------------------------- diff --git a/plugman.js b/plugman.js index 072d9b9..2775fe1 100755 --- a/plugman.js +++ b/plugman.js @@ -31,4 +31,5 @@ module.exports = { on: emitter.addListener, off: emitter.removeListener, removeAllListeners: emitter.removeAllListeners, + emit: emitter.emit }; http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0ddac94/spec/install.spec.js ---------------------------------------------------------------------- diff --git a/spec/install.spec.js b/spec/install.spec.js index f51d92a..fd84e0e 100644 --- a/spec/install.spec.js +++ b/spec/install.spec.js @@ -8,7 +8,6 @@ var install = require('../src/install'), path = require('path'), shell = require('shelljs'), semver = require('semver'), - events = require('../src/events'), temp = __dirname, dummyplugin = 'DummyPlugin', dummy_id = 'com.phonegap.plugins.dummyplugin', @@ -51,7 +50,7 @@ describe('install', function() { expect(add_to_queue).toHaveBeenCalledWith(plugins_dir, 'DummyPlugin', 'android', {}, true); }); it('should notify if plugin is already installed into project', function() { - var spy = spyOn(events, 'emit'); + var spy = spyOn(plugman, 'emit'); get_json.andReturn({ installed_plugins:{ 'com.phonegap.plugins.dummyplugin':{} http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0ddac94/src/fetch.js ---------------------------------------------------------------------- diff --git a/src/fetch.js b/src/fetch.js index f712b0a..8f2064a 100644 --- a/src/fetch.js +++ b/src/fetch.js @@ -4,12 +4,11 @@ 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 + '"...'); + require('../plugman').emit('log', 'Fetching plugin from location "' + plugin_dir + '"...'); // Ensure the containing directory exists. shell.mkdir('-p', plugins_dir); @@ -49,7 +48,7 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options, callback // First, read the plugin.xml and grab the ID. plugin_dir = path.join(uri.path, options.subdir); var plugin_xml_path = path.join(plugin_dir, 'plugin.xml'); - events.emit('log', 'Fetch is reading plugin.xml from location "' + plugin_xml_path + '"...'); + require('../plugman').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; @@ -57,11 +56,11 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options, callback shell.rm('-rf', dest); if (options.link) { - events.emit('log', 'Symlinking from location "' + plugin_dir + '" to location "' + dest + '"'); + require('../plugman').emit('log', 'Symlinking from location "' + plugin_dir + '" to location "' + dest + '"'); fs.symlinkSync(plugin_dir, dest, 'dir'); } else { shell.mkdir('-p', dest); - events.emit('log', 'Copying from location "' + plugin_dir + '" to location "' + dest + '"'); + require('../plugman').emit('log', 'Copying from location "' + plugin_dir + '" to location "' + dest + '"'); shell.cp('-R', path.join(plugin_dir, '*'), dest); } http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0ddac94/src/install.js ---------------------------------------------------------------------- diff --git a/src/install.js b/src/install.js index e07b973..2c2c025 100644 --- a/src/install.js +++ b/src/install.js @@ -2,7 +2,6 @@ var path = require('path'), fs = require('fs'), et = require('elementtree'), n = require('ncallbacks'), - events = require('./events'), action_stack = require('./util/action-stack'), shell = require('shelljs'), semver = require('semver'), @@ -72,7 +71,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt , filtered_variables = {}; var name = plugin_et.findall('name').text; var plugin_id = plugin_et.getroot().attrib['id']; - events.emit('log', 'Starting installation of "' + plugin_id + '"...'); + require('../plugman').emit('log', 'Starting installation of "' + plugin_id + '"...'); // check if platform has plugin installed already. var platform_config = config_changes.get_platform_json(plugins_dir, platform); @@ -89,7 +88,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt } }); if (is_installed) { - events.emit('log', 'Plugin "' + plugin_id + '" already installed, \'sall good.'); + require('../plugman').emit('log', 'Plugin "' + plugin_id + '" already installed, \'sall good.'); if (callback) callback(); return; } @@ -123,7 +122,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt }); } } else { - events.emit('log', 'Cordova project version not detected (lacks a ./cordova/version script), continuing.'); + require('../plugman').emit('log', 'Cordova project version not detected (lacks a ./cordova/version script), continuing.'); } // checking preferences, if certain variables are not provided, we should throw. @@ -148,7 +147,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt // Check for dependencies, (co)recurse to install each one var dependencies = plugin_et.findall('dependency'); if (dependencies && dependencies.length) { - events.emit('log', 'Dependencies detected, iterating through them...'); + require('../plugman').emit('log', 'Dependencies detected, iterating through them...'); var end = n(dependencies.length, function() { handleInstall(actions, plugin_id, plugin_et, platform, project_dir, plugins_dir, plugin_basename, plugin_dir, filtered_variables, options.www_dir, options.is_top_level, callback); }); @@ -204,7 +203,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt var dep_plugin_dir = path.join(plugins_dir, dep_plugin_id); if (fs.existsSync(dep_plugin_dir)) { - events.emit('log', 'Dependent plugin "' + dep_plugin_id + '" already fetched, using that version.'); + require('../plugman').emit('log', 'Dependent plugin "' + dep_plugin_id + '" already fetched, using that version.'); var opts = { cli_variables: filtered_variables, www_dir: options.www_dir, @@ -212,7 +211,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt }; runInstall(actions, platform, project_dir, dep_plugin_dir, plugins_dir, opts, end); } else { - events.emit('log', 'Dependent plugin "' + dep_plugin_id + '" not fetched, retrieving then installing.'); + require('../plugman').emit('log', 'Dependent plugin "' + dep_plugin_id + '" not fetched, retrieving then installing.'); var opts = { cli_variables: filtered_variables, www_dir: options.www_dir, @@ -235,7 +234,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt } function handleInstall(actions, plugin_id, plugin_et, platform, project_dir, plugins_dir, plugin_basename, plugin_dir, filtered_variables, www_dir, is_top_level, callback) { - events.emit('log', 'Installing plugin ' + plugin_id + '...'); + require('../plugman').emit('log', 'Installing plugin ' + plugin_id + '...'); var handler = platform_modules[platform]; www_dir = www_dir || handler.www_dir(project_dir); @@ -295,7 +294,7 @@ function handleInstall(actions, plugin_id, plugin_et, platform, project_dir, plu // call prepare after a successful install require('./../plugman').prepare(project_dir, platform, plugins_dir); - events.emit('log', plugin_id + ' installed.'); + require('../plugman').emit('log', plugin_id + ' installed.'); if (callback) callback(); } }); http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0ddac94/src/prepare.js ---------------------------------------------------------------------- diff --git a/src/prepare.js b/src/prepare.js index a608dcc..4904975 100644 --- a/src/prepare.js +++ b/src/prepare.js @@ -18,7 +18,6 @@ */ var platform_modules = require('./platforms'), - events = require('./events'), path = require('path'), config_changes = require('./util/config-changes'), xml_helpers = require('./util/xml-helpers'), @@ -43,7 +42,7 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) { // - Write this object into www/cordova_plugins.json. // - Cordova.js contains code to load them at runtime from that file. - events.emit('log', 'Preparing ' + platform + ' project, starting with processing of config changes...'); + require('../plugman').emit('log', 'Preparing ' + platform + ' project, starting with processing of config changes...'); config_changes.process(plugins_dir, project_dir, platform); var wwwDir = platform_modules[platform].www_dir(project_dir); @@ -54,7 +53,7 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) { // This array holds all the metadata for each module and ends up in cordova_plugins.json var moduleObjects = []; - events.emit('log', 'Iterating over installed plugins...'); + require('../plugman').emit('log', 'Iterating over installed plugins...'); plugins && plugins.forEach(function(plugin) { var pluginDir = path.join(plugins_dir, plugin); @@ -124,7 +123,7 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) { } }); - events.emit('log', 'Writing out cordova_plugins.json...'); + require('../plugman').emit('log', 'Writing out cordova_plugins.json...'); // Write out moduleObjects as JSON to cordova_plugins.json fs.writeFileSync(path.join(wwwDir, 'cordova_plugins.json'), JSON.stringify(moduleObjects), 'utf-8'); // Write out moduleObjects as JSON wrapped in a cordova module to cordova_plugins.js @@ -132,6 +131,6 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) { var final_contents = "cordova.define('cordova/plugin_list', function(require, exports, module) {\n"; final_contents += 'module.exports = ' + JSON.stringify(moduleObjects) + '\n'; final_contents += '});'; - events.emit('log', 'Writing out cordova_plugins.js...'); + require('../plugman').emit('log', 'Writing out cordova_plugins.js...'); fs.writeFileSync(path.join(wwwDir, 'cordova_plugins.js'), final_contents, 'utf-8'); }; http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0ddac94/src/uninstall.js ---------------------------------------------------------------------- diff --git a/src/uninstall.js b/src/uninstall.js index 5cb807b..dbe0fae 100644 --- a/src/uninstall.js +++ b/src/uninstall.js @@ -6,7 +6,6 @@ var path = require('path'), xml_helpers = require('./util/xml-helpers'), action_stack = require('./util/action-stack'), n = require('ncallbacks'), - events = require('./events'), dependencies = require('./util/dependencies'), underscore = require('underscore'), platform_modules = require('./platforms'); @@ -63,7 +62,7 @@ function runUninstall(actions, platform, project_dir, plugin_dir, plugins_dir, o diff_arr.unshift(dependents); var danglers = underscore.difference.apply(null, diff_arr); if (dependents.length && danglers && danglers.length) { - events.emit('log', 'Uninstalling ' + danglers.length + ' dangling dependent plugins...'); + require('../plugman').emit('log', 'Uninstalling ' + danglers.length + ' dangling dependent plugins...'); var end = n(danglers.length, function() { handleUninstall(actions, platform, plugin_id, plugin_et, project_dir, options.www_dir, plugins_dir, plugin_dir, options.is_top_level, callback); }); @@ -87,7 +86,7 @@ function handleUninstall(actions, platform, plugin_id, plugin_et, project_dir, w var handler = platform_modules[platform]; var platformTag = plugin_et.find('./platform[@name="'+platform+'"]'); www_dir = www_dir || handler.www_dir(project_dir); - events.emit('log', 'Uninstalling ' + plugin_id + '...'); + require('../plugman').emit('log', 'Uninstalling ' + plugin_id + '...'); var assets = plugin_et.findall('./asset'); if (platformTag) { @@ -134,7 +133,7 @@ function handleUninstall(actions, platform, plugin_id, plugin_et, project_dir, w require('./../plugman').prepare(project_dir, platform, plugins_dir); // axe the directory shell.rm('-rf', plugin_dir); - events.emit('log', plugin_id + ' uninstalled.'); + require('../plugman').emit('log', plugin_id + ' uninstalled.'); if (callback) callback(); } }); http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0ddac94/src/util/action-stack.js ---------------------------------------------------------------------- diff --git a/src/util/action-stack.js b/src/util/action-stack.js index c26bd9e..fb63ce8 100644 --- a/src/util/action-stack.js +++ b/src/util/action-stack.js @@ -1,7 +1,6 @@ var ios = require('../platforms/ios'), wp7 = require('../platforms/wp7'), wp8 = require('../platforms/wp8'), - events = require('../events'), fs = require('fs'); function ActionStack() { @@ -26,19 +25,19 @@ ActionStack.prototype = { this.stack.push(tx); }, process:function(platform, project_dir, callback) { - events.emit('log', 'Beginning processing of action stack for ' + platform + ' project...'); + require('../../plugman').emit('log', 'Beginning processing of action stack for ' + platform + ' project...'); var project_files; // parse platform-specific project files once if (platform == 'ios') { - events.emit('log', 'Parsing iOS project files...'); + require('../../plugman').emit('log', 'Parsing iOS project files...'); project_files = ios.parseIOSProjectFiles(project_dir); } if (platform == 'wp7') { - events.emit('log', 'Parsing WP7 project files...'); + require('../../plugman').emit('log', 'Parsing WP7 project files...'); project_files = wp7.parseWP7ProjectFile(project_dir); } if (platform == 'wp8') { - events.emit('log', 'Parsing WP8 project files...'); + require('../../plugman').emit('log', 'Parsing WP8 project files...'); project_files = wp8.parseWP8ProjectFile(project_dir); } while(this.stack.length) { @@ -49,7 +48,7 @@ ActionStack.prototype = { try { handler.apply(null, action_params); } catch(e) { - events.emit('warn', 'Error during processing of action! Attempting to revert...'); + require('../../plugman').emit('warn', 'Error during processing of action! Attempting to revert...'); var incomplete = this.stack.unshift(action); var issue = 'Uh oh!\n'; // revert completed tasks @@ -61,7 +60,7 @@ ActionStack.prototype = { try { revert.apply(null, revert_params); } catch(err) { - events.emit('warn', 'Error during reversion of action! We probably really messed up your project now, sorry! D:'); + require('../plugman').emit('warn', 'Error during reversion of action! We probably really messed up your project now, sorry! D:'); issue += 'A reversion action failed: ' + err.message + '\n'; } } @@ -71,14 +70,14 @@ ActionStack.prototype = { } this.completed.push(action); } - events.emit('log', 'Action stack processing complete.'); + require('../../plugman').emit('log', 'Action stack processing complete.'); if (platform == 'ios') { // write out xcodeproj file - events.emit('log', 'Writing out iOS pbxproj file...'); + require('../../plugman').emit('log', 'Writing out iOS pbxproj file...'); fs.writeFileSync(project_files.pbx, project_files.xcode.writeSync()); } if (platform == 'wp7' || platform == 'wp8') { - events.emit('log', 'Writing out ' + platform + ' project files...'); + require('../../plugman').emit('log', 'Writing out ' + platform + ' project files...'); project_files.write(); } if (callback) callback(); http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0ddac94/src/util/config-changes.js ---------------------------------------------------------------------- diff --git a/src/util/config-changes.js b/src/util/config-changes.js index c49c705..4a4d7ac 100644 --- a/src/util/config-changes.js +++ b/src/util/config-changes.js @@ -23,7 +23,6 @@ var fs = require('fs'), plist = require('plist'), bplist = require('bplist-parser'), et = require('elementtree'), - events = require('../events'), xml_helpers = require('./../util/xml-helpers'), plist_helpers = require('./../util/plist-helpers'); http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0ddac94/src/util/plugins.js ---------------------------------------------------------------------- diff --git a/src/util/plugins.js b/src/util/plugins.js index 706d352..90b24f7 100644 --- a/src/util/plugins.js +++ b/src/util/plugins.js @@ -24,7 +24,6 @@ var http = require('http'), util = require('util'), shell = require('shelljs'), xml_helpers = require('./xml-helpers'), - events = require('../events'), tmp_dir = path.join(os.tmpdir(), 'plugman-tmp'); module.exports = { @@ -41,14 +40,14 @@ module.exports = { shell.cd(path.dirname(tmp_dir)); var cmd = util.format('git clone "%s" "%s"', plugin_git_url, path.basename(tmp_dir)); - events.emit('log', 'Fetching plugin via git-clone command: ' + cmd); + require('../../plugman').emit('log', 'Fetching plugin via git-clone command: ' + cmd); shell.exec(cmd, {silent: true, async:true}, function(code, output) { if (code > 0) { var err = new Error('failed to get the plugin via git from URL '+ plugin_git_url + ', output: ' + output); if (callback) return callback(err) else throw err; } else { - events.emit('log', 'Plugin "' + plugin_git_url + '" fetched.'); + require('../../plugman').emit('log', 'Plugin "' + plugin_git_url + '" fetched.'); // Check out the specified revision, if provided. if (git_ref) { var cmd = util.format('cd "%s" && git checkout "%s"', tmp_dir, git_ref); @@ -58,7 +57,7 @@ module.exports = { if (callback) return callback(err); else throw err; } - events.emit('log', 'Plugin "' + plugin_git_url + '" checked out to git ref "' + git_ref + '".'); + require('../../plugman').emit('log', 'Plugin "' + plugin_git_url + '" checked out to git ref "' + git_ref + '".'); } // Read the plugin.xml file and extract the plugin's ID. @@ -70,11 +69,11 @@ module.exports = { // TODO: what if a plugin dependended on different subdirectories of the same plugin? this would fail. // should probably copy over entire plugin git repo contents into plugins_dir and handle subdir seperately during install. - events.emit('log', 'Copying fetched plugin over "' + plugin_dir + '"...'); + require('../../plugman').emit('log', 'Copying fetched plugin over "' + plugin_dir + '"...'); var plugin_dir = path.join(plugins_dir, plugin_id); shell.cp('-R', path.join(tmp_dir, '*'), plugin_dir); - events.emit('log', 'Plugin "' + plugin_id + '" fetched.'); + require('../../plugman').emit('log', 'Plugin "' + plugin_id + '" fetched.'); if (callback) callback(null, plugin_dir); } });
