hook-scripts
Add git-style hooks to your node project.
Install
npm install hook-scripts
Example usage
var hooks = ; ;
API
By default, hook-scripts will look for a hooks
folder in the current
working directory (process.cwd()
). You can override this behavior by
parsing in a path to a different directory upon initialization:
var hooks = '/path/to/hooks';
It's expected that the hook names map to filenames inside the hooks directory.
You can parse in arguments to the hook script using an optional 2nd argument when registering the hook:
;
And you can even set custom environment variables:
;
Initialize
An initializer is returned when requireing hook-scripts
. It takes one
optional argument which can either be a string or an options hash.
dir || options;
The string is just a shorthand for parsing in { dir: string }
.
The full list of options are:
dir
- The directory in which to look for the hook scriptscwd
- The working directory in which to run the hook scripts (defaults toprocess.cwd()
)env
- Environment key-value pairsoverrides
- An optional hash of hook script overrides (see the Advanced section below)
Example hooks
The hooks can be written in any language that you prefer. Just make sure they are executable and include a hashbang in the top of the script.
Here are some examples in various languages:
Bash
#!/usr/bin/env bash echo 'Hello World'
Node.js
#!/usr/bin/env node console;
Ruby
#!/usr/bin/env ruby puts 'Hello World'
Advanced
Overrides
Using the initialization option overrides
it's possible to override
individual hooks:
var hooks = overrides: foo: 'echo bar' ; // will run `echo bar` instead of looking for a script named foo;
License
MIT