You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/10/10 08:50:55 UTC

[cordova-lib] branch master updated: HooksRunner code & spec cleanup (#796)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-lib.git


The following commit(s) were added to refs/heads/master by this push:
     new 7f66885  HooksRunner code & spec cleanup (#796)
7f66885 is described below

commit 7f6688582aa778a5b9f0ba70b55b1479536a572e
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Thu Oct 10 10:50:51 2019 +0200

    HooksRunner code & spec cleanup (#796)
    
    * Cleanup HooksRunner code
    
    * Merge the 'plugin hooks' blocks in HooksRunner.spec
    
    * Reduce amount of fixtures for HooksRunner test
---
 integration-tests/HooksRunner.spec.js              | 122 ++++++++++++++++-----
 .../com.plugin.withhooks/pluginOnePlatform_bat.xml |  19 ----
 .../com.plugin.withhooks/pluginOnePlatform_sh.xml  |  19 ----
 .../pluginOnlyNonPlatformScripts_bat.xml           |  14 ---
 .../pluginOnlyNonPlatformScripts_sh.xml            |  14 ---
 .../pluginTwoPlatforms_bat.xml                     |  24 ----
 .../com.plugin.withhooks/pluginTwoPlatforms_sh.xml |  24 ----
 .../projWithHooks/configOnePlatform_bat.xml        |  22 ----
 .../projWithHooks/configOnePlatform_sh.xml         |  22 ----
 .../configOnlyNonPlatformScripts_bat.xml           |  16 ---
 .../configOnlyNonPlatformScripts_sh.xml            |  16 ---
 .../projWithHooks/configTwoPlatforms_bat.xml       |  28 -----
 .../projWithHooks/configTwoPlatforms_sh.xml        |  28 -----
 src/hooks/HooksRunner.js                           |  79 ++++++-------
 14 files changed, 129 insertions(+), 318 deletions(-)

diff --git a/integration-tests/HooksRunner.spec.js b/integration-tests/HooksRunner.spec.js
index f7a89e4..be42bf6 100644
--- a/integration-tests/HooksRunner.spec.js
+++ b/integration-tests/HooksRunner.spec.js
@@ -21,12 +21,13 @@ const path = require('path');
 const fs = require('fs-extra');
 const delay = require('delay');
 const globby = require('globby');
+const et = require('elementtree');
 
 const HooksRunner = require('../src/hooks/HooksRunner');
 const cordovaUtil = require('../src/cordova/util');
 const cordova = require('../src/cordova/cordova');
 const { tmpDir, testPlatform } = require('../spec/helpers');
-const { PluginInfo } = require('cordova-common');
+const { PluginInfo, ConfigParser } = require('cordova-common');
 const { Q_chainmap } = require('../src/util/promise-util');
 
 const tmp = tmpDir('hooks_test');
@@ -131,12 +132,43 @@ describe('HooksRunner', function () {
             expect(hooksOrder).toEqual(sortedHooksOrder);
         }
 
-        function useAppConfig (name) {
-            fs.copySync(path.join(project, `config${name}_${ext}.xml`), path.join(project, 'config.xml'));
+        const BASE_HOOKS = `
+            <widget xmlns="http://www.w3.org/ns/widgets">
+                <hook type="before_build" src="scripts/appBeforeBuild1.${ext}" />
+                <hook type="before_build" src="scripts/appBeforeBuild02.js" />
+                <hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />
+            </widget>
+        `;
+        const WINDOWS_HOOKS = `
+            <widget xmlns="http://www.w3.org/ns/widgets">
+                <platform name="windows">
+                    <hook type="before_build" src="scripts/windows/appWindowsBeforeBuild.${ext}" />
+                    <hook type="before_build" src="scripts/windows/appWindowsBeforeBuild.js" />
+                    <hook type="before_plugin_install" src="scripts/windows/appWindowsBeforePluginInstall.js" />
+                </platform>
+            </widget>
+        `;
+        const ANDROID_HOOKS = `
+            <widget xmlns="http://www.w3.org/ns/widgets">
+                <platform name="android">
+                    <hook type="before_build" src="scripts/android/appAndroidBeforeBuild.${ext}" />
+                    <hook type="before_build" src="scripts/android/appAndroidBeforeBuild.js" />
+                    <hook type="before_plugin_install" src="scripts/android/appAndroidBeforePluginInstall.js" />
+                </platform>
+            </widget>
+        `;
+
+        function addHooks (hooksXml, doc) {
+            const hooks = et.parse(hooksXml);
+            for (const el of hooks.getroot().findall('./*')) {
+                doc.getroot().append(el);
+            }
         }
 
-        function usePluginConfig (name) {
-            fs.copySync(path.join(testPluginInstalledPath, `plugin${name}_${ext}.xml`), path.join(testPluginInstalledPath, 'plugin.xml'));
+        function addHooksToConfig (hooksXml) {
+            const config = new ConfigParser(path.join(project, 'config.xml'));
+            addHooks(hooksXml, config.doc);
+            config.write();
         }
 
         describe('application hooks', function () {
@@ -154,21 +186,24 @@ describe('HooksRunner', function () {
             });
 
             it('Test 006 : should execute hook scripts serially from config.xml', function () {
-                useAppConfig('OnlyNonPlatformScripts');
+                addHooksToConfig(BASE_HOOKS);
 
                 return hooksRunner.fire(test_event, hookOptions)
                     .then(checkHooksOrderFile);
             });
 
             it('Test 007 : should execute hook scripts serially from config.xml including platform scripts', function () {
-                useAppConfig('OnePlatform');
+                addHooksToConfig(BASE_HOOKS);
+                addHooksToConfig(WINDOWS_HOOKS);
 
                 return hooksRunner.fire(test_event, hookOptions)
                     .then(checkHooksOrderFile);
             });
 
             it('Test 008 : should filter hook scripts from config.xml by platform', function () {
-                useAppConfig('TwoPlatforms');
+                addHooksToConfig(BASE_HOOKS);
+                addHooksToConfig(WINDOWS_HOOKS);
+                addHooksToConfig(ANDROID_HOOKS);
                 hookOptions.cordova.platforms = ['android'];
 
                 return hooksRunner.fire(test_event, hookOptions).then(function () {
@@ -183,12 +218,64 @@ describe('HooksRunner', function () {
         });
 
         describe('plugin hooks', function () {
+            const PLUGIN_BASE_HOOKS = `
+                <widget xmlns="http://www.w3.org/ns/widgets">
+                    <hook type="before_plugin_install" src="scripts/beforeInstall01.js" />
+                    <hook type="before_plugin_install" src="scripts/beforeInstall2.js" />
+                    <hook type="before_plugin_install" src="scripts/beforeInstall.${ext}" />
+                    <hook type="before_plugin_uninstall" src="scripts/beforeUninstall.js" />
+                    <hook type="before_build" src="scripts/beforeBuild.js" />
+                    <hook type="before_build" src="scripts/beforeBuild.${ext}" />
+                </widget>
+            `;
+            const PLUGIN_WINDOWS_HOOKS = `
+                <widget xmlns="http://www.w3.org/ns/widgets">
+                    <platform name="windows">
+                        <hook type="before_plugin_install" src="scripts/windows/windowsBeforeInstall.js" />
+                        <hook type="before_build" src="scripts/windows/windowsBeforeBuild.js" />
+                    </platform>
+                </widget>
+            `;
+            const PLUGIN_ANDROID_HOOKS = `
+                <widget xmlns="http://www.w3.org/ns/widgets">
+                    <platform name="android">
+                        <hook type="before_plugin_install" src="scripts/android/androidBeforeInstall.js" />
+                        <hook type="before_build" src="scripts/android/androidBeforeBuild.js" />
+                    </platform>
+                </widget>
+            `;
+
+            function addHooksToPlugin (hooksXml) {
+                const config = new PluginInfo(testPluginInstalledPath);
+                addHooks(hooksXml, config._et);
+
+                const configPath = path.join(testPluginInstalledPath, 'plugin.xml');
+                fs.writeFileSync(configPath, config._et.write({ indent: 4 }));
+            }
+
+            it('Test 009 : should execute hook scripts serially from plugin.xml', function () {
+                addHooksToPlugin(PLUGIN_BASE_HOOKS);
+
+                return hooksRunner.fire(test_event, hookOptions)
+                    .then(checkHooksOrderFile);
+            });
+
+            it('Test 010 : should execute hook scripts serially from plugin.xml including platform scripts', function () {
+                addHooksToPlugin(PLUGIN_BASE_HOOKS);
+                addHooksToPlugin(PLUGIN_WINDOWS_HOOKS);
+
+                return hooksRunner.fire(test_event, hookOptions)
+                    .then(checkHooksOrderFile);
+            });
+
             it('Test 011 : should filter hook scripts from plugin.xml by platform', function () {
                 // Make scripts executable
                 globby.sync('scripts/**', { cwd: testPluginInstalledPath, absolute: true })
                     .forEach(f => fs.chmodSync(f, 0o755));
 
-                usePluginConfig('TwoPlatforms');
+                addHooksToPlugin(PLUGIN_BASE_HOOKS);
+                addHooksToPlugin(PLUGIN_WINDOWS_HOOKS);
+                addHooksToPlugin(PLUGIN_ANDROID_HOOKS);
                 hookOptions.cordova.platforms = ['android'];
 
                 return hooksRunner.fire(test_event, hookOptions).then(function () {
@@ -249,23 +336,6 @@ describe('HooksRunner', function () {
                             });
                     });
             }, 20 * 1000);
-        });
-
-        describe('plugin hooks', function () {
-
-            it('Test 009 : should execute hook scripts serially from plugin.xml', function () {
-                usePluginConfig('OnlyNonPlatformScripts');
-
-                return hooksRunner.fire(test_event, hookOptions)
-                    .then(checkHooksOrderFile);
-            });
-
-            it('Test 010 : should execute hook scripts serially from plugin.xml including platform scripts', function () {
-                usePluginConfig('OnePlatform');
-
-                return hooksRunner.fire(test_event, hookOptions)
-                    .then(checkHooksOrderFile);
-            });
 
             it('Test 013 : should not execute the designated hook when --nohooks option specifies the exact hook name', function () {
                 hookOptions.nohooks = ['before_build'];
diff --git a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnePlatform_bat.xml b/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnePlatform_bat.xml
deleted file mode 100644
index e1d6a0c..0000000
--- a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnePlatform_bat.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        id="com.plugin.withhooks"
-        version="0.0.1">
-    <name>Plugin with hooks</name>
-
-    <hook type="before_plugin_install" src="scripts/beforeInstall01.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall2.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall.bat" />
-    <hook type="before_plugin_uninstall" src="scripts/beforeUninstall.js" />
-    <hook type="before_build" src="scripts/beforeBuild.js" />
-    <hook type="before_build" src="scripts/beforeBuild.bat" />
-
-    <platform name="android">
-        <hook type="before_plugin_install" src="scripts/android/androidBeforeInstall.js" />
-        <hook type="before_build" src="scripts/android/androidBeforeBuild.js" />
-    </platform>
-</plugin>
\ No newline at end of file
diff --git a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnePlatform_sh.xml b/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnePlatform_sh.xml
deleted file mode 100644
index fef675a..0000000
--- a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnePlatform_sh.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        id="com.plugin.withhooks"
-        version="0.0.1">
-    <name>Plugin with hooks</name>
-
-    <hook type="before_plugin_install" src="scripts/beforeInstall01.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall2.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall.sh" />
-    <hook type="before_plugin_uninstall" src="scripts/beforeUninstall.js" />
-    <hook type="before_build" src="scripts/beforeBuild.js" />
-    <hook type="before_build" src="scripts/beforeBuild.sh" />
-
-    <platform name="android">
-        <hook type="before_plugin_install" src="scripts/android/androidBeforeInstall.js" />
-        <hook type="before_build" src="scripts/android/androidBeforeBuild.js" />
-    </platform>
-</plugin>
\ No newline at end of file
diff --git a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnlyNonPlatformScripts_bat.xml b/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnlyNonPlatformScripts_bat.xml
deleted file mode 100644
index fcbdb61..0000000
--- a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnlyNonPlatformScripts_bat.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        id="com.plugin.withhooks"
-        version="0.0.1">
-    <name>Plugin with hooks</name>
-
-    <hook type="before_plugin_install" src="scripts/beforeInstall01.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall2.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall.bat" />
-    <hook type="before_plugin_uninstall" src="scripts/beforeUninstall.js" />
-    <hook type="before_build" src="scripts/beforeBuild.js" />
-    <hook type="before_build" src="scripts/beforeBuild.bat" />
-</plugin>
\ No newline at end of file
diff --git a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnlyNonPlatformScripts_sh.xml b/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnlyNonPlatformScripts_sh.xml
deleted file mode 100644
index 7593ffe..0000000
--- a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginOnlyNonPlatformScripts_sh.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        id="com.plugin.withhooks"
-        version="0.0.1">
-    <name>Plugin with hooks</name>
-
-    <hook type="before_plugin_install" src="scripts/beforeInstall01.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall2.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall.sh" />
-    <hook type="before_plugin_uninstall" src="scripts/beforeUninstall.js" />
-    <hook type="before_build" src="scripts/beforeBuild.js" />
-    <hook type="before_build" src="scripts/beforeBuild.sh" />
-</plugin>
\ No newline at end of file
diff --git a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginTwoPlatforms_bat.xml b/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginTwoPlatforms_bat.xml
deleted file mode 100644
index 8fd6d38..0000000
--- a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginTwoPlatforms_bat.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        id="com.plugin.withhooks"
-        version="0.0.1">
-    <name>Plugin with hooks</name>
-
-    <hook type="before_plugin_install" src="scripts/beforeInstall01.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall2.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall.bat" />
-    <hook type="before_plugin_uninstall" src="scripts/beforeUninstall.js" />
-    <hook type="before_build" src="scripts/beforeBuild.js" />
-    <hook type="before_build" src="scripts/beforeBuild.bat" />
-
-    <platform name="windows">
-        <hook type="before_plugin_install" src="scripts/windows/windowsBeforeInstall.js" />
-        <hook type="before_build" src="scripts/windows/windowsBeforeBuild.js" />
-    </platform>
-
-    <platform name="android">
-        <hook type="before_plugin_install" src="scripts/android/androidBeforeInstall.js" />
-        <hook type="before_build" src="scripts/android/androidBeforeBuild.js" />
-    </platform>
-</plugin>
\ No newline at end of file
diff --git a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginTwoPlatforms_sh.xml b/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginTwoPlatforms_sh.xml
deleted file mode 100644
index 6a4e11d..0000000
--- a/spec/cordova/fixtures/plugins/com.plugin.withhooks/pluginTwoPlatforms_sh.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        id="com.plugin.withhooks"
-        version="0.0.1">
-    <name>Plugin with hooks</name>
-
-    <hook type="before_plugin_install" src="scripts/beforeInstall01.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall2.js" />
-    <hook type="before_plugin_install" src="scripts/beforeInstall.sh" />
-    <hook type="before_plugin_uninstall" src="scripts/beforeUninstall.js" />
-    <hook type="before_build" src="scripts/beforeBuild.js" />
-    <hook type="before_build" src="scripts/beforeBuild.sh" />
-
-    <platform name="windows">
-        <hook type="before_plugin_install" src="scripts/windows/windowsBeforeInstall.js" />
-        <hook type="before_build" src="scripts/windows/windowsBeforeBuild.js" />
-    </platform>
-
-    <platform name="android">
-        <hook type="before_plugin_install" src="scripts/android/androidBeforeInstall.js" />
-        <hook type="before_build" src="scripts/android/androidBeforeBuild.js" />
-    </platform>
-</plugin>
\ No newline at end of file
diff --git a/spec/cordova/fixtures/projWithHooks/configOnePlatform_bat.xml b/spec/cordova/fixtures/projWithHooks/configOnePlatform_bat.xml
deleted file mode 100644
index 6f1a691..0000000
--- a/spec/cordova/fixtures/projWithHooks/configOnePlatform_bat.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
-    <name>HelloCordova</name>
-    <description>
-        A sample Apache Cordova application that responds to the deviceready event.
-    </description>
-    <author email="dev@cordova.apache.org" href="http://cordova.io">
-        Apache Cordova Team
-    </author>
-    <content src="index.html" />
-    <access origin="*" />
-
-    <hook type="before_build" src="scripts/appBeforeBuild1.bat" />
-    <hook type="before_build" src="scripts/appBeforeBuild02.js" />
-    <hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />
-
-    <platform name="windows">
-        <hook type="before_build" src="scripts/windows/appWindowsBeforeBuild.bat" />
-        <hook type="before_build" src="scripts/windows/appWindowsBeforeBuild.js" />
-        <hook type="before_plugin_install" src="scripts/windows/appWindowsBeforePluginInstall.js" />
-    </platform>
-</widget>
\ No newline at end of file
diff --git a/spec/cordova/fixtures/projWithHooks/configOnePlatform_sh.xml b/spec/cordova/fixtures/projWithHooks/configOnePlatform_sh.xml
deleted file mode 100644
index bddcd25..0000000
--- a/spec/cordova/fixtures/projWithHooks/configOnePlatform_sh.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
-    <name>HelloCordova</name>
-    <description>
-        A sample Apache Cordova application that responds to the deviceready event.
-    </description>
-    <author email="dev@cordova.apache.org" href="http://cordova.io">
-        Apache Cordova Team
-    </author>
-    <content src="index.html" />
-    <access origin="*" />
-
-    <hook type="before_build" src="scripts/appBeforeBuild1.sh" />
-    <hook type="before_build" src="scripts/appBeforeBuild02.js" />
-    <hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />
-
-    <platform name="windows">
-        <hook type="before_build" src="scripts/windows/appWindowsBeforeBuild.sh" />
-        <hook type="before_build" src="scripts/windows/appWindowsBeforeBuild.js" />
-        <hook type="before_plugin_install" src="scripts/windows/appWindowsBeforePluginInstall.js" />
-    </platform>
-</widget>
\ No newline at end of file
diff --git a/spec/cordova/fixtures/projWithHooks/configOnlyNonPlatformScripts_bat.xml b/spec/cordova/fixtures/projWithHooks/configOnlyNonPlatformScripts_bat.xml
deleted file mode 100644
index 8ad84f6..0000000
--- a/spec/cordova/fixtures/projWithHooks/configOnlyNonPlatformScripts_bat.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
-    <name>HelloCordova</name>
-    <description>
-        A sample Apache Cordova application that responds to the deviceready event.
-    </description>
-    <author email="dev@cordova.apache.org" href="http://cordova.io">
-        Apache Cordova Team
-    </author>
-    <content src="index.html" />
-    <access origin="*" />
-
-    <hook type="before_build" src="scripts/appBeforeBuild1.bat" />
-    <hook type="before_build" src="scripts/appBeforeBuild02.js" />
-    <hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />
-</widget>
\ No newline at end of file
diff --git a/spec/cordova/fixtures/projWithHooks/configOnlyNonPlatformScripts_sh.xml b/spec/cordova/fixtures/projWithHooks/configOnlyNonPlatformScripts_sh.xml
deleted file mode 100644
index 8634f64..0000000
--- a/spec/cordova/fixtures/projWithHooks/configOnlyNonPlatformScripts_sh.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
-    <name>HelloCordova</name>
-    <description>
-        A sample Apache Cordova application that responds to the deviceready event.
-    </description>
-    <author email="dev@cordova.apache.org" href="http://cordova.io">
-        Apache Cordova Team
-    </author>
-    <content src="index.html" />
-    <access origin="*" />
-
-    <hook type="before_build" src="scripts/appBeforeBuild1.sh" />
-    <hook type="before_build" src="scripts/appBeforeBuild02.js" />
-    <hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />
-</widget>
\ No newline at end of file
diff --git a/spec/cordova/fixtures/projWithHooks/configTwoPlatforms_bat.xml b/spec/cordova/fixtures/projWithHooks/configTwoPlatforms_bat.xml
deleted file mode 100644
index 758ac70..0000000
--- a/spec/cordova/fixtures/projWithHooks/configTwoPlatforms_bat.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
-    <name>HelloCordova</name>
-    <description>
-        A sample Apache Cordova application that responds to the deviceready event.
-    </description>
-    <author email="dev@cordova.apache.org" href="http://cordova.io">
-        Apache Cordova Team
-    </author>
-    <content src="index.html" />
-    <access origin="*" />
-
-    <hook type="before_build" src="scripts/appBeforeBuild1.bat" />
-    <hook type="before_build" src="scripts/appBeforeBuild02.js" />
-    <hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />
-
-    <platform name="windows">
-        <hook type="before_build" src="scripts/windows/appWindowsBeforeBuild.bat" />
-        <hook type="before_build" src="scripts/windows/appWindowsBeforeBuild.js" />
-        <hook type="before_plugin_install" src="scripts/windows/appWindowsBeforePluginInstall.js" />
-    </platform>
-
-    <platform name="android">
-        <hook type="before_build" src="scripts/android/appAndroidBeforeBuild.bat" />
-        <hook type="before_build" src="scripts/android/appAndroidBeforeBuild.js" />
-        <hook type="before_plugin_install" src="scripts/android/appAndroidBeforePluginInstall.js" />
-    </platform>
-</widget>
\ No newline at end of file
diff --git a/spec/cordova/fixtures/projWithHooks/configTwoPlatforms_sh.xml b/spec/cordova/fixtures/projWithHooks/configTwoPlatforms_sh.xml
deleted file mode 100644
index 1175e6c..0000000
--- a/spec/cordova/fixtures/projWithHooks/configTwoPlatforms_sh.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
-    <name>HelloCordova</name>
-    <description>
-        A sample Apache Cordova application that responds to the deviceready event.
-    </description>
-    <author email="dev@cordova.apache.org" href="http://cordova.io">
-        Apache Cordova Team
-    </author>
-    <content src="index.html" />
-    <access origin="*" />
-
-    <hook type="before_build" src="scripts/appBeforeBuild1.sh" />
-    <hook type="before_build" src="scripts/appBeforeBuild02.js" />
-    <hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />
-
-    <platform name="windows">
-        <hook type="before_build" src="scripts/windows/appWindowsBeforeBuild.sh" />
-        <hook type="before_build" src="scripts/windows/appWindowsBeforeBuild.js" />
-        <hook type="before_plugin_install" src="scripts/windows/appWindowsBeforePluginInstall.js" />
-    </platform>
-
-    <platform name="android">
-        <hook type="before_build" src="scripts/android/appAndroidBeforeBuild.sh" />
-        <hook type="before_build" src="scripts/android/appAndroidBeforeBuild.js" />
-        <hook type="before_plugin_install" src="scripts/android/appAndroidBeforePluginInstall.js" />
-    </platform>
-</widget>
\ No newline at end of file
diff --git a/src/hooks/HooksRunner.js b/src/hooks/HooksRunner.js
index c124834..a42044f 100644
--- a/src/hooks/HooksRunner.js
+++ b/src/hooks/HooksRunner.js
@@ -53,14 +53,11 @@ HooksRunner.prototype.fire = function fire (hook, opts) {
     }
     opts = this.prepareOptions(opts);
 
-    var scripts = scriptsFinder.getHookScripts(hook, opts);
-
-    // execute hook event listeners first
-    return executeEventHandlersSerially(hook, opts).then(function () {
-        // then execute hook script files
-        var context = new Context(hook, opts);
-        return runScriptsSerially(scripts, context);
-    });
+    // first run hook event listeners, then run hook script files
+    return runJobsSerially([
+        ...getEventHandlerJobs(hook, opts),
+        ...getHookJobs(hook, opts)
+    ]);
 };
 
 /**
@@ -96,35 +93,27 @@ function globalFire (hook, opts) {
     }
 
     opts = opts || {};
-    return executeEventHandlersSerially(hook, opts);
+    return runJobsSerially(getEventHandlerJobs(hook, opts));
 }
 
-// Returns a promise.
-function executeEventHandlersSerially (hook, opts) {
-    var handlers = events.listeners(hook);
-    if (handlers.length) {
-        // Chain the handlers in series.
-        return handlers.reduce(function (soFar, f) {
-            return soFar.then(function () { return f(opts); });
-        }, Promise.resolve());
-    } else {
-        return Promise.resolve(); // Nothing to do.
-    }
+function getEventHandlerJobs (hook, opts) {
+    return events.listeners(hook)
+        .map(handler => () => handler(opts));
 }
 
-/**
- * Serially fires scripts either via Promise.resolve(require(pathToScript)(context)) or via child_process.spawn.
- * Returns promise.
- */
-function runScriptsSerially (scripts, context) {
+function getHookJobs (hook, opts) {
+    const scripts = scriptsFinder.getHookScripts(hook, opts);
+
     if (scripts.length === 0) {
-        events.emit('verbose', 'No scripts found for hook "' + context.hook + '".');
+        events.emit('verbose', `No scripts found for hook "${hook}".`);
     }
-    return scripts.reduce(function (prevScriptPromise, nextScript) {
-        return prevScriptPromise.then(function () {
-            return runScript(nextScript, context);
-        });
-    }, Promise.resolve());
+
+    const context = new Context(hook, opts);
+    return scripts.map(script => () => runScript(script, context));
+}
+
+function runJobsSerially (jobs) {
+    return jobs.reduce((acc, job) => acc.then(job), Promise.resolve());
 }
 
 /**
@@ -207,13 +196,18 @@ function runScriptViaChildProcessSpawn (script, context) {
         }
     }
 
-    var execOpts = { cwd: opts.projectRoot, printCommand: true, stdio: 'inherit' };
-    execOpts.env = {};
-    execOpts.env.CORDOVA_VERSION = require('../../package').version;
-    execOpts.env.CORDOVA_PLATFORMS = opts.platforms ? opts.platforms.join() : '';
-    execOpts.env.CORDOVA_PLUGINS = opts.plugins ? opts.plugins.join() : '';
-    execOpts.env.CORDOVA_HOOK = script.fullPath;
-    execOpts.env.CORDOVA_CMDLINE = process.argv.join(' ');
+    const execOpts = {
+        cwd: opts.projectRoot,
+        printCommand: true,
+        stdio: 'inherit',
+        env: {
+            CORDOVA_VERSION: require('../../package').version,
+            CORDOVA_PLATFORMS: opts.platforms ? opts.platforms.join() : '',
+            CORDOVA_PLUGINS: opts.plugins ? opts.plugins.join() : '',
+            CORDOVA_HOOK: script.fullPath,
+            CORDOVA_CMDLINE: process.argv.join(' ')
+        }
+    };
 
     return superspawn.spawn(command, args, execOpts)
         .catch(function (err) {
@@ -251,12 +245,5 @@ function isHookDisabled (opts, hook) {
     if (opts === undefined || opts.nohooks === undefined) {
         return false;
     }
-    var disabledHooks = opts.nohooks;
-    var length = disabledHooks.length;
-    for (var i = 0; i < length; i++) {
-        if (hook.match(disabledHooks[i]) !== null) {
-            return true;
-        }
-    }
-    return false;
+    return opts.nohooks.some(pattern => hook.match(pattern) !== null);
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org