Skip to content

Commit

Permalink
docs(husky): add desc of Husky doc
Browse files Browse the repository at this point in the history
  • Loading branch information
chandq committed Oct 25, 2023
1 parent 6829dc6 commit 0fcc33d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
38 changes: 31 additions & 7 deletions docs/husky.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Config for new husky

husky `v6.0`包含`break change`, 该文仅包含husky v8.x的安装配置,从v4.x迁移请参考 [Migrating from v4](https://typicode.github.io/husky/migrating-from-v4.html)

## 1. Install husky, lint-staged

```bash
Expand All @@ -9,7 +11,7 @@ npm install husky lint-staged --save-dev
## 2. 自动启用 husky

```bash
npm pkg set scripts.prepare="husky install"
npm pkg set scripts.prepare="husky install" && npm run prepare
```

## 3. Add commit-msg hook
Expand All @@ -29,9 +31,7 @@ npm install --save-dev @commitlint/cli @commitlint/config-conventional
在根目录新建一个`commitlint.config.js`文件并加入如下内容:

```js
module.exports = {
extends: ['@commitlint/config-conventional']
};
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js
```

## 5. add pre-commit hook
Expand All @@ -40,15 +40,15 @@ module.exports = {
npx husky add .husky/pre-commit "npx lint-staged"
```

### 添加交互式git commit配置
## 添加交互式git commit配置

1. install commitizen
#### 1. install commitizen

```bash
npm install --save-dev commitizen
```

2. 初始化
#### 2. 初始化

```bash
npx commitizen init cz-conventional-changelog
Expand All @@ -69,3 +69,27 @@ npx commitizen init cz-conventional-changelog
```bash
npx git-cz
```

#### 3. 配置cz的命令

```bash
npm pkg set scripts.commit="git-cz"
```

## lint-staged的配置示例

在package.json中添加关于 `ts、tsx、js、jsx、vue、css、json、md`等代码的lint、prettier配置

```json
"lint-staged": {
"*.[tj]s?(x)": [
"eslint --fix"
],
"*.vue": [
"eslint --fix"
],
"*.{css,less,scss,json,md}": [
"prettier --write"
]
}
```
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"prettier": "prettier -c --write \"**/*.{vue,ts,js,jsx,css,less,scss,json}\"",
"release:patch": "standard-version --release-as patch",
"release:minor": "standard-version --release-as minor",
"release:major": "standard-version --release-as major"
"release:major": "standard-version --release-as major",
"commit": "git-cz"
},
"author": "chendq <[email protected]>",
"main": "lib/cjs/index.js",
Expand Down

0 comments on commit 0fcc33d

Please sign in to comment.