Skip to content

开发规范

git提交规范conventionalcommits

  • 本项目的git提交规范遵循conventionalcommits并进行了自定义配置,具体配置规则如下
"types": [
    {
    "type": "feat",
    "section": "新功能[feat]"
    },
    {
    "type": "fix",
    "section": "Bug 修复[fix]"
    },
    {
    "type": "chore",
    "section": "其他[chore]"
    },
    {
    "type": "docs",
    "section": "文档更改[docs]"
    },
    {
    "type": "style",
    "section": "样式更改[style]"
    },
    {
    "type": "refactor",
    "section": "重构[refactor]"
    },
    {
    "type": "perf",
    "section": "性能改进[perf]"
    },
    {
    "type": "test",
    "section": "测试添加/更正[test]"
    },
    {
    "type": "revert",
    "section": "还原提交[revert]"
    },
    {
    "type": "ignore",
    "section": "需要忽略[ignore]",
    "hidden": true
    },
    {
    "type": "ci",
    "section": "CI发版[ci]"
    }
]
  • 如果使用vscode编辑器,建议安装Conventional Commits插件,此插件会自动生成对应格式提交日志

husky自动化

  1. 安装时不使用npm install直接使用npm run i ,或者初始化后在当前目录下运行npx husky install
  2. 或者在 package.json加入以下scripts再install (husky对应文档)
    //npm/pnpm
    {
         "scripts": {
             "prepare": "husky install"
         }
     }
    //yarn
     {
     "private": true, // ← your package is private, you only need postinstall
     "scripts": {
         "postinstall": "husky install"
     }
     }

会自动生成生成husky对应的git hookhusky会在git提交时进行以下操作:

  • 自动运行prettier --write进行代码格式化
  • 自动运行eslint --cache --fix进行eslint校验和修复,如果无法修复会报错并停止提交
  • 自动校验提交message是否符合conventionalcommits规范,如果不符合会报错并停止提交

husky 在linux/mac下不生效

husky目前有一个bug, windows下创建的hooks 当在linux/macos下拉取后即使执行了husky install也不能成功调用,需要单独执行下chmod ug+x .husky/* 赋予脚本执行权限。对应的issue