Github user riknoll commented on a diff in the pull request: https://github.com/apache/cordova-docs/pull/489#discussion_r52080114 --- Diff: www/docs/en/dev/guide/appdev/hooks/index.md --- @@ -178,28 +307,51 @@ module.exports = function(context) { `context.opts.plugin` object will only be passed to plugin hooks scripts. You can also require additional Cordova modules in your script using `context.requireCordovaModule` in the following way: + ```javascript var Q = context.requireCordovaModule('q'); ``` +You can make your scipts async using Q: + +```javascript +module.exports = function(context) { + var Q = context.requireCordovaModule('q'); + var deferral = new Q.defer(); + + setTimeout(function(){ + console.log('hook.js>> end'); + deferral.resolve(); + }, 1000); + + return deferral.promise; +} +``` + + + __Note__: new module loader script interface is used for the `.js` files defined via `config.xml` or `plugin.xml` only. For compatibility reasons hook files specified via `/hooks` folders are run via Node child_process spawn, see 'Non-javascript' section below. ### Non-javascript -__Note__: we highly recommend writing your hooks using Node.js so that they are cross-platform, see 'Javascript' section above. - Non-javascript scripts are run via Node child_process spawn from the project's root directory and have the root directory passes as the first argument. All other options are passed to the script using environment variables: -* CORDOVA_VERSION - The version of the Cordova-CLI. -* CORDOVA_PLATFORMS - Comma separated list of platforms that the command applies to (e.g.: android, ios). -* CORDOVA_PLUGINS - Comma separated list of plugin IDs that the command applies to (e.g.: org.apache.cordova.file, org.apache.cordova.file-transfer) -* CORDOVA_HOOK - Path to the hook that is being executed. -* CORDOVA_CMDLINE - The exact command-line arguments passed to cordova (e.g.: cordova run ios --emulate) +Environment Variable Name | Description +------------------------------|-------------------------------------------- +CORDOVA_VERSION | The version of the Cordova-CLI. +CORDOVA_PLATFORMS | Comma separated list of platforms that the command applies to (e.g.: android, ios). +CORDOVA_PLUGINS | Comma separated list of plugin IDs that the command applies to (e.g.: cordova-plugin-file-transfer, cordova-plugin-file) +CORDOVA_HOOK | Path to the hook that is being executed. +CORDOVA_CMDLINE | The exact command-line arguments passed to cordova (e.g.: cordova run ios --emulate) If a script returns a non-zero exit code, then the parent cordova command will be aborted. -Also, note that even if you are working on Windows, and in case your hook scripts aren't bat files (which is recommended, if you want your scripts to work in non-Windows operating systems) Cordova CLI will expect a shebang line as the first line for it to know the interpreter it needs to use to launch the script. The shebang line should match the following example: +__Note__: we highly recommend writing your hooks using Node.js so that they are cross-platform, see [Javascript](#link-javascript) section above. + +#### Windows Quirks + +If you are working on Windows, and in case your hook scripts aren't bat files (which is recommended, if you want your scripts to work in non-Windows operating systems) Cordova CLI will expect a shebang line as the first line for it to know the interpreter it needs to use to launch the script. The shebang line should match the following example: --- End diff -- This sentence reads awkwardly and should be rephrased.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org For additional commands, e-mail: dev-h...@cordova.apache.org