{"name":"git-validate","version":"1.0.2","description":"the extensible core of precommit-hook","main":"index.js","scripts":{"test":"lab -L -a code -t 100"},"repository":{"type":"git","url":"git://github.com/nlf/git-validate.git"},"keywords":["precommit","pre-commit","git","hook"],"author":{"name":"Nathan LaFreniere","email":"quitlahok@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/nlf/git-validate/issues"},"homepage":"https://github.com/nlf/git-validate","devDependencies":{"code":"1.x.x","lab":"5.x.x","mkdirp":"^0.5.0","rimraf":"2.x.x"},"gitHead":"0e660bf8d74cfbfe7f2290526132608e953d7140","_id":"git-validate@1.0.2","_shasum":"ca648b5a14886f3cb1ea092e9ae001989dede065","_from":".","_npmVersion":"2.6.1","_nodeVersion":"0.10.36","_npmUser":{"name":"nlf","email":"quitlahok@gmail.com"},"maintainers":[{"name":"nlf","email":"quitlahok@gmail.com"}],"dist":{"shasum":"ca648b5a14886f3cb1ea092e9ae001989dede065","tarball":"http://registry-npm.ywwl.com/git-validate/download/git-validate-1.0.2.tgz","integrity":"sha512-CC/X12E10Fhmf7J6cTJOCb7wDBc9ED8cLCV2k+vzpJOG1gnp7GxsYih142e6jsQHZsBmh9Dz55xAUjd/ia7tdg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCBO3c6kazpSVJBpGQnWRnuiORBMZtHBWDIK685KnWHHwIhAIeJmd8stwlHo593ZskW9bomRF/ObD04ZjLvu8GVLhSY"}],"size":7881,"noattachment":false,"key":"/git-validate/-/git-validate-1.0.2.tgz"},"directories":{},"readme":"# git-validate\n\nThis is a super simple framework to facilitate creating your own modules similar to [precommit-hook](https://github.com/nlf/precommit-hook).\n\n## Usage\n\nThis module isn't intended to be used directly in your projects (thought it can be), but rather as the dependency of a module that you create that will act as a template of sorts.\n\nTo create a validate module, first make a new directory and use `npm init` to initialize your module:\n\n```bash\nmkdir validate-nlf\ncd validate-nlf\nnpm init\n```\n\nFollow the prompts, and when complete install this module:\n\n```bash\nnpm install --save git-validate\n```\n\nNow, let's say we want to provide a default `.jshintrc` file, let's go ahead and create that file in our new directory and fill it with some options:\n\n```bash\nvim jshintrc\n```\n\n```javascript\n{\n  \"node\": true,\n\n  \"curly\": true,\n  \"latedef\": true,\n  \"quotmark\": true,\n  \"undef\": true,\n  \"unused\": true,\n  \"trailing\": true\n}\n```\n\nNote that we saved the file as `jshintrc` without the leading dot.\n\nNext, let's create our install script:\n\n```bash\nvim install.js\n```\n\n```javascript\nvar Validate = require('git-validate');\n\nValidate.copy('jshintrc', '.jshintrc');\n```\n\nThis instructs **git-validate** to copy the `jshintrc` file in our module to `.jshintrc` in the root of the project that installs it.\n\nNow we edit our `package.json` to tell it about our install script:\n\n```javascript\n  \"scripts\": {\n    \"install\": \"node install.js\"\n  }\n```\n\nAnd that's it for the simplest possible example. Now anytime you install `validate-nlf` you'll automatically get a `.jshintrc` file in your project.\n\nThis wouldn't be any fun without the git hooks though, so let's extend it a bit further to make sure that `jshint` is run any time a user tries to `git commit` after installing our module. We can do that by configuring the hook in our install script like so:\n\n```javascript\nValidate.installScript('lint', 'jshint .');\nValidate.configureHook('pre-commit', ['lint']);\n```\n\nGreat, that's it!\n\nNow when a user installs your package the `installScript` method will see if they already have a script in their package.json named `lint`, if they do not it will add one that runs `\"jshint .\"`. The second line will also check their package.json for a `pre-commit` key, which is used to configure that specific git hook. If the key does not exist, it will be added with the value `[\"lint\"]` telling git-validate to run the \"lint\" script on `pre-commit`.\n\n\n## The Details\n\n**git-validate** exports a few methods to be used for creating your custom hooks.\n\n### `copy`\n\nCopy a file or directory from your hook to a target project.\n\n```javascript\nValidate.copy(source, target, options);\n```\n\nWhere `source` is a path relative to your install script, and `target` is a path relative to the root of the project that is installing the module. For example if my module has the layout:\n\n```\nbin/install\njshintrc\n```\n\nAnd I wish for the file `jshintrc` to be placed in the root of projects as `.jshintrc` when running `bin/install`, I would call `Validate.copy('../jshintrc', '.jshintrc')`.\n\nNote that `source` may be a file *or* a directory. If a directory is specified than a new directory will be created at `target` and the *full contents* of source will be copied to the `target` directory recursively.\n\nThe only `option` currently available is `overwrite`. When set to `true` overwrite will *always* copy the given file, overwriting any existing destination file. If this is not set, `copy` will instead silently fail and leave the old file in place.\n\n\n### `installHooks`\n\nInstall one or more git hooks to the current repo.\n\n```javascript\nValidate.installHooks('pre-commit');\nValidate.installHooks(['pre-commit', 'pre-push']);\n```\n\nThis method will copy the hook script to the appropriate path in your repo's `.git/hooks` path.\n\n### `configureHook`\n\nProvide a default configuration for a given hook.\n\n```javascript\nValidate.configureHook('pre-commit', ['lint', 'test']);\n```\n\nwould write\n\n```javascript\n{\n  \"pre-commit\": [\"lint\", \"test\"]\n}\n```\n\nto your package.json, but *only* if the `\"pre-commit\"` key was not already set, or you specify so explicitly:\n\n```javascript\n{\n  \"pre-commit\": [\"test\"]\n}\n```\n\nwith:\n\n```javascript\nvar overwrite = true;\nValidate.configureHook('pre-commit', ['lint', 'test'], overwrite);\n```\n\nwould change package.json to:\n\n```javascript\n{\n  \"pre-commit\": [\"lint\", \"test\"]\n}\n```\n\n\n### `installScript`\n\nConfigure a script (if it is not already configured) for the project via package.json.\n\n```javascript\nValidate.installScript('test', 'lab -a code');\n```\n\nwould write\n\n```javascript\n{\n  \"scripts\": {\n    \"test\": \"lab -a code\"\n  }\n}\n```\n\nto your package.json. If the `\"test\"` script was already defined, this method will do nothing.\n\n\n## Configuration\n\nIn addition to the `scripts` property, your package.json file will be parsed and checked for keys matching the name of your git hooks (e.g. `pre-commit`, `pre-push`, etc) and used to provide a list of hooks to be run for each hook. The keys must be an array of script names to be run. If any of the scripts are not defined, they will be skipped and a message will be printed showing that no script was found.\n\n### per-branch hooks\n\nIt is possible to run scripts only for a specific branch by specifying the key in your `package.json` as `hook-name#branch`:\n\n```javascript\n{\n  \"pre-commit\": [\"lint\", \"test\"],\n  \"pre-commit#dev\": [\"lint\"]\n}\n```\n\nIn the above example, when run in the `dev` branch only the `lint` script will be run, however in all other branches both `lint` and `test` will be run.\n","publish_time":1426697332683,"_cnpm_publish_time":1426697332683,"dist-tags":{"latest":"2.2.4"}}