You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/06/21 17:54:13 UTC

git commit: Move Q_chainmap cordova/util -> util/promiseutil. Use it in plugman/uninstall.

Repository: cordova-lib
Updated Branches:
  refs/heads/master 2c9dce9fb -> 5322192a9


Move Q_chainmap cordova/util -> util/promiseutil. Use it in plugman/uninstall.


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

Branch: refs/heads/master
Commit: 5322192a9c5693300aec34facf7eddcc7bbc1258
Parents: 2c9dce9
Author: Andrew Grieve <ag...@chromium.org>
Authored: Sat Jun 21 11:53:36 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Sat Jun 21 11:53:36 2014 -0400

----------------------------------------------------------------------
 cordova-lib/src/cordova/platform.js  | 97 ++++++++++++++++---------------
 cordova-lib/src/cordova/util.js      | 14 -----
 cordova-lib/src/plugman/uninstall.js | 25 ++++----
 cordova-lib/src/util/promise-util.js | 40 +++++++++++++
 4 files changed, 102 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/5322192a/cordova-lib/src/cordova/platform.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js
index 784b1c5..be8c60b 100644
--- a/cordova-lib/src/cordova/platform.js
+++ b/cordova-lib/src/cordova/platform.js
@@ -37,6 +37,7 @@ var config            = require('./config'),
     CordovaError      = require('../CordovaError'),
     Q                 = require('q'),
     platforms         = require('./platforms'),
+    promiseutil       = require('../util/promise-util'),
     superspawn        = require('./superspawn'),
     semver            = require('semver'),
     shell             = require('shelljs');
@@ -76,56 +77,58 @@ function add(hooks, projectRoot, targets, opts) {
     }
 
     return hooks.fire('before_platform_add', opts)
