cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carlos Santana <csantan...@gmail.com>
Subject Re: NodeJS Hooks dependencies?
Date Wed, 06 Aug 2014 21:32:43 GMT
It didn't came as negative, is just I could not help make the reference.

I don't understand the App/hook "app" and "workspace" analogy

Hook to me is some code that user want to be run by cordova command at a
certain point of the lifecycle of command.
Is source code located in the "hooks/" directory and that the user puts in
version control and he owns.

Now that I have evaluated plugin hooks, and I understand better the
implementation, plugin hooks is code that plugin developers want to be run
by cordova command at a certain point of the lifecycle of command.
the plugin hooks are deliver with the plugin and user does not need to
manage them, and don't need to check into source control is part of the
plugin.

Users can declare hooks implemented with javascript interface (.js) in
config.xml (typical location cordovaproject/hooks/)
Plugin developers can declare hooks  implemented with javascript interface
(.js) in plugin.xml (typical location within the plugin
cordovaproject/plugins/com.example.pluginid/src/hooks/)

I will help review and test the code that is there today.
There is shared code and both hooks work the same way.




On Wed, Aug 6, 2014 at 3:02 PM, Michal Mocny <mmocny@chromium.org> wrote:

> Carlos,
>
> I hope my use of "dilemma" did not come off as negative, I really did not
> mean it to.  I'm super interested in the tooling experiments you are
> running and was just trying to provide my opinions as input.
>
> RE: distinction between application hooks, and plugin hooks:
> - App/hooks/ -> application hooks
> - App/plugins/org.foo.bar/hooks -> plugin hooks [Note: not yet landed, see
> PR referenced in Carlos' email]
>
> That is the only distinction.  I don't think the hooks themselves should
> function differently.
>
> RE: treating App/hooks/ is part of the "app" and not the "workspace" --
> aka, hooks are *not* a build artefact -- it has certain implications.  E.g.
> - Should App/hooks/ be added to version control? (I think yes)
> - Should App/hooks/ affect how we do platform/plugin upgrades? (I hope no)
>
> I think that if plugins start modifying App/hooks/ then both the above
> answers change for the worse.
>
> RE: whats left for plugin hooks:  Other than reviewing & testing, I think
> making sure App hooks and plugin hooks work the same is important.  Not
> sure if others agree.  Last time I took a look at the patch it used
> plugin.xml tags instead of hooks/ directory, the way the hooks execute
> differed from app hooks, and not nearly enough code was shared, but its
> been a while since I looked.
>
> -Michal
>
>
>
> On Wed, Aug 6, 2014 at 1:39 PM, Carlos Santana <csantana23@gmail.com>
> wrote:
>
> > TLDR;
> >
> > What's else is required for Sergey to push this code [1]?
> >
> > Michal,
> >      My only dilemma is that my name is "Carlos Santana" and I don't play
> > the guitar :-p, other than that I I'm OK.
> >
> > It looks you have a clear distinction between application hooks, and
> plugin
> > hooks. Maybe this is something you can document because I'm not aware of
> > any documentation that states this design concept.
> >
> > As of today released version of Cordova, I just know about plain hooks
> that
> > by the way are not documented in our docs, just a readme file that we
> dump
> > in a folder called "hooks"
> >
> > Maybe in your mind you have clear definition that the hooks folder should
> > include only things provided by end user, anything else should not.
> > I don't disagree, just that it needs to be communicated via doc some
> where.
> >
> > Myles,
> >   I don't want user to run npm anything, just cordova commands and my
> hooks
> > code to run automatically on every prepare if a flag is passed.
> >
> > About the location of node_modules, I understand how node/npm it works
> but
> > I appreciate the clarification. I don't have an issue with that. What I
> > have a problem is about another hook depending on a node module and they
> > install the node modules in the cordova project, hook directory or a
> > hook_type directory, or even worst I install the node module that is not
> > compatible with their code and I brake them.
> > I was thinking installing them in a place with less conflicts like
> > hooks/after_prepare/worklight/node_modules but then if I have another
> hook
> > then is duplicate code again, or install in
> > plugins/mypluginid/node_modules/
> >
> >
> > Thanks all for the feedback. Now to my next option.
> >
> > I took a look at plugin hooks code [1], I thought they were only for hook
> > code to run at install and unininstall time of plugin, but it's not, its
> > better it's looks like its' what I was looking for.
> >
> > 1. Can be package with plugin ( no need to ask unser to unzip
> wl_hooks.zip)
> > 2. They can run at any lifecycle event (before_prepare, before_build)
> > 3. One script can be use for different lifecycles
> > 4. I can reuse node modules already available under cordova-lib, which I
> > don't need that many only nopt, shelljs, elementree for now
> >
> > OK I will try to implement my hooks using this pull request, if I'm
> > successful,
> >
> > What's else is required for Sergey push this code?
> >
> > [1]: https://github.com/apache/cordova-lib/pull/55
> >
> > -- Carlos
> >
> > On Tue, Aug 5, 2014 at 5:54 PM, Lorin Beer <lorin.beer@gmail.com> wrote:
> >
> > > thanks Myles, nice to see you on the list!
> > >
> > >
> > > On Tue, Aug 5, 2014 at 2:33 PM, Myles Borins <myles@famo.us> wrote:
> > >
> > > > If you have a package.json at the base of the project any
> dependencies
> > > > installed in the node_modules folder will be resolved at any depth.
> >  You
> > > > should only need to do a single install at the base of hook.  Do you
> > > have a
> > > > copy of the project I could take a peek at?
> > > >
> > > > If the cordovaUserProject itself already has a package.json you
> should
> > > > just add the dependencies in there and they will automatically be
> added
> > > to
> > > > the path when required in by the scripts (and only need to be
> installed
> > > at
> > > > the same time the user does the initial bootstrap).  If you were
> > > interested
> > > > in abstracting these scripts further it is possible to build node
> > modules
> > > > that expose binaries through the ‘bin’ key in the package json.  You
> > > would
> > > > then be able to reference these scripts directly in an npm script
> > without
> > > > specific paths, as they will be installed into ./node_modules/.bin,
> > which
> > > > is shimmed into path of an npm script.
> > > >
> > > > This would allow you to add the following to the single package.json
> > > >
> > > > scripts: {
> > > >         bootstrap: ‘prepare’,
> > > >         compile: ‘some bash script that compiles’,
> > > >         post: ‘compile’,
> > > >         build: ‘npm run bootstrap && npm run compile &&
npm run post’
> > > > }
> > > >
> > > > then in your project (or any script) you could simply run ‘npm build’
> > and
> > > > it would all work!
> > > >
> > > > Please let me know if any of that wasn’t clear.  It is worth
> mentioning
> > > > that install scripts are generally considered an anti-pattern in the
> > node
> > > > community (as it states in the docs
> > > > https://www.npmjs.org/doc/misc/npm-scripts.html).  Clever
> > concatenation
> > > > of bash scripts is considered elegant though!
> > > >
> > > > Best,
> > > >
> > > > Myles Borins
> > > >
> > > > On Aug 5, 2014, at 2:22 PM, Lorin Beer <lorin.beer@gmail.com> wrote:
> > > >
> > > > > a suggestion:
> > > > >
> > > > > as part of the hook script, have it attempt an npm install iff the
> > > > > dependencies are not present. You can hide the require calls in a
> > > > > try/catch, if caught, then run an install script in the relevant
> hook
> > > > > directories.
> > > > >
> > > > > If admin privileges are required for the install, prompt for
> > > credentials,
> > > > > or tell the user to change the directory permissions...
> > > > >
> > > > > Don't know about 'best practice', but it's light weight and doesn't
> > > force
> > > > > the user to execute an intermediate install step.
> > > > >
> > > > >
> > > > >
> > > > > On Tue, Aug 5, 2014 at 1:00 PM, Carlos Santana <
> csantana23@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
> > > > >> <csantana23@gmail.com>
> > > > >>
> > > >
> > > >
> > >
> >
> >
> >
> > --
> > Carlos Santana
> > <csantana23@gmail.com>
> >
>



-- 
Carlos Santana
<csantana23@gmail.com>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message