# @jsenv/git-hooks

> Declare git hooks in your package.json.

Latest version **1.3.3** (published 2020-02-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jsenv/git-hooks
pnpm add @jsenv/git-hooks
yarn add @jsenv/git-hooks
bun add @jsenv/git-hooks
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.3 |
| Published | 2020-02-10 |
| First published | 2020-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=12.0.0 |
| Dependencies | 2 |
| Unpacked size | 81.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | dmail, jsenv-admin |

## Links

- npm: https://www.npmjs.com/package/@jsenv/git-hooks
- Repository: https://github.com/jsenv/jsenv-git-hooks
- Homepage: https://github.com/jsenv/jsenv-git-hooks#readme
- Issues: https://github.com/jsenv/jsenv-git-hooks/issues
- npm.io page: https://npm.io/package/@jsenv/git-hooks

## Dependencies (2)

- [@jsenv/util](https://npm.io/package/@jsenv/util.md) 3.5.2
- [@jsenv/logger](https://npm.io/package/@jsenv/logger.md) 3.3.1

## Recent versions

- 1.3.3 (latest) — 2020-02-10
- 1.3.2 — 2020-02-10
- 1.3.1 — 2020-02-02
- 1.3.0 — 2020-02-02
- 1.2.0 — 2020-01-13
- 1.1.0 — 2020-01-10
- 1.0.0-alpha.1 — 2020-01-10

## README

# git-hooks

Declare git hooks in your package.json.

[![github package](https://img.shields.io/github/package-json/v/jsenv/jsenv-git-hooks.svg?logo=github&label=package)](https://github.com/jsenv/jsenv-git-hooks/packages)
[![npm package](https://img.shields.io/npm/v/@jsenv/git-hooks.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/git-hooks)
[![github ci](https://github.com/jsenv/jsenv-git-hooks/workflows/ci/badge.svg)](https://github.com/jsenv/jsenv-git-hooks/actions?workflow=ci)
[![codecov coverage](https://codecov.io/gh/jsenv/jsenv-git-hooks/branch/master/graph/badge.svg)](https://codecov.io/gh/jsenv/jsenv-git-hooks)

# Table of contents

- [Presentation](#Presentation)
- [Installation](#Installation)
- [Documentation](#Documentation)
  - [installGitHooks](#installGitHooks)
    - [projectDirectoryUrl](#projectDirectoryUrl)
    - [logLevel](#logLevel)
  - [uninstallGitHooks](#uninstallGitHooks)
- [Why](#Why)

# Presentation

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

# Installation

```console
npm install @jsenv/git-hooks@1.3.0
```

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

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

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

```js
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.

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

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

— source code at [src/installGitHooks.js](./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.

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

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

— source code at [src/uninstallGitHooks.js](./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](https://code.visualstudio.com/docs/getstarted/tips-and-tricks#_run-npm-scripts-as-tasks-from-the-explorer).

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

---
_Source: https://npm.io/package/@jsenv/git-hooks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
