You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2013/09/25 17:54:50 UTC

[3/3] git commit: [CB-4877]: Add basic logging, --silent flag.

[CB-4877]: Add basic logging, --silent flag.


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

Branch: refs/heads/master
Commit: aa09f18171d36493f6bd73c06132cdc92fe77e5b
Parents: f2574b2
Author: Braden Shepherdson <br...@gmail.com>
Authored: Wed Sep 25 11:53:12 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Wed Sep 25 11:53:12 2013 -0400

----------------------------------------------------------------------
 src/cli.js       |  12 +++---
 src/compile.js   |   2 +-
 src/lazy_load.js |   2 +-
 src/platform.js  |   3 +-
 src/plugin.js    | 110 ++++++++++++++++++++++++++------------------------
 5 files changed, 67 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/aa09f181/src/cli.js
----------------------------------------------------------------------
diff --git a/src/cli.js b/src/cli.js
index 9dd18f8..6e82f99 100755
--- a/src/cli.js
+++ b/src/cli.js
@@ -37,7 +37,8 @@ module.exports = function CLI(inputArgs) {
         opts = {
             platforms: [],
             options: [],
-            verbose: (args.d || args.verbose)
+            verbose: (args.d || args.verbose),
+            silent: args.silent
         },
         cmd;
 
@@ -58,8 +59,12 @@ module.exports = function CLI(inputArgs) {
         var plugman = require('plugman');
         plugman.on('log', console.log);
         plugman.on('warn', console.warn);
+    } else {
+        // Remove the token.
+        tokens.splice(tokens.indexOf('--silent'), 1);
     }
 
+
     if (opts.verbose) {
         // Add handlers for verbose logging.
         cordova.on('verbose', console.log);
@@ -75,11 +80,6 @@ module.exports = function CLI(inputArgs) {
         }
     }
 
-    if (opts.silent) {
-        // Remove the token.
-        tokens.splice(tokens.indexOf('--silent'));
-    }
-
     cmd = tokens && tokens.length ? tokens.splice(0,1) : undefined;
     if (cmd === undefined) {
         return cordova.help();

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/aa09f181/src/compile.js
----------------------------------------------------------------------
diff --git a/src/compile.js b/src/compile.js
index 0069b45..34c24fe 100644
--- a/src/compile.js
+++ b/src/compile.js
@@ -26,7 +26,7 @@ var cordova_util      = require('./util'),
 // Returns a promise.
 function shell_out_to_build(projectRoot, platform, options) {
     var cmd = '"' + path.join(projectRoot, 'platforms', platform, 'cordova', 'build') + (options.length ? '" ' + options.join(" ") : '"');
-    events.emit('log', 'Compiling platform "' + platform + '" with command "' + cmd + '"');
+    events.emit('log', 'Compiling ' + platform + ' project.');
     var d = Q.defer();
     child_process.exec(cmd, function(err, stdout, stderr) {
         events.emit('verbose', stdout);

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/aa09f181/src/lazy_load.js
----------------------------------------------------------------------
diff --git a/src/lazy_load.js b/src/lazy_load.js
index 9a982ea..b34105d 100644
--- a/src/lazy_load.js
+++ b/src/lazy_load.js
@@ -47,7 +47,7 @@ module.exports = {
         var download_dir = (platform == 'wp7' || platform == 'wp8' ? path.join(util.libDirectory, 'wp', id, version) :
                                                                      path.join(util.libDirectory, platform, id, version));
         if (fs.existsSync(download_dir)) {
-            events.emit('log', id + ' library for "' + platform + '" already exists. No need to download. Continuing.');
+            events.emit('verbose', id + ' library for "' + platform + '" already exists. No need to download. Continuing.');
             return Q();
         }
         events.emit('log', 'Downloading ' + id + ' library for ' + platform + '...');

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/aa09f181/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 3da1de9..3b4adac 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -228,7 +228,7 @@ function call_into_create(target, projectRoot, cfg, id, version, template_dir) {
         return Q.reject(new Error('Platform ' + target + ' already added'));
     } else {
         // Make sure we have minimum requirements to work with specified platform
-        events.emit('log', 'Checking if platform "' + target + '" passes minimum requirements...');
+        events.emit('verbose', 'Checking if platform "' + target + '" passes minimum requirements...');
         return module.exports.supports(projectRoot, target)
         .then(function() {
             // Create a platform app using the ./bin/create scripts that exist in each repo.
@@ -243,6 +243,7 @@ function call_into_create(target, projectRoot, cfg, id, version, template_dir) {
             if (template_dir) {
                 command += ' "' + template_dir + '"';
             }
+            events.emit('log', 'Creating ' + target + ' project...');
             events.emit('verbose', 'Running bin/create for platform "' + target + '" with command: "' + command + '" (output to follow)');
 
             var d = Q.defer();

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/aa09f181/src/plugin.js
----------------------------------------------------------------------
diff --git a/src/plugin.js b/src/plugin.js
index d7cac8e..0139393 100644
--- a/src/plugin.js
+++ b/src/plugin.js
@@ -78,49 +78,52 @@ module.exports = function plugin(command, targets) {
         case 'add':
             return hooks.fire('before_plugin_add', opts)
             .then(function() {
-                return Q.all(opts.plugins.map(function(target, index) {
+                return opts.plugins.reduce(function(soFar, target) {
                     var pluginsDir = path.join(projectRoot, 'plugins');
+                    return soFar.then(function() {
+                        if (target[target.length - 1] == path.sep) {
+                            target = target.substring(0, target.length - 1);
+                        }
 
-                    if (target[target.length - 1] == path.sep) {
-                        target = target.substring(0, target.length - 1);
-                    }
-
-                    // Fetch the plugin first.
-                    events.emit('verbose', 'Calling plugman.fetch on plugin "' + target + '"');
-                    var plugman = require('plugman');
-                    return plugman.raw.fetch(target, pluginsDir, {})
+                        // Fetch the plugin first.
+                        events.emit('verbose', 'Calling plugman.fetch on plugin "' + target + '"');
+                        var plugman = require('plugman');
+                        return plugman.raw.fetch(target, pluginsDir, {})
+                    })
                     .fail(function(err) {
                         return Q.reject(new Error('Error fetching plugin: ' + err));
                     })
                     .then(function(dir) {
                         // Iterate (in serial!) over all platforms in the project and install the plugin.
-                        return Q.all(platformList.map(function(platform) {
-                            var platforms = require('../platforms');
-                            var platformRoot = path.join(projectRoot, 'platforms', platform),
-                                parser = new platforms[platform].parser(platformRoot),
-                                options = {
-                                    www_dir: parser.staging_dir(),
-                                    cli_variables: {}
-                                },
-                                tokens,
-                                key,
-                                i;
-                            //parse variables into cli_variables
-                            for (i=0; i< opts.options.length; i++) {
-                                if (opts.options[i] === "--variable" && typeof opts.options[++i] === "string") {
-                                    tokens = opts.options[i].split('=');
-                                    key = tokens.shift().toUpperCase();
-                                    if (/^[\w-_]+$/.test(key)) {
-                                        options.cli_variables[key] = tokens.join('=');
+                        return platformList.reduce(function(soFar, platform) {
+                            return soFar.then(function() {
+                                var platforms = require('../platforms');
+                                var platformRoot = path.join(projectRoot, 'platforms', platform),
+                                    parser = new platforms[platform].parser(platformRoot),
+                                    options = {
+                                        www_dir: parser.staging_dir(),
+                                        cli_variables: {}
+                                    },
+                                    tokens,
+                                    key,
+                                    i;
+                                //parse variables into cli_variables
+                                for (i=0; i< opts.options.length; i++) {
+                                    if (opts.options[i] === "--variable" && typeof opts.options[++i] === "string") {
+                                        tokens = opts.options[i].split('=');
+                                        key = tokens.shift().toUpperCase();
+                                        if (/^[\w-_]+$/.test(key)) {
+                                            options.cli_variables[key] = tokens.join('=');
+                                        }
                                     }
                                 }
-                            }
 
-                            events.emit('verbose', 'Calling plugman.install on plugin "' + dir + '" for platform "' + platform + '" with options "' + JSON.stringify(options)  + '"');
-                            return plugman.raw.install(platform, platformRoot, path.basename(dir), pluginsDir, options);
-                        }));
+                                events.emit('verbose', 'Calling plugman.install on plugin "' + dir + '" for platform "' + platform + '" with options "' + JSON.stringify(options)  + '"');
+                                return plugman.raw.install(platform, platformRoot, path.basename(dir), pluginsDir, options);
+                            });
+                        }, Q());
                     });
-                })); // end Q.all
+                }, Q()); // end Q.all
             }).then(function() {
                 return hooks.fire('after_plugin_add', opts);
             });
@@ -129,30 +132,31 @@ module.exports = function plugin(command, targets) {
         case 'remove':
             return hooks.fire('before_plugin_rm', opts)
             .then(function() {
-                return Q.all(opts.plugins.map(function(target, index) {
+                return opts.plugins.reduce(function(soFar, target) {
                     // Check if we have the plugin.
-                    if (plugins.indexOf(target) > -1) {
-                        var targetPath = path.join(pluginPath, target);
-                        // Iterate over all installed platforms and uninstall.
-                        // If this is a web-only or dependency-only plugin, then
-                        // there may be nothing to do here except remove the
-                        // reference from the platform's plugin config JSON.
-                        var plugman = require('plugman');
-                        return Q.all(
-                            platformList.map(function(platform) {
-                                var platformRoot = path.join(projectRoot, 'platforms', platform);
-                                var platforms = require('../platforms');
-                                var parser = new platforms[platform].parser(platformRoot);
-                                events.emit('verbose', 'Calling plugman.uninstall on plugin "' + target + '" for platform "' + platform + '"');
-                                return plugman.raw.uninstall.uninstallPlatform(platform, platformRoot, target, path.join(projectRoot, 'plugins'), { www_dir: parser.staging_dir() });
-                            })
-                        ).then(function() {
-                            return plugman.raw.uninstall.uninstallPlugin(target, path.join(projectRoot, 'plugins'));
-                        });
-                    } else {
+                    if (plugins.indexOf(target) < 0) {
                         return Q.reject(new Error('Plugin "' + target + '" not added to project.'));
                     }
-                }));
+
+                    var targetPath = path.join(pluginPath, target);
+                    // Iterate over all installed platforms and uninstall.
+                    // If this is a web-only or dependency-only plugin, then
+                    // there may be nothing to do here except remove the
+                    // reference from the platform's plugin config JSON.
+                    var plugman = require('plugman');
+                    return platformList.reduce(function(soFar, platform) {
+                        return soFar.then(function() {
+                            var platformRoot = path.join(projectRoot, 'platforms', platform);
+                            var platforms = require('../platforms');
+                            var parser = new platforms[platform].parser(platformRoot);
+                            events.emit('verbose', 'Calling plugman.uninstall on plugin "' + target + '" for platform "' + platform + '"');
+                            return plugman.raw.uninstall.uninstallPlatform(platform, platformRoot, target, path.join(projectRoot, 'plugins'), { www_dir: parser.staging_dir() });
+                        });
+                    }, Q())
+                    .then(function() {
+                        return plugman.raw.uninstall.uninstallPlugin(target, path.join(projectRoot, 'plugins'));
+                    });
+                }, Q());
             }).then(function() {
                 return hooks.fire('after_plugin_rm', opts);
             });