不知道是不是node版本问题或者vue版本问题,网上的查了几十篇没有一个能成功的,好不容易琢磨出来了正确思路,凭着记忆大概记录了一下
commitizen
-
npm install -g commitizen
-
npm install -D commitizen cz-conventional-changelog
网上有提到commitizen init cz-conventional-changelog --save-dev --save-exact
但输入会显示让用npm包初始化
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
}
经过尝试,这一步可有可无
git cz
? Select the type of change that you're committing: (Use arrow keys)
> feat: A new feature
fix: A bug fix
docs: Documentation only changes
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
refactor: A code change that neither fixes a bug nor adds a feature
perf: A code change that improves performance
test: Adding missing tests or correcting existing tests
(Move up and down to reveal more choices)
如果这一步不能出现,就反反复复安装commitizen,一样的代码我执行了两遍才安装成功
conmmitlint
-
npm install -g @commitlint/cli @commitlint/config-conventional
-
npx husky-init
安装husky,此步会出现新的.husky文件夹,并生成一个pre-commit的文件(示例挂钩),内容是“npm test”,意思是在提交之前自动执行"npm test"命令,可以修改成自己想要执行的命令,多个命令之间使用 && 分隔
我写的是,代码美化和eslint
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run lint &&npm run format
- 添加commit-msg钩子,验证git commit的message是否符合commitlint的规范
这一步会出现commit-msg的文件
- Husky 添加一个 Hook
npx husky add .husky/pre-commit “npm run lint”
- 然后在根目录创建配置文件 .commitlintrc.cjs,而不是别的博客说的cofig.js,亲测无效
module.exports = {
extends: [“@commitlint/config-conventional”],
};
- 然后把 commitlint 命令也添加 Husky Hook。运行命令:
npx husky add .husky/commit-msg "npx --no-install commitlint -e $HUSKY_GIT_PARAMS"
最后基本才算配置完毕
git commit -m ‘foo: test’测试