Github user nikhilkh commented on a diff in the pull request: https://github.com/apache/cordova-docs/pull/489#discussion_r52085942 --- Diff: www/docs/en/dev/guide/appdev/hooks/index.md --- @@ -20,63 +20,193 @@ license: > title: Hooks Guide --- -# Hooks Guide +# Hooks + +## Introduction Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands. -Hook scripts could be defined by adding them to the special predefined folder -(`/hooks`) or via configuration files (`config.xml` and `plugin.xml`) and run -serially in the following order: - -* Application hooks from `/hooks`; -* Application hooks from `config.xml`; -* Plugin hooks from `plugins/.../plugin.xml`. -__Note__: `/hooks` directory is considered deprecated in favor of the hook elements -in config.xml and plugin.xml. - -## Supported hook types -The following hook types are supported: - - after_build - after_compile - after_clean - after_docs - after_emulate - after_platform_add - after_platform_rm - after_platform_ls - after_plugin_add - after_plugin_ls - after_plugin_rm - after_plugin_search - after_plugin_install // Plugin hooks in plugin.xml are executed for a plugin being installed only - after_prepare - after_run - after_serve - before_build - before_clean - before_compile - before_docs - before_emulate - before_platform_add - before_platform_rm/ - before_platform_ls - before_plugin_add - before_plugin_ls - before_plugin_rm - before_plugin_search/ - before_plugin_install // Plugin hooks in plugin.xml are executed for a plugin being installed only - before_plugin_uninstall // Plugin hooks in plugin.xml are executed for a plugin being uninstalled only - before_prepare - before_run - before_serve - pre_package // Windows and Windows Phone only +Cordova hooks allow you to perform special activities around cordova commands. For example, +you may have a custom tool that checks for code formatting in your javascript file. And, you +would like to run this tool before every build. In such a case, you could use a +'before_build' hook and instruct the cordova run time to run the custom tool to be invoked +before every build. + +There are 2 types of hooks: + +- Application hooks +- Plugins hooks + +### Application hooks + +These hooks are related to the application. For example, hooks such as `before_build`, +`after_build`, etc applies to your application. + +### Plugin hooks + +These hooks are related to the plugins of your application. For example, hooks such as +`before_plugin_add`, `after_plugin_add`, etc applies to plugin related activities. These +hooks can be associated with all plugins within your application or be specific to only +one plugin. + +Cordova supports the following hook types: + +<!-- START HTML --> + +<table class="hooks" width="100%"> + <thead> + <tr> + <th>Hook Type</th> + <th>Associated Cordova Command</th> + <th>Description</th> + </tr> + </thead> + <tbody> + <tr> + <th colspan="3" class="sd">Application hooks</th> + </tr> + <tr> + <th data-col="beforeplatformadd">before_platform_add</th> + <td data-col="code" rowspan="2"><code>cordova platform add</code></td> + <td rowspan="2" class="description" data-col="description">To be executed before and after adding a platform.</td> + </tr> + <tr> + <th data-col="afterplatformadd">after_platform_add</th> + </tr> + <tr> + <th data-col="beforeplatformrm">before_platform_rm</th> + <td data-col="code" rowspan="2"><code>cordova platform rm</code></td> + <td rowspan="2" class="description" data-col="description">To be executed before and after removing a platform.</td> + </tr> + <tr> + <th data-col="afterplatformrm">after_platform_rm</th> + </tr> + <tr> + <th data-col="beforeplatformls">before_platform_ls</th> + <td data-col="code" rowspan="2"><code>cordova platform ls</code></td> + <td rowspan="2" class="description" data-col="description">To be executed before and after listing the installed and available platforms.</td> + </tr> + <tr> + <th data-col="afterplatformls">after_platform_ls</th> + </tr> + <tr> + <th data-col="beforeprepare">before_prepare</th> + <td data-col="code" rowspan="2"><code>cordova prepare</code></td> + <td rowspan="2" data-col="description">To be executed before and after preparing your application.</td> + </tr> + <tr> + <th data-col="afterprepare">after_prepare</th> + </tr> + <tr> + <th data-col="beforecompile">before_compile</th> + <td data-col="code" rowspan="2"><code>cordova compile</code></td> + <td rowspan="2" data-col="description">To be executed before and after compiling your application.</td> + </tr> + <tr> + <th data-col="aftercompile">after_compile</th> + </tr> + <tr> + <th data-col="beforebuild">before_build</th> + <td data-col="code" rowspan="2"><code>cordova build</code></td> + <td rowspan="2" data-col="description">To be executed before and after building your application.</td> + </tr> + <tr> + <th data-col="afterbuild">after_build</th> + </tr> + <tr> + <th data-col="beforeemulate">before_emulate</th> + <td data-col="code" rowspan="2"><code>cordova emulate</code></td> + <td rowspan="2" data-col="description">To be executed before and after emulating your application.</td> + </tr> + <tr> + <th data-col="afteremulate">after_emulate</th> + </tr> + <tr> + <th data-col="beforerun">before_run</th> + <td data-col="code" rowspan="2"><code>cordova run</code></td> + <td rowspan="2" data-col="description">To be executed before and after running your application.</td> + </tr> + <tr> + <th data-col="afterrun">after_run</th> + </tr> + <tr> + <th data-col="beforeserve">before_serve</th> + <td data-col="code" rowspan="2"><code>cordova serve</code></td> + <td rowspan="2" data-col="description">To be executed before and after serving your application.</td> + </tr> + <tr> + <th data-col="afterserve">after_serve</th> + </tr> + <tr> + <th data-col="beforeclean">before_clean</th> + <td data-col="code" rowspan="2"><code>cordova clean</code></td> + <td rowspan="2" data-col="description">To be executed before and after cleaning your application.</td> + </tr> + <tr> + <th data-col="afterclean">after_clean</th> + </tr> + <tr> + <th data-col="prepackage">pre_package</td> + <td data-col="code">N/A</td> + <td data-col="description">Applicable to Windows 8 and Windows Phone only. This hook is deprecated.</td> + </tr> + <tr> + <th colspan="3" class="sd">Plugin hooks</th> + </tr> + <tr> + <th data-col="beforepluginadd">before_plugin_add</th> + <td data-col="code" rowspan="2"><code>cordova plugin add</code></td> + <td rowspan="2" data-col="description">To be executed before and after adding a plugin.</td> + </tr> + <tr> + <th data-col="afterpluginadd">after_plugin_add</th> + </tr> + <tr> + <th data-col="beforepluginrm">before_plugin_rm</th> + <td data-col="code" rowspan="2"><code>cordova plugin rm</code></td> + <td rowspan="2" data-col="description">To be executed before and after removing a plugin.</td> + </tr> + <tr> + <th data-col="afterpluginrm">after_plugin_rm</th> + </tr> + <tr> + <th data-col="beforepluginls">before_plugin_ls</th> + <td data-col="code" rowspan="2"><code>cordova plugin ls</code></td> + <td rowspan="2" data-col="description">To be executed before and after listing the plugins in your application.</td> + </tr> + <tr> + <th data-col="afterpluginls">after_plugin_ls</th> + </tr> + <tr> + <th data-col="beforepluginsearch">before_plugin_search</th> + <td data-col="code" rowspan="2"><code>cordova plugin search</code></td> + <td rowspan="2" data-col="description">To be executed before and after a plugin search.</td> + </tr> + <tr> + <th data-col="afterpluginsearch">after_plugin_search</th> + </tr> + <tr> + <th data-col="beforeplugininstall">before_plugin_install</th> + <td data-col="code" rowspan="2"><code>cordova plugin add</code></td> + <td rowspan="2" data-col="description">To be executed before and after installing a plugin (to the platforms).</td> + </tr> + <tr> + <th data-col="afterplugininstall">after_plugin_install</th> + </tr> + <tr> + <th data-col="beforepluginuninstall">before_plugin_uninstall</th> + <td data-col="code" rowspan="2"><code>cordova plugin rm</code></td> + <td data-col="description">To be executed before uninstalling a plugin (from the platforms).</td> + </tr> + </tbody> +</table> + +<!-- END HTML --> ## Ways to define hooks -### Via `/hooks` directory -__Note__: this method is considered deprecated in favor of the hook elements in config.xml and plugin.xml. +### Via `/hooks` directory --- End diff -- Let's not keep the deprecated option as the first way to define a hook. Also, in the title it will be great to add `(Deprecated)`
--- 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