Github user sarangan12 commented on a diff in the pull request: https://github.com/apache/cordova-docs/pull/489#discussion_r53701491 --- Diff: www/docs/en/dev/guide/appdev/hooks/index.md --- @@ -178,30 +326,44 @@ 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'); ``` -__Note__: new module loader script interface is used for the `.js` files defined via `config.xml` or `plugin.xml` only. +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) --- End diff -- Done
--- 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