1.3.3 • Published 4 years ago

@jsenv/git-hooks v1.3.3

Weekly downloads
14
License
MIT
Repository
github
Last release
4 years ago

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.

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0-alpha.1

4 years ago