Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-6481 adds plugin level hooks support #12

Closed
wants to merge 1 commit into from
Closed

CB-6481 adds plugin level hooks support #12

wants to merge 1 commit into from

Conversation

sgrebnov
Copy link
Member

1.Support of js hook files (nodejs is used to run script file)

2.Support of the following hook types

  • beforeinstall/preinstall – run before plugin is installed
  • install/postinstall/afterinstall – run after plugin is installed
  • uninstall – run after plugin is uninstalled
<script type="postinstall" src="scripts/postinstall.js" />
<script type="preinstall" src="scripts/preinstall.js" />
<script type="install" src="scripts/install.js" />

3.Use context argument to retrieve execution parameters inside hook function

module.exports = function(context) {
    console.log('hook.js>> platform: ' + context.platform);
    console.log('hook.js>> projectDir: ' + context.projectDir);
    console.log('hook.js>> pluginDir: ' + context.pluginDir);
    console.log('hook.js>> cmdLine: ' + context.cmdLine);

    var deferral = new Q.defer();

    setTimeout(function(){
        deferral.resolve();
    }, 1000);

    return deferral.promise;
}

var pendingScripts = [],
me = this;

scripts.forEach(function(script){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use scripts.slice(0) here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, updated

@mmocny
Copy link
Contributor

mmocny commented May 20, 2014

Did a quick pass and ran some tests locally. I haven't reviewed the patch thoroughly, yet. Notes:

  • Using Q works for me for all the install hooks, but not for the uninstall hook.. odd! Its also odd that Q is used without requireing it, since if you try to require it you get module not found.
  • Why do we support both pre_/post_ and before_/after_ versions?
  • Why don't we support before/after for uninstall?
  • Why have an "install" hook that is == afterinstall?!
  • To be consistent with the CLI hooks, I suggest: before_plugin_install, after_plugin_install, before_plugin_uninstall, after_plugin_uninstall
  • I cannot require('cordova'). Not sure exactly how to approach this problem, but I would like to at least be able to run cordova commands from these hooks, like the node equivalent of cordova plugin ls.
  • Why are we specifying hooks in plugin.xml instead of using a hooks/ folder? This seems quite opposite of the CLI, and I'm not sure why. If you want hooks to run only for a specific platform, you can use the provided context to early exit, instead of using <platform> tags.

Finally, I'd love to see plugin hooks share a common module with CLI application hooks. Right now the CLI hooks look rather tightly coupled with the CLI application structure, but we could break that up to have common modules for:

  • mapping a hook by-name to a set of node scripts to run
  • running hooks, passing an appropriate context, preferences, and environment setup

@sgrebnov
Copy link
Member Author

sgrebnov commented Jul 1, 2014

New plugin hooks implementation is coming...closing this one

@sgrebnov sgrebnov closed this Jul 1, 2014
@sgrebnov sgrebnov deleted the plugin-hooks branch April 16, 2015 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants