Skip to content

Instantly share code, notes, and snippets.

@ilmsg
Forked from domenic/README.md
Created September 7, 2013 03:34
Show Gist options
  • Save ilmsg/6472632 to your computer and use it in GitHub Desktop.
Save ilmsg/6472632 to your computer and use it in GitHub Desktop.

Here's how this works:

  • Include a git_hooks/ directory in your project, with these two files (plus other hooks if you want, written in a similar style).
  • Add "npm" to your devDependencies in package.json, so that the pre-commit hook can do its magic.
  • Add test and lint scripts to your package.json, e.g.
    "scripts": {
        "test": "mocha",
        "lint": "jshint ./lib --show-non-errors"
    }
  • Whenever you clone the repository, run node git_hooks/link.js to symlink the hooks stored in the repository, in git_hooks, to the hidden .git/hooks directory.
#!/usr/bin/env node
var npm = require("npm");
npm.load(function (err) {
if (err) {
throw err;
}
npm.commands.test(function (err) {
if (err) {
process.exit(1);
}
npm.commands["run-script"](["lint"], function (err) {
if (err) {
process.exit(1);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment