Site Overlay

基础设施 — git提交前的校验

主要 npm 包

  1. husky(增强的git hook工具,在各个阶段执行在package.json 中配置好的 npm script)
  2. lint-staged(用于实现每次提交只检查本次提交所修改的文件)
  3. commitlint(提交验证工具)
    • @commitlint/cli
    • @commitlint/config-conventional

新版husky的工作原理

新功能 core.hooksPath(只添加需要的 git hook,存在 .husky/目录下)

  1. 在 scripts 下添加 npm script
{
  "scripts": {
    "prepare": "husky install"
  }
}
  1. 执行prepare脚本(npm run prepare
  2. 添加pre-commit脚本(npx husky add .husky/pre-commit "npm run pre-commit"
  3. 添加commit-msg脚本(npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
  4. 在 scripts 下添加 npm script
{
  "scripts": {
    "pre-commit": "lint-staged",
  }
}
  1. 根据eslint配置lint-staged
  2. commitlint.config.js文件中配置git提交message