Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

jsenv/jsenv-git-hooks

Repository files navigation

git-hooks

Declare git hooks in your package.json.

github package npm package github ci codecov coverage

Table of contents

Presentation

@jsenv/git-hooks create a git hook for every scripts your package.json matching git-hook-*.

Installation

npm install @jsenv/git-hooks@1.3.0
import { installGitHooks } from "@jsenv/git-hooks"

installGitHooks({
  projectDirectoryUrl: "file:///directory",
})

If you use node < 13 you can use the commonjs export.

const { installGitHooks } = require("@jsenv/git-hooks")

Documentation

installGitHooks

installGitHooks is an async function writing a hook file for every git hook script declared in a project package.json.

import { installGitHooks } from "@jsenv/git-hooks"

await installGitHooks({
  projectDirectoryUrl: "file:///directory",
  logLevel: "info",
})

— source code at src/installGitHooks.js.

projectDirectoryUrl

projectDirectoryUrl parameter is a string leading to a directory as documented in https://github.com/jsenv/jsenv-util#assertandnormalizedirectoryurl. It is used to locate your package.json and the directory where git hooks will be written.

logLevel

logLevel parameter is a string controlling the verbosity of logs during function exectuion as documented in https://github.com/jsenv/jsenv-logger#logLevel.

uninstallGitHooks

uninstallGitHooks is an async function removing all git hooks installed by installGitHooks.

import { uninstallGitHooks } from "@jsenv/git-hooks"

await uninstallGitHooks({
  projectDirectoryUrl: "file:///directory",
  logLevel: "info",
})

— source code at src/uninstallGitHooks.js.

Why

I wanted a git precommit hook to run prettier on staged files as documented in https://prettier.io/docs/en/precommit.html.

I wanted to declare my hooks in package.json script to benefit from vscode script explorer feature, see npm.enableScriptExplorer.

After that I discovered husky, https://github.com/typicode/husky, which could do the job but they have deprecated declaring hooks inside scripts field.

About

Install git hooks from package.json.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published