npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

closedinterval-git-hooks

v2.1.2

Published

Commonly used git hooks for projects

Downloads

34

Readme

closedinterval-git-hooks

Git hooks manager and pre-commit linter for projects

Installation

It's advised to install the closedinterval-git-hooks module as a devDependencies in your package.json as you only need this for development purposes. To install the module simply run:

npm install --save-dev closedinterval-git-hooks

To install it as devDependency. When this module is installed it will override the existing pre-commit, post-checkout, and post-merge file in your .git/hooks folder. Existing hooks will be backed up as *.bak file in the same folder.

To disable automatically creating links, set the environment variable NO_GITHOOK_LINKS=1

export NO_GITHOOK_LINKS=1
or
NO_GITHOOK_LINKS=1 npm install --save-dev closedinterval-git-hooks
or
NO_GITHOOK_LINKS=1 npm install

Configuration

These set of hooks will run common actions in the steps for pre-commit, post-checkout, and post-merge. Additional actions can be defined when these internal hooks run inside closedinterval-git-hooks.

Additional actions can be set up if a .git-hooks folder exists in the repository root. The .git-hooks folder is set up in the following format:

--- REPO ROOT
    --- .git/
    --- .git-hooks/
        --- pre-commit/
        --- post-checkout/
        --- post-merge/
        --- pre-commit-plugins/
            --- filetypes/
                --- file-php.js
                --- file-java.js
                --- etc.
            --- plugins/
                --- php-lint.js
                --- phpcs.js
                --- etc.
            --- pre-commit-modifier.js

Configuring pre-commit

All files within the .git-hooks/pre-commit/ directory will be run automatically. If any script fails, the following scripts will not be run and the commit will not be successful.

Setting linting rules

A .precommitrc is required for the pre-commit linter to run. It is a json formatted file in the following format. The following are the available rules built into this package.

{
  "rules": {
    "css": ["less", "csslint"],
    "less": ["less", "csslint"],
    "html": ["eslint", "jscs", "jshint"],
    "js": ["eslint", "jscs", "jshint"]
  }
}

Files can be skipped from being checked with a .precommitignore file. This file follows the same pattern as a .gitignore file, but without the starting slash /, and follows the minimatch pattern matcher. Example to ignore the node_modules directory.

bower_components/**
node_modules/**

Additional file type checks can be setup by putting a js file in .git-hooks/pre-commit-plugins/filetypes/file-EXTENSION.js that exports a function that returns a Promise and takes the parameters function (data, validators, reporter).

// Example
module.exports = function check(data, validators, reporter) {
    // data => { filename, src } // src and file to validate
    // validators => .precommitrc => rules.EXT = [] // rules found in .precommitrc
    // reporter => function(checktype, filename, line, message) // to write grouped error messages

    var filename = data.filename,
        src = data.src;

    return new Promise(function(resolve, reject) {
        if(lint(src)) {
           resolve();
        } else {
           reject();
        }
    });
};

Additional hooks can be attached to existing checked file types (css, html, js, and less) by putting files inside .git-hooks/pre-commit-plugins/plugins/CHECK.js. Each check is then loaded by including the validator in .precommitrc. The check files follows the following format which takes in function(data, reporter) and returns a Promise:

// Example
module.exports = function validator(data, reporter) {
    // data => { filename, src } // src and file to validate
    // reporter => function(checktype, filename, line, message) // to write grouped error messages

    var filename = data.filename,
        src = data.src;

    return new Promise(function(resolve, reject) {
        if(jscsOrSomething(src)) {
           resolve();
        } else {
           reject();
        }
    });
};

Configuring post-checkout

All files within the .git-hooks/post-checkout/ directory will be run automatically. If any script fails, the following scripts will not be run.

The default behavior:

  • Run npm install when the package.json file has changed.
  • Run bower install when the bower.json file has changed.

Configuring post-merge

All files within the .git-hooks/post-merge/ directory will be run automatically. If any script fails, the following scripts will not be run.

The default behavior:

  • Run npm install when the package.json file has changed.
  • Run bower install when the bower.json file has changed.

License

MIT