Skip to content

Commit

Permalink
docs: wording and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Dec 11, 2020
1 parent 9440e8e commit c4e1ed1
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions docs/README.md
Expand Up @@ -66,10 +66,10 @@ yarn husky install

## Add a hook

To add a hook, you can use `husky add <hookname> [cmd]` (don't forget to run `husky install` before).
To add a hook, you can use `husky add <file> [cmd]` (don't forget to run `husky install` before).

```shell
npx husky add pre-commit "npm test" # will create .husky/pre-commit file
npx husky add .husky/pre-commit "npm test"
```

Try to make a commit
Expand Down Expand Up @@ -107,7 +107,7 @@ By design, `husky install` must be run in the same directory as `.git`, but you
// package.json
{
"scripts": {
"postinstall": "cd .. && husky install ./front/.husky"
"postinstall": "cd .. && husky install front/.husky"
}
}
```
Expand All @@ -117,7 +117,7 @@ In your hooks, you'll also need to change directory:
```shell
# .husky/pre-commit
# ...
cd ./front
cd front
npm test
```

Expand All @@ -144,7 +144,7 @@ Alternatively, most Continuous Integration Servers set a `CI` environment variab
```shell
# .husky/pre-commit
# ...
[ -z "$CI" ] && exit 0
[ -n "$CI" ] && exit 0
```

You can also use [is-ci](https://github.com/watson/is-ci) in your `postinstall` script to conditionnally install husky
Expand Down Expand Up @@ -224,73 +224,63 @@ Environment variables:

# Migrate from v4 to v5

## Package scripts (i.e. npm test, ...)
## Package scripts

If you were calling `package.json` scripts, you don't have to make particular changes.

`v4`
If you were calling `package.json` scripts using `npm` or `yarn`, **you can simply copy your commands**:

```js
// .huskyrc.json
// .huskyrc.json (v4)
{
"hooks": {
"pre-commit": "npm test && npm run foo"
}
}
```

`v5`

```shell
# .husky/pre-commit
# .husky/pre-commit (v5)
# ...
npm test
npm run foo
```

## Locally installed tools (i.e. jest, eslint, ...)
## Locally installed binaries

`v4`
If you were calling directly locally installed binaries, **you need to run them via your package manager**:

```js
// .huskyrc.json
// .huskyrc.json (v4)
{
"hooks": {
"pre-commit": "jest"
}
}
```

`v5`

```shell
# .husky/pre-commit
# .husky/pre-commit (v5)
# ...
npx --no-install jest
# or
yarn jest
```

## HUSKY_GIT_PARAMS (i.e. commitlint, ...)

`v4`
Previous `HUSKY_GIT_PARAMS` environment variable is replaced by native params `$1`, `$2`, etc.

```js
// .huskyrc.json
// .huskyrc.json (v4)
{
"hooks": {
"pre-commit": "commitlint -E HUSKY_GIT_PARAMS"
}
}
```

`v5`

```shell
# .husky/pre-commit
# .husky/pre-commit (v5)
# ...
npx --no-install commitlint --edit $1
# or
yarn commitlint --edit $1
```

Expand Down

0 comments on commit c4e1ed1

Please sign in to comment.