You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sg...@apache.org on 2014/09/26 23:20:11 UTC

[12/13] git commit: CB-6481 getPluginsHookScripts to work if plugin platform not defined

CB-6481 getPluginsHookScripts to work if plugin platform not defined

Also HookRunner minor code improvements


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

Branch: refs/heads/master
Commit: a8cf9fd23dd74b897e45de6b4f94a796885f9b7c
Parents: b74d87d
Author: sgrebnov <v-...@microsoft.com>
Authored: Sun Aug 10 19:59:12 2014 +0400
Committer: daserge <da...@yandex.ru>
Committed: Thu Sep 25 19:06:15 2014 +0400

----------------------------------------------------------------------
 cordova-lib/src/hooks/HooksRunner.js   | 26 +++++---------------------
 cordova-lib/src/hooks/scriptsFinder.js |  4 ++--
 2 files changed, 7 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a8cf9fd2/cordova-lib/src/hooks/HooksRunner.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/hooks/HooksRunner.js b/cordova-lib/src/hooks/HooksRunner.js
index 77ed54a..0bb199f 100644
--- a/cordova-lib/src/hooks/HooksRunner.js
+++ b/cordova-lib/src/hooks/HooksRunner.js
@@ -61,7 +61,6 @@ HooksRunner.prototype.fire = function fire(hook, opts) {
 
 /**
  * Refines passed options so that all required parameters are set.
- * Returns a promise.
  */
 HooksRunner.prototype.prepareOptions = function(opts) {
     opts = opts || {};
@@ -110,26 +109,11 @@ function executeEventHandlersSerially(hook, opts) {
  * Returns promise.
  */
 function runScriptsSerially (scripts, context) {
-    var deferral = new Q.defer();
-
-    function executePendingScript() {
-        try {
-            if (scripts.length === 0) {
-                deferral.resolve();
-                return;
-            }
-            var nextScript = scripts[0];
-            scripts.shift();
-
-            runScript(nextScript, context).then(executePendingScript, function(err){
-                deferral.reject(err);
-            });
-        } catch (ex) {
-            deferral.reject(ex);
-        }
-    }
-    executePendingScript();
-    return deferral.promise;
+    return scripts.reduce(function(prevScriptPromise, nextScript) {
+        return prevScriptPromise.then(function() { 
+            return runScript(nextScript, context);
+        });
+    }, Q());
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a8cf9fd2/cordova-lib/src/hooks/scriptsFinder.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/hooks/scriptsFinder.js b/cordova-lib/src/hooks/scriptsFinder.js
index 3345af1..33a076a 100644
--- a/cordova-lib/src/hooks/scriptsFinder.js
+++ b/cordova-lib/src/hooks/scriptsFinder.js
@@ -71,8 +71,8 @@ function getPluginsHookScripts(hook, opts) {
     // retrieve scripts exclusive for this plugin.
     if(opts.plugin) {
         events.emit('debug', 'Executing "' + hook + '"  hook for "' + opts.plugin.id + '" on ' + opts.plugin.platform + '.');
-
-        return getPluginScriptFiles(opts.plugin, hook, [ opts.plugin.platform ]);
+        // if plugin hook is not run for specific platform then use all available platforms
+        return getPluginScriptFiles(opts.plugin, hook, opts.plugin.platform  ? [opts.plugin.platform] : opts.cordova.platforms);
     }
 
     events.emit('debug', 'Executing "' + hook + '"  hook for all plugins.');