Few comments first:
- The solution may be different for top-level and plugin hooks.  This
question seems to ask about application hooks.
- I consider top-level hooks to belong to the application, to be versioned
alongside www/, and should not be modified by cordova tooling (I think
Carlos disagrees here, and so his opinions may differ from mine) (also for
the record, cca current breaks this rule. We write application hooks, but
have a bug open to fix that since it has come up as a problem).

Okay, so with that said, I think that application hooks/ should just use
the top level node_modules, aka "cordovaUserProject/node_modules/", but its
really up to each user.  Since I think tooling shouldn't write hooks, and
since we don't currently have a "hooks registry", hooks are just what users
make of them / find online.

If you have a tool that writes hooks, it should probably also set up
the dependencies.  If I'm correct, Carlos, your dilemma comes because you
are writing plugins to install top-level hooks?  In that case, perhaps you
can (ab)use after_plugin_add to automatically run global "npm install" on
the hook during plugin install?  Not sure.

I'd prefer to just land plugin hooks, and then you can publish those with
node_modules bundled.

-Michal


On Tue, Aug 5, 2014 at 4:00 PM, Carlos Santana <csantan...@gmail.com> wrote:

> I'm writing new cordova hooks, and decided to do them in nodejs
>
> First problem I hit was dependencies for the hook scripts:
> so far I have two scripts:
> cordovaUserProject/hook/before_prepare/wl_b_prepare.js
> cordovaUserProject/hook/after_compile/wl_a_compile.js
>
> I have both starting like this:
> #!/usr/bin/env node
>
> var shell = require('shelljs'),
> nopt  = require('nopt');
>
> shell.echo('Running Worklight Cordova Hook');
>
>
> I get errors because it can't find dependencies 'shelljs' and 'nopt'
>
> To resolve this I would need the user or another hook before this one to
> install the node_modules in one of these places
>
> cordovaUserProject/node_modules/
> cordovaUserProject/hook/node_modules/
> cordovaUserProject/hook/before_prepare/node_modules/
> cordovaUserProject/hook/after_compile/node_modules/
>
> What would be a best practice?
> Who get's to install? (user or me)
> Where to install?
>
>
>
> --
> Carlos Santana
> <csantan...@gmail.com>
>

Reply via email to