You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/06/07 03:31:12 UTC

[05/22] git commit: [CB-2452] added a verbosity flag (-d or --verbose) using event emitters.

[CB-2452] added a verbosity flag (-d or --verbose) using event emitters.


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

Branch: refs/heads/2.8.x
Commit: 00d885319c1fedff594b387aa29fc273fc9ea127
Parents: 5ccaec0
Author: Fil Maj <ma...@gmail.com>
Authored: Tue Jun 4 17:22:10 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Thu Jun 6 18:26:07 2013 -0700

----------------------------------------------------------------------
 bin/cordova                                  |   18 ++++---
 spec/platform-script/android/android.spec.js |    3 +-
 spec/platform-script/ios/ios.spec.js         |    3 +-
 src/compile.js                               |   26 ++++++++--
 src/create.js                                |    5 ++-
 src/emulate.js                               |   43 ++++++++++++----
 src/hooker.js                                |    1 -
 src/metadata/android_parser.js               |   11 ++++-
 src/metadata/blackberry_parser.js            |   55 +++++++++++++--------
 src/metadata/ios_parser.js                   |   34 +++++++++---
 src/platform.js                              |   26 ++++++++--
 src/plugin.js                                |   28 +++++++++--
 src/prepare.js                               |   31 +++++++++---
 13 files changed, 209 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/bin/cordova
----------------------------------------------------------------------
diff --git a/bin/cordova b/bin/cordova
index e6ec3e1..941f461 100755
--- a/bin/cordova
+++ b/bin/cordova
@@ -2,12 +2,6 @@
 var tokens = process.argv.slice(2, process.argv.length),
     cordova= require('../cordova');
 
-// provide clean output on exceptions rather than dumping a stack trace
-process.on('uncaughtException', function(err){
-	console.error(err);
-    process.exit(1);
-});
-
 var cmd, version = false, verbose = false, current;
 
 while (current = tokens.shift()) {
@@ -20,6 +14,16 @@ while (current = tokens.shift()) {
     }
 }
 
+// provide clean output on exceptions rather than dumping a stack trace
+process.on('uncaughtException', function(err){
+	console.error(err);
+    process.exit(1);
+});
+if (verbose) {
+    cordova.on('log', console.log);
+    cordova.on('warn', console.warn);
+}
+
 if (version) {
     console.log(require('../package').version);
 } else if (cmd === undefined) {
@@ -41,5 +45,5 @@ if (version) {
     }
     if (r) console.log(r);
 } else {
-    console.error('Cordova does not know ' + cmd + '; try help for a list of all the available commands.')
+    throw new Error('Cordova does not know ' + cmd + '; try help for a list of all the available commands.');
 }

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/spec/platform-script/android/android.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform-script/android/android.spec.js b/spec/platform-script/android/android.spec.js
index 8c39af0..2433c0a 100644
--- a/spec/platform-script/android/android.spec.js
+++ b/spec/platform-script/android/android.spec.js
@@ -64,6 +64,7 @@ describe('Test:', function() {
         it('should shell out to run command on Android', function() {
             var proj_spy = spyOn(android_parser.prototype, 'update_project');
             var s = spyOn(require('shelljs'), 'exec');
+            spyOn(require('plugman'), 'prepare');
             cordova.emulate('android');
             proj_spy.mostRecentCall.args[1](); // update_project fake
             expect(s).toHaveBeenCalled();
@@ -95,4 +96,4 @@ describe('Test:', function() {
             expect(s.mostRecentCall.args[0]).toContain(build_cmd);
         });
     });
-});
\ No newline at end of file
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/spec/platform-script/ios/ios.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform-script/ios/ios.spec.js b/spec/platform-script/ios/ios.spec.js
index 0fecd75..04ae4bf 100644
--- a/spec/platform-script/ios/ios.spec.js
+++ b/spec/platform-script/ios/ios.spec.js
@@ -65,6 +65,7 @@ describe('Test:', function() {
         it('should shell out to run command on ios', function() {
             var proj_spy = spyOn(ios_parser.prototype, 'update_project');
             var s = spyOn(require('shelljs'), 'exec');
+            spyOn(require('plugman'), 'prepare');
             cordova.emulate('ios');
             proj_spy.mostRecentCall.args[1](); // update_project fake
             expect(s).toHaveBeenCalled();
@@ -96,4 +97,4 @@ describe('Test:', function() {
             expect(s.mostRecentCall.args[0]).toContain(build_cmd);
         });
     });
-});
\ No newline at end of file
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/src/compile.js
----------------------------------------------------------------------
diff --git a/src/compile.js b/src/compile.js
index 4cf3b85..58d944e 100644
--- a/src/compile.js
+++ b/src/compile.js
@@ -23,6 +23,7 @@ var cordova_util      = require('./util'),
     shell             = require('shelljs'),
     et                = require('elementtree'),
     hooker            = require('./hooker'),
