[
https://issues.apache.org/jira/browse/CB-10353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15157799#comment-15157799
]
ASF GitHub Bot commented on CB-10353:
-------------------------------------
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
> Make Hooks guide a reference
> ----------------------------
>
> Key: CB-10353
> URL: https://issues.apache.org/jira/browse/CB-10353
> Project: Apache Cordova
> Issue Type: Task
> Components: Docs
> Reporter: Raghav
> Assignee: Sarangan Rajamanickam
> Labels: Docs-6.x
>
> Hooks guide
> (https://cordova.apache.org/docs/en/latest/guide/appdev/hooks/index.html)
> needs to be modified as per the reference structure.
> General guidelines:
> - While giving examples, keep them short. Do not repeat for all
> plugins/platforms.
> - Remove all references to cordova plugin registry.
> - Remove Tizen references. The platform is deprecated
> (http://markmail.org/message/hryg6sjswecpgndu)
> - Keep information up to date for the platforms, CLI and plugins
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]