-    .then(cordova_util.Q_chainmap(targets, function(t) {
-        // For each platform, download it and call its "create" script.
-
-        var p;  // The promise to be returned by this function.
-        var platform = t.split('@')[0];
-        // If t is not a platform or platform@version, it must be a dir.
-        // In this case get platform name from package.json in that dir and
-        // skip lazy-load.
-        if( !(platform in platforms) ) {
-            var pPath = path.resolve(t);
-            var pkg;
-            // Prep the message in advance, we might need it in several places.
-            msg = 'The provided path does not seem to contain a ' +
-                  'Cordova platform: ' + t;
-            try {
-                pkg = require(path.join(pPath, 'package'));
-            } catch(e) {
-                throw new CordovaError(msg + '\n' + e.message);
-            }
-            if ( !pkg || !pkg.name ) {
-                throw new CordovaError(msg);
-            }
-            // Package names for Cordova platforms look like "cordova-ios".
-            var nameParts = pkg.name.split('-');
-            var name = nameParts[1];
-            if( !platforms[name] ) {
-                throw new CordovaError(msg);
+    .then(function() {
+        return promiseutil.Q_chainmap(targets, function(t) {
+            // For each platform, download it and call its "create" script.
+
+            var p;  // The promise to be returned by this function.
+            var platform = t.split('@')[0];
+            // If t is not a platform or platform@version, it must be a dir.
+            // In this case get platform name from package.json in that dir and
+            // skip lazy-load.
+            if( !(platform in platforms) ) {
+                var pPath = path.resolve(t);
+                var pkg;
+                // Prep the message in advance, we might need it in several places.
+                msg = 'The provided path does not seem to contain a ' +
+                      'Cordova platform: ' + t;
+                try {
+                    pkg = require(path.join(pPath, 'package'));
+                } catch(e) {
+                    throw new CordovaError(msg + '\n' + e.message);
+                }
+                if ( !pkg || !pkg.name ) {
+                    throw new CordovaError(msg);
+                }
+                // Package names for Cordova platforms look like "cordova-ios".
+                var nameParts = pkg.name.split('-');
+                var name = nameParts[1];
+                if( !platforms[name] ) {
+                    throw new CordovaError(msg);
+                }
+                platform = name;
+
+                // Use a fulfilled promise with the path as value to skip dloading.
+                p = Q(pPath);
+            } else {
+                // Using lazy_load for a platform specified by name
+                p = lazy_load.based_on_config(projectRoot, t, opts)
+                .fail(function(err) {
+                    throw new CordovaError('Unable to fetch platform ' + t + ': ' + err);
+                });
             }
-            platform = name;
-
-            // Use a fulfilled promise with the path as value to skip dloading.
-            p = Q(pPath);
-        } else {
-            // Using lazy_load for a platform specified by name
-            p = lazy_load.based_on_config(projectRoot, t, opts)
-            .fail(function(err) {
-                throw new CordovaError('Unable to fetch platform ' + t + ': ' + err);
-            });
-        }
 
-        return p
-        .then(function(libDir) {
-            var template = config_json.lib && config_json.lib[platform] && config_json.lib[platform].template || null;
-            var copts = null;
-            if ('spawnoutput' in opts) {
-                copts = opts.spawnoutput;
-            }
-            return call_into_create(platform, projectRoot, cfg, libDir, template, copts);
+            return p
+            .then(function(libDir) {
+                var template = config_json.lib && config_json.lib[platform] && config_json.lib[platform].template || null;
+                var copts = null;
+                if ('spawnoutput' in opts) {
+                    copts = opts.spawnoutput;
+                }
+                return call_into_create(platform, projectRoot, cfg, libDir, template, copts);
+            });
         });
-    }))
+    })
     .then(function() {
         return hooks.fire('after_platform_add', opts);
     });

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/5322192a/cordova-lib/src/cordova/util.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/util.js b/cordova-lib/src/cordova/util.js
index d4ee389..86dff6d 100644
--- a/cordova-lib/src/cordova/util.js
+++ b/cordova-lib/src/cordova/util.js
@@ -23,7 +23,6 @@
 
 var fs            = require('fs'),
     path          = require('path'),
-    Q             = require('q'),
     CordovaError  = require('../CordovaError'),
     shell         = require('shelljs');
 
@@ -48,7 +47,6 @@ exports.projectWww = projectWww;
 exports.projectConfig = projectConfig;
 exports.preProcessOptions = preProcessOptions;
 exports.addModuleProperty = addModuleProperty;
-exports.Q_chainmap = Q_chainmap;
 
 function isRootDir(dir) {
     if (fs.existsSync(path.join(dir, 'www'))) {
@@ -235,15 +233,3 @@ function addModuleProperty(module, symbol, modulePath, opt_wrap, opt_obj) {
         });
     }
 }
-
-// Given a function and an array of values, creates a chain of promises that
-// will sequentially execute func(args[i]).
-function Q_chainmap(args, func) {
-    return function(inValue) {
-        return args.reduce(function(soFar, arg) {
-            return soFar.then(function(val) {
-                return func(arg, val);
-            });
-        }, Q(inValue));
-    };
-}

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/5322192a/cordova-lib/src/plugman/uninstall.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/uninstall.js b/cordova-lib/src/plugman/uninstall.js
index 3145a3c..408f6f6 100644
--- a/cordova-lib/src/plugman/uninstall.js
+++ b/cordova-lib/src/plugman/uninstall.js
@@ -35,7 +35,8 @@ var path = require('path'),
     underscore = require('underscore'),
     events = require('../events'),
     platform_modules = require('./platforms'),
-    plugman = require('./plugman');
+    plugman = require('./plugman'),
+    promiseutil = require('../util/promise-util');
 
 // possible options: cli_variables, www_dir
 // Returns a promise.
@@ -216,18 +217,16 @@ function runUninstallPlatform(actions, platform, project_dir, plugin_dir, plugin
 
         // @tests - important this event is checked spec/uninstall.spec.js
         events.emit('log', 'Uninstalling ' + danglers.length + ' dependent plugins.');
-        promise = Q.all(
-            danglers.map(function(dangler) {
-                var dependent_path = dependencies.resolvePath(dangler, plugins_dir);
-
-                var opts = underscore.extend({}, options, {
-                    is_top_level: depsInfo.top_level_plugins.indexOf(dangler) > -1,
-                    depsInfo: depsInfo
-                });
-
-                return runUninstallPlatform(actions, platform, project_dir, dependent_path, plugins_dir, opts);
-            })
-        );
+        promise = promiseutil.Q_chainmap(danglers, function(dangler) {
+            var dependent_path = dependencies.resolvePath(dangler, plugins_dir);
+
+            var opts = underscore.extend({}, options, {
+                is_top_level: depsInfo.top_level_plugins.indexOf(dangler) > -1,
+                depsInfo: depsInfo
+            });
+
+            return runUninstallPlatform(actions, platform, project_dir, dependent_path, plugins_dir, opts);
+        });
     } else {
         promise = Q();
     }

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/5322192a/cordova-lib/src/util/promise-util.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/util/promise-util.js b/cordova-lib/src/util/promise-util.js
new file mode 100644
index 0000000..e8b038e
--- /dev/null
+++ b/cordova-lib/src/util/promise-util.js
@@ -0,0 +1,40 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+
+/* jshint node:true, bitwise:true, undef:true, trailing:true, quotmark:true,
+          indent:4, unused:vars, latedef:nofunc
+*/
+
+var Q = require('q');
+
+// Given a function and an array of values, creates a chain of promises that
+// will sequentially execute func(args[i]).
+// Returns a promise.
+//
+function Q_chainmap(args, func) {
+    return Q.when().then(function(inValue) {
+        return args.reduce(function(soFar, arg) {
+            return soFar.then(function(val) {
+                return func(arg, val);
+            });
+        }, Q(inValue));
+    });
+}
+
+exports.Q_chainmap = Q_chainmap;