+    events            = require('./events'),
     n                 = require('ncallbacks');
 
 
@@ -35,21 +36,25 @@ function shell_out_to_debug(projectRoot, platform, callback) {
     } else {
         cmd = '"' + path.join(cmd, 'cordova', 'build') + '"';
     }
+    events.emit('log', 'Compiling platform "' + platform + '" with command "' + cmd + '"');
     shell.exec(cmd, {silent:true, async:true}, function(code, output) {
         if (code > 0) {
             throw new Error('An error occurred while building the ' + platform + ' project. ' + output);
         } else {
+            events.emit('log', 'Platform "' + platform + '" compiled successfully.');
             if (callback) callback();
         }
     });
 }
 
-
 module.exports = function compile(platformList, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
     if (!projectRoot) {
-        throw new Error('Current working directory is not a Cordova-based project.');
+        var err = new Error('Current working directory is not a Cordova-based project.');
+        if (callback) callback(err);
+        else throw err;
+        return;
     }
 
     var xml = cordova_util.projectConfig(projectRoot);
@@ -63,16 +68,27 @@ module.exports = function compile(platformList, callback) {
         platformList = cordova_util.listPlatforms(projectRoot);
     }
 
-    if (platformList.length === 0) throw new Error('No platforms added to this project. Please use `cordova platform add <platform>`.');
+    if (platformList.length === 0) {
+        var err = new Error('No platforms added to this project. Please use `cordova platform add <platform>`.');
+        if (callback) callback(err);
+        else throw err;
+        return;
+    }
 
     var hooks = new hooker(projectRoot);
     if (!(hooks.fire('before_compile'))) {
-        throw new Error('before_compile hooks exited with non-zero code. Aborting.');
+        var err = new Error('before_compile hooks exited with non-zero code. Aborting.');
+        if (callback) callback(err);
+        else throw err;
+        return;
     }
 
     var end = n(platformList.length, function() {
         if (!(hooks.fire('after_compile'))) {
-            throw new Error('after_compile hooks exited with non-zero code. Aborting.');
+            var err = new Error('after_compile hooks exited with non-zero code. Aborting.');
+            if (callback) callback(err);
+            else throw err;
+            return;
         }
         if (callback) callback();
     });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/src/create.js
----------------------------------------------------------------------
diff --git a/src/create.js b/src/create.js
index 84e8b13..5cced50 100644
--- a/src/create.js
+++ b/src/create.js
@@ -1,4 +1,3 @@
-
 /**
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
@@ -22,6 +21,7 @@ var path          = require('path'),
     shell         = require('shelljs'),
     help          = require('./help'),
     config_parser = require('./config_parser'),
+    events        = require('./events'),
     util          = require('./util');
 
 var DEFAULT_NAME = "HelloCordova",
@@ -49,6 +49,8 @@ module.exports = function create (dir, id, name) {
     // Make absolute.
     dir = path.resolve(dir);
 
+    events.emit('log', 'Creating a new cordova project with name "' + name + '" and id "' + id + '" at location "' + dir + '"');
+
     var dotCordova = path.join(dir, '.cordova');
 
     // Check for existing cordova project
@@ -95,6 +97,7 @@ module.exports = function create (dir, id, name) {
     }));
 
     // Copy in base template
+    events.emit('log', 'Copying stock application assets into "' + path.join(dir, 'www') + '"');
     shell.cp('-r', path.join(__dirname, '..', 'templates', 'www'), dir);
 
     // Write out id and name to config.xml

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/src/emulate.js
----------------------------------------------------------------------
diff --git a/src/emulate.js b/src/emulate.js
index 4e5451a..0787f60 100644
--- a/src/emulate.js
+++ b/src/emulate.js
@@ -22,6 +22,8 @@ var cordova_util      = require('./util'),
     config_parser     = require('./config_parser'),
     platforms         = require('../platforms'),
     platform          = require('./platform'),
+    events            = require('./events'),
+    prepare           = require('./prepare'),
     fs                = require('fs'),
     ls                = fs.readdirSync,
     n                 = require('ncallbacks'),
@@ -34,10 +36,12 @@ function shell_out_to_emulate(root, platform, callback) {
     if (platform == 'blackberry') {
         cmd = 'ant -f "' + path.join(root, 'platforms', platform, 'build.xml') + '" qnx load-simulator';
     }
+    events.emit('log', 'Running on emulator for platform "' + platform + '" via command "' + cmd + '"');
     shell.exec(cmd, {silent:true, async:true}, function(code, output) {
         if (code > 0) {
             throw new Error('An error occurred while emulating/deploying the ' + platform + ' project.' + output);
         } else {
+            events.emit('log', 'Platform "' + platform + '" deployed to emulator.');
             callback();
         }
     });
@@ -47,7 +51,10 @@ module.exports = function emulate (platformList, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
     if (!projectRoot) {
-        throw new Error('Current working directory is not a Cordova-based project.');
+        var err = new Error('Current working directory is not a Cordova-based project.');
+        if (callback) callback(err);
+        else throw err;
+        return;
     }
 
     var xml = cordova_util.projectConfig(projectRoot);
@@ -61,27 +68,41 @@ module.exports = function emulate (platformList, callback) {
         platformList = cordova_util.listPlatforms(projectRoot);
     }
 
-    if (platformList.length === 0) throw new Error('No platforms added to this project. Please use `cordova platform add <platform>`.');
+    if (platformList.length === 0) {
+        var err = new Error('No platforms added to this project. Please use `cordova platform add <platform>`.');
+        if (callback) callback(err);
+        else throw err;
+        return;
+    }
 
     var hooks = new hooker(projectRoot);
     if (!(hooks.fire('before_emulate'))) {
-        throw new Error('before_emulate hooks exited with non-zero code. Aborting build.');
+        var err = new Error('before_emulate hooks exited with non-zero code. Aborting build.');
+        if (callback) callback(err);
+        else throw err;
+        return;
     }
 
     var end = n(platformList.length, function() {
         if (!(hooks.fire('after_emulate'))) {
-            throw new Error('after_emulate hooks exited with non-zero code. Aborting.');
+            var err = new Error('after_emulate hooks exited with non-zero code. Aborting.');
+            if (callback) callback(err);
+            else throw err;
+            return;
         }
         if (callback) callback();
     });
 
-    // Iterate over each added platform and shell out to debug command
-    platformList.forEach(function(platform) {
-        var platformPath = path.join(projectRoot, 'platforms', platform);
-        var parser = new platforms[platform].parser(platformPath);
-        parser.update_project(cfg, function() {
-            shell_out_to_emulate(projectRoot, platform, end);
-        });
+    // Run a prepare first!
+    prepare(platformList, function(err) {
+        if (err) {
+            if (callback) callback(err);
+            else throw err;
+        } else {
+            platformList.forEach(function(platform) {
+                shell_out_to_emulate(projectRoot, platform, end);
+            });
+        }
     });
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/src/hooker.js
----------------------------------------------------------------------
diff --git a/src/hooker.js b/src/hooker.js
index 5a0eb3c..d40b686 100644
--- a/src/hooker.js
+++ b/src/hooker.js
@@ -1,4 +1,3 @@
-
 /**
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/src/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/android_parser.js b/src/metadata/android_parser.js
index a81de9d..63582a4 100644
--- a/src/metadata/android_parser.js
+++ b/src/metadata/android_parser.js
@@ -20,6 +20,7 @@ var fs            = require('fs'),
     path          = require('path'),
     et            = require('elementtree'),
     util          = require('../util'),
+    events        = require('../events'),
     shell         = require('shelljs'),
     config_parser = require('../config_parser');
 
@@ -69,6 +70,7 @@ module.exports.prototype = {
         var strings = new et.ElementTree(et.XML(fs.readFileSync(this.strings, 'utf-8')));
         strings.find('string[@name="app_name"]').text = name;
         fs.writeFileSync(this.strings, strings.write({indent: 4}), 'utf-8');
+        events.emit('log', 'Wrote out Android application name to "' + name + '"');
 
         // Update package name by changing the AndroidManifest id and moving the entry class around to the proper package directory
         var manifest = new et.ElementTree(et.XML(fs.readFileSync(this.manifest, 'utf-8')));
@@ -85,6 +87,7 @@ module.exports.prototype = {
         var new_javs = path.join(pkgDir, orig_java_class);
         var javs_contents = fs.readFileSync(orig_javs, 'utf-8');
         javs_contents = javs_contents.replace(/package [\w\.]*;/, 'package ' + pkg + ';');
+        events.emit('log', 'Wrote out Android package name to "' + pkg + '"');
         fs.writeFileSync(new_javs, javs_contents, 'utf-8');
 
         // Update whitelist by changing res/xml/config.xml
@@ -171,7 +174,13 @@ module.exports.prototype = {
 
     update_project:function(cfg, callback) {
         var platformWww = path.join(this.path, 'assets');
-        this.update_from_config(cfg);
+        try {
+            this.update_from_config(cfg);
+        } catch(e) {
+            if (callback) callback(e);
+            else throw e;
+            return;
+        }
         this.update_www();
         this.update_overrides();
         this.update_staging();

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/src/metadata/blackberry_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/blackberry_parser.js b/src/metadata/blackberry_parser.js
index 7ad69ba..e3c6f87 100644
--- a/src/metadata/blackberry_parser.js
+++ b/src/metadata/blackberry_parser.js
@@ -22,6 +22,7 @@ var fs            = require('fs'),
     prompt        = require('prompt'),
     shell         = require('shelljs'),
     util          = require('../util'),
+    events        = require('../events'),
     config_parser = require('../config_parser');
 
 module.exports = function blackberry_parser(project) {
@@ -44,7 +45,9 @@ module.exports.prototype = {
         } else throw new Error('update_from_config requires a config_parser object');
 
         this.xml.name(config.name());
+        events.emit('log', 'Wrote out BlackBerry application name to "' + config.name() + '"');
         this.xml.packageName(config.packageName());
+        events.emit('log', 'Wrote out BlackBerry package name to "' + config.packageName() + '"');
         this.xml.access.remove();
         var self = this;
         this.xml.doc.findall('access').forEach(function(a) {
@@ -61,7 +64,13 @@ module.exports.prototype = {
     update_project:function(cfg, callback) {
         var self = this;
 
-        self.update_from_config(cfg);
+        try {
+            self.update_from_config(cfg);
+        } catch(e) {
+            if (callback) callback(e);
+            else throw e;
+            return;
+        }
         self.update_www();
         self.update_overrides();
         self.update_staging();
@@ -72,17 +81,18 @@ module.exports.prototype = {
         var dotFile = path.join(projectRoot, '.cordova', 'config.json');
         var dot = JSON.parse(fs.readFileSync(dotFile, 'utf-8'));
         if (dot.blackberry === undefined || dot.blackberry.qnx === undefined) {
+            events.emit('warn', 'WARNING! Missing BlackBerry configuration file.');
             this.get_blackberry_environment(function() {
                 // Update project.properties
                 self.write_project_properties();
 
                 if (callback) callback();
             });
-            return;
+        } else {
+            // Write out config stuff to project.properties file
+            this.write_project_properties();
+            if (callback) callback();
         }
-        // Write out config stuff to project.properties file
-        this.write_project_properties();
-        if (callback) callback();
     },
 
     // Returns the platform-specific www directory.
@@ -144,7 +154,6 @@ module.exports.prototype = {
     },
 
     write_project_properties:function() {
-        // TODO: eventually support all blackberry sub-platforms
         var projectRoot = util.isCordova(this.path);
 
         var projFile = path.join(this.path, 'project.properties');
@@ -160,14 +169,14 @@ module.exports.prototype = {
         props = props.replace(/qnx\.sim\.ip=.*\n/, 'qnx.sim.ip=' + dot.blackberry.qnx.sim_ip + '\n');
         props = props.replace(/qnx\.sim\.password=.*\n/, 'qnx.sim.password=' + dot.blackberry.qnx.sim_password + '\n');
         fs.writeFileSync(projFile, props, 'utf-8');
+        events.emit('log', 'Wrote out BlackBerry 10 configuration file to "' + projFile + '"');
     },
     get_blackberry_environment:function(callback) {
-        // TODO: add other blackberry sub-platforms
         var projectRoot = util.isCordova(this.path);
         var dotFile = path.join(projectRoot, '.cordova', 'config.json');
         var dot = JSON.parse(fs.readFileSync(dotFile, 'utf-8'));
         // Let's save relevant BB SDK + signing info to .cordova/config.json
-        console.log('Looks like we need some of your BlackBerry development environment information. We\'ll just ask you a few questions and we\'ll be on our way to building.');
+        events.emit('log', 'Prompting for BlackBerry 10 configuration information...');
         prompt.start();
         prompt.get([{
             name:'bbwp',
@@ -192,19 +201,23 @@ module.exports.prototype = {
             description:'Enter the password for your BB10 simulator'
         }
         ], function(err, results) {
-            if (err) throw new Error('Error during BlackBerry environment config retrieval');
-            // Write out .cordova/config.json file
-            if (dot.blackberry === undefined) dot.blackberry = {};
-            if (dot.blackberry.qnx === undefined) dot.blackberry.qnx = {};
-            dot.blackberry.qnx.bbwp = results.bbwp;
-            dot.blackberry.qnx.signing_password = results.signing_password;
-            dot.blackberry.qnx.device_ip = results.device_ip;
-            dot.blackberry.qnx.device_password = results.device_password;
-            dot.blackberry.qnx.sim_ip = results.sim_ip;
-            dot.blackberry.qnx.sim_password = results.sim_password;
-            fs.writeFileSync(dotFile, JSON.stringify(dot), 'utf-8');
-            console.log('Perfect! If you need to change any of these properties, just edit the .cordova/config.json file in the root of your cordova project.');
-            if (callback) callback();
+            if (err) {
+                if (callback) callback(err);
+                else throw err;
+            } else {
+                // Write out .cordova/config.json file
+                if (dot.blackberry === undefined) dot.blackberry = {};
+                if (dot.blackberry.qnx === undefined) dot.blackberry.qnx = {};
+                dot.blackberry.qnx.bbwp = results.bbwp;
+                dot.blackberry.qnx.signing_password = results.signing_password;
+                dot.blackberry.qnx.device_ip = results.device_ip;
+                dot.blackberry.qnx.device_password = results.device_password;
+                dot.blackberry.qnx.sim_ip = results.sim_ip;
+                dot.blackberry.qnx.sim_password = results.sim_password;
+                fs.writeFileSync(dotFile, JSON.stringify(dot), 'utf-8');
+                events.emit('log', 'Wrote out BlackBerry 10 configuration file to "' + dotFile + '"');
+                if (callback) callback();
+            }
         });
     }
 };

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index 4f15a59..b7e2d69 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -20,6 +20,7 @@ var fs            = require('fs'),
     path          = require('path'),
     xcode         = require('xcode'),
     util          = require('../util'),
+    events        = require('../events'),
     shell         = require('shelljs'),
     plist         = require('plist'),
     semver        = require('semver'),
@@ -76,7 +77,12 @@ module.exports.check_requirements = function(callback) {
 module.exports.prototype = {
     update_from_config:function(config, callback) {
         if (config instanceof config_parser) {
-        } else throw new Error('update_from_config requires a config_parser object');
+        } else {
+            var err = new Error('update_from_config requires a config_parser object');
+            if (callback) callback(err);
+            else throw err;
+            return;
+        }
         var name = config.name();
         var pkg = config.packageName();
 
@@ -87,6 +93,7 @@ module.exports.prototype = {
         var info_contents = plist.build(infoPlist);
         info_contents = info_contents.replace(/<string>[\s\r\n]*<\/string>/g,'<string></string>');
         fs.writeFileSync(plistFile, info_contents, 'utf-8');
+        events.emit('log', 'Wrote out iOS Bundle Identifier to "' + pkg + '"');
 
         // Update whitelist
         var self = this;
@@ -124,10 +131,14 @@ module.exports.prototype = {
         var proj = new xcode.project(this.pbxproj);
         var parser = this;
         proj.parse(function(err,hash) {
-            if (err) throw new Error('An error occured during parsing of project.pbxproj. Start weeping.');
-            else {
+            if (err) {
+                var err = new Error('An error occured during parsing of project.pbxproj. Start weeping. Output: ' + err);
+                if (callback) callback(err);
+                else throw err;
+            } else {
                 proj.updateProductName(name);
                 fs.writeFileSync(parser.pbxproj, proj.writeSync(), 'utf-8');
+                events.emit('log', 'Wrote out iOS Product Name to "' + name + '"');
                 if (callback) callback();
             }
         });
@@ -183,12 +194,17 @@ module.exports.prototype = {
 
     update_project:function(cfg, callback) {
         var self = this;
-        this.update_from_config(cfg, function() {
-            self.update_www();
-            self.update_overrides();
-            self.update_staging();
-            util.deleteSvnFolders(self.www_dir());
-            if (callback) callback();
+        this.update_from_config(cfg, function(err) {
+            if (err) {
+                if (callback) callback(err);
+                else throw err;
+            } else {
+                self.update_www();
+                self.update_overrides();
+                self.update_staging();
+                util.deleteSvnFolders(self.www_dir());
+                if (callback) callback();
+            }
         });
     }
 };

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 38032bc..7f9af14 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -22,6 +22,7 @@ var config_parser     = require('./config_parser'),
     fs                = require('fs'),
     path              = require('path'),
     hooker            = require('./hooker'),
+    events            = require('./events'),
     n                 = require('ncallbacks'),
     platforms         = require('../platforms'),
     plugman           = require('plugman'),
@@ -31,7 +32,10 @@ module.exports = function platform(command, targets, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
     if (!projectRoot) {
-        throw new Error('Current working directory is not a Cordova-based project.');
+        var err = new Error('Current working directory is not a Cordova-based project.');
+        if (callback) callback(err);
+        else throw err;
+        return;
     }
 
     var hooks = new hooker(projectRoot),
@@ -67,16 +71,22 @@ module.exports = function platform(command, targets, callback) {
 
                 // Check if output directory already exists.
                 if (fs.existsSync(output)) {
-                    throw new Error('Platform "' + target + '" already exists' );
+                    var err = new Error('Platform "' + target + '" already exists' );
+                    if (callback) callback(err);
+                    else throw err;
+                    return;
                 }
 
                 // Make sure we have minimum requirements to work with specified platform
+                events.emit('log', 'Checking if platform "' + target + '" passes minimum requirements.');
                 module.exports.supports(target, function(err) {
                     if (err) {
-                        throw new Error('Your system does not meet the requirements to create ' + target + ' projects: ' + err.message);
+                        var err = new Error('Your system does not meet the requirements to create ' + target + ' projects: ' + err.message);
+                        if (callback) callback(err);
+                        else throw err;
+                        return;
                     } else {
                         // Create a platform app using the ./bin/create scripts that exist in each repo.
-                        // TODO: eventually refactor to allow multiple versions to be created.
                         // Run platform's create script
                         var bin = path.join(cordova_util.libDirectory, 'cordova-' + target, 'bin', 'create');
                         var args = (target=='ios') ? '--arc' : '';
@@ -85,13 +95,18 @@ module.exports = function platform(command, targets, callback) {
                         // TODO: PLATFORM LIBRARY INCONSISTENCY: order/number of arguments to create
                         // TODO: keep tabs on CB-2300
                         var command = util.format('"%s" %s "%s" "%s" "%s"', bin, args, output, (target=='blackberry'?name:pkg), name);
+                        events.emit('log', 'Running bin/create for platform "' + target + '" with command: "' + command + '"');
 
                         shell.exec(command, {silent:true,async:true}, function(code, create_output) {
                             if (code > 0) {
-                                throw new Error('An error occured during creation of ' + target + ' sub-project. ' + create_output);
+                                var err = new Error('An error occured during creation of ' + target + ' sub-project. ' + create_output);
+                                if (callback) callback(err);
+                                else throw err;
+                                return;
                             }
 
                             var parser = new platforms[target].parser(output);
+                            events.emit('log', 'Updating ' + target + ' project from config.xml...');
                             parser.update_project(cfg, function() {
                                 createOverrides(target);
                                 hooks.fire('after_platform_add');
@@ -104,6 +119,7 @@ module.exports = function platform(command, targets, callback) {
                                         return;
                                     }
 
+                                    events.emit('log', 'Installing plugin "' + plugin + '" following success platform add of ' + target);
                                     plugman.install(target, output, path.basename(plugin), pluginsDir, { www_dir: parser.staging_dir() });
                                 });
                                 end();

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/src/plugin.js
----------------------------------------------------------------------
diff --git a/src/plugin.js b/src/plugin.js
index 6045840..0851305 100644
--- a/src/plugin.js
+++ b/src/plugin.js
@@ -25,6 +25,7 @@ var cordova_util  = require('./util'),
     platforms     = require('../platforms'),
     config_parser = require('./config_parser'),
     hooker        = require('./hooker'),
+    events        = require('./events'),
     plugin_parser = require('./plugin_parser'),
     ls            = fs.readdirSync,
     plugman       = require('plugman');
@@ -33,7 +34,10 @@ module.exports = function plugin(command, targets, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
     if (!projectRoot) {
-        throw new Error('Current working directory is not a Cordova-based project.');
+        var err = new Error('Current working directory is not a Cordova-based project.');
+        if (callback) callback(err);
+        else throw err;
+        return;
     }
     if (arguments.length === 0) command = 'ls';
 
@@ -72,9 +76,13 @@ module.exports = function plugin(command, targets, callback) {
                 }
 
                 // Fetch the plugin first.
+                events.emit('log', 'Calling plugman.fetch on plugin "' + target + '"');
                 plugman.fetch(target, pluginsDir, {}, function(err, dir) {
                     if (err) {
-                        throw new Error('Error fetching plugin: ' + err);
+                        var err = new Error('Error fetching plugin: ' + err);
+                        if (callback) callback(err);
+                        else throw err;
+                        return;
                     }
 
                     // Iterate over all platforms in the project and install the plugin.
@@ -82,6 +90,7 @@ module.exports = function plugin(command, targets, callback) {
                         var platformRoot = path.join(projectRoot, 'platforms', platform);
                         var parser = new platforms[platform].parser(platformRoot);
                         // TODO: unify use of blackberry in cli vs blackberry10 in plugman
+                        events.emit('log', 'Calling plugman.install on plugin "' + dir + '" for platform "' + platform + '"');
                         plugman.install((platform=='blackberry'?'blackberry10':platform), platformRoot,
                                         path.basename(dir), pluginsDir, { www_dir: parser.staging_dir() });
                     });
@@ -94,7 +103,10 @@ module.exports = function plugin(command, targets, callback) {
         case 'rm':
         case 'remove':
             if (platformList.length === 0) {
-                throw new Error('You need at least one platform added to your app. Use `cordova platform add <platform>`.');
+                var err = new Error('You need at least one platform added to your app. Use `cordova platform add <platform>`.');
+                if (callback) callback(err);
+                else throw err;
+                return;
             }
             targets.forEach(function(target, index) {
                 // Check if we have the plugin.
@@ -116,17 +128,23 @@ module.exports = function plugin(command, targets, callback) {
                     intersection.forEach(function(platform) {
                         var platformRoot = path.join(projectRoot, 'platforms', platform);
                         var parser = new platforms[platform].parser(platformRoot);
+                        events.emit('log', 'Calling plugman.uninstall on plugin "' + target + '" for platform "' + platform + '"');
                         plugman.uninstall(platform, platformRoot, target, path.join(projectRoot, 'plugins'), { www_dir: parser.staging_dir() });
                     });
 
                     hooks.fire('after_plugin_rm');
                 } else {
-                    throw new Error('Plugin "' + target + '" not added to project.');
+                    var err = new Error('Plugin "' + target + '" not added to project.');
+                    if (callback) callback(err);
+                    else throw err;
+                    return;
                 }
             });
             if (callback) callback();
             break;
         default:
-            throw new Error('Unrecognized command "' + command + '". Use either `add`, `remove`, or `list`.');
+            var err = new Error('Unrecognized command "' + command + '". Use either `add`, `remove`, or `list`.');
+            if (callback) callback(err);
+            else throw err;
     }
 };

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/00d88531/src/prepare.js
----------------------------------------------------------------------
diff --git a/src/prepare.js b/src/prepare.js
index b08827e..9911000 100644
--- a/src/prepare.js
+++ b/src/prepare.js
@@ -25,6 +25,7 @@ var cordova_util      = require('./util'),
     shell             = require('shelljs'),
     et                = require('elementtree'),
     hooker            = require('./hooker'),
+    events            = require('./events'),
     n                 = require('ncallbacks'),
     prompt            = require('prompt'),
     plugman           = require('plugman'),
@@ -34,7 +35,10 @@ module.exports = function prepare(platformList, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
     if (!projectRoot) {
-        throw new Error('Current working directory is not a Cordova-based project.');
+        var err = new Error('Current working directory is not a Cordova-based project.');
+        if (callback) callback(err);
+        else throw err;
+        return;
     }
 
     var xml = cordova_util.projectConfig(projectRoot);
@@ -48,16 +52,27 @@ module.exports = function prepare(platformList, callback) {
         platformList = cordova_util.listPlatforms(projectRoot);
     }
 
-    if (platformList.length === 0) throw new Error('No platforms added to this project. Please use `cordova platform add <platform>`.');
+    if (platformList.length === 0) {
+        var err = new Error('No platforms added to this project. Please use `cordova platform add <platform>`.');
+        if (callback) callback(err);
+        else throw err;
+        return;
+    }
 
     var hooks = new hooker(projectRoot);
     if (!(hooks.fire('before_prepare'))) {
-        throw new Error('before_prepare hooks exited with non-zero code. Aborting.');
+        var err = new Error('before_prepare hooks exited with non-zero code. Aborting.');
+        if (callback) callback(err);
+        else throw err;
+        return;
     }
 
     var end = n(platformList.length, function() {
         if (!(hooks.fire('after_prepare'))) {
-            throw new Error('after_prepare hooks exited with non-zero code. Aborting.');
+            var err = new Error('after_prepare hooks exited with non-zero code. Aborting.');
+            if (callback) callback(err);
+            else throw err;
+            return;
         }
         if (callback) callback();
     });
@@ -66,22 +81,24 @@ module.exports = function prepare(platformList, callback) {
     platformList.forEach(function(platform) {
         var platformPath = path.join(projectRoot, 'platforms', platform);
         var parser = new platforms[platform].parser(platformPath);
-
         parser.update_project(cfg, function() {
             // Call plugman --prepare for this platform. sets up js-modules appropriately.
             var plugins_dir = path.join(projectRoot, 'plugins');
+            events.emit('log', 'Calling plugman.prepare for platform "' + platform + '"');
             plugman.prepare(platformPath, platform, plugins_dir);
 
             // Make sure that config changes for each existing plugin is in place
             var plugins = cordova_util.findPlugins(plugins_dir);
             var platform_json = plugman.config_changes.get_platform_json(plugins_dir, platform);
-            plugins.forEach(function(plugin_id) {
+            plugins && plugins.forEach(function(plugin_id) {
                 if (platform_json.installed_plugins[plugin_id]) {
-                    console.log('readding ' + plugin_id);
+                    events.emit('log', 'Ensuring plugin "' + plugin_id + '" is installed correctly...');
                     plugman.config_changes.add_plugin_changes(platform, platformPath, plugins_dir, plugin_id, /* variables for plugin */ platform_json.installed_plugins[plugin_id], /* top level plugin? */ true, /* should increment config munge? cordova-cli never should, only plugman */ false);
                 } else if (platform_json.dependent_plugins[plugin_id]) {
+                    events.emit('log', 'Ensuring plugin "' + plugin_id + '" is installed correctly...');
                     plugman.config_changes.add_plugin_changes(platform, platformPath, plugins_dir, plugin_id, /* variables for plugin */ platform_json.dependent_plugins[plugin_id], /* top level plugin? */ false, /* should increment config munge? cordova-cli never should, only plugman */ false);
                 }
+                events.emit('log', 'Plugin "' + plugin_id + '" is good to go.');
             });
             end();
         });