From 2917a94b2c14412d3e64809af4a6ef1783433134 Mon Sep 17 00:00:00 2001 From: typicode Date: Fri, 2 Jul 2021 02:33:01 +0200 Subject: [PATCH] docs: update Docker section --- docs/README.md | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/docs/README.md b/docs/README.md index 85dff6035..cf1b835d4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -244,12 +244,25 @@ HUSKY=0 git push # yolo! ## Disable husky in CI/Docker +There's no right or wrong way to disable husky in CI/Docker context and it's highly dependent on your use-case. + +### With npm + If you want to prevent husky from installing completely ```shell npm ci --only=production --ignore-scripts ``` +Alternatively, you can specifically disable `prepare` script with + +```shell +npm set-script prepare "" +npm ci --only-production +``` + +### With env variables + You can set `HUSKY` environment variable to `0` in your CI config file, to disable all hooks. Alternatively, most Continuous Integration Servers set a `CI` environment variable. You can use it in your hooks to detect if it's running in a CI. @@ -260,6 +273,8 @@ Alternatively, most Continuous Integration Servers set a `CI` environment variab [ -n "$CI" ] && exit 0 ``` +### With is-ci + You can also use [is-ci](https://github.com/watson/is-ci) in your `prepare` script to conditionally install husky ```shell @@ -304,27 +319,6 @@ To **revert** the git-flow hooks directory back to its default you need to reset git config gitflow.path.hooks .git/hooks ``` -## Sharing hooks - -Most of the time, a better approach is to create shareable configs for the tools you're using. However if you need to share hook scripts using npm, you can do so this way: - -``` -// my-husky-scripts/index.js -module.exports = { - 'pre-commit': 'echo hello' -} -``` - -``` -npm install my-husky-scripts --save-dev -``` - -```sh -# .husky/pre-commit -# ... -eval "$(node -p "require('my-husky-scripts')['pre-commit']")" -``` - # FAQ ## Does it work on Windows?