Skip to content

规范提交

git commit 规范

husky

shell
pnpm add --save-dev husky
pnpm exec husky init

pnpm add commitizen cz-customizable commitlint-config-cz @commitlint/cli commitlint-config-git-commit-emoji commitlint-config-cz conventional-changelog-cli conventional-changelog-gitmoji-config -D

commit-msg

shell
echo "Running commitlint..."
pnpm dlx commitlint --edit $1

package.json 配置

json
{
  "scripts": {
    "commit": "git add . &&  cz",
    "changelog": "conventional-changelog -p gitmoji-config -i CHANGELOG.md -s"
  },
  "config": {
    "commitizen": {
      "path": "node_modules/cz-customizable"
    },
    "cz-customizable": {
      "config": ".cz-config.cjs"
    }
  }
}

.cz-config.cjs 配置

js
const path = require('path');

// 读取apps和packages目录下所有的文件夹

const apps = require('fs').readdirSync(path.resolve(__dirname, 'apps'));

const packages = require('fs').readdirSync(path.resolve(__dirname, 'packages'));

const scopes = ['global', ...apps, ...packages].map((item) => ({
    name: item,
}));

module.exports = {
    types: [
        {
            value: ':sparkles: feat',
            name: '✨ feat:  新功能',
        },
        {
            value: ':construction: feat',
            name: '🚧 construction:  开发中',
        },
        {
            value: ':bug: fix',
            name: '🐛 fix:  修复 bug',
        },
        {
            value: ':memo: docs',
            name: '📝 docs:  文档变更',
        },
        {
            value: ':lipstick: style',
            name: '💄 style:  样式美化',
        },
        {
            value: ':hammer: refactor',
            name: '🔨 refactor:  重构',
        },
        {
            value: ':zap: perf',
            name: '⚡️ perf:  优化',
        },
        {
            value: ':white_check_mark: test',
            name: '✅ test:  测试',
        },
        {
            value: ':rewind: revert',
            name: '⏪ revert:  回退',
        },
        {
            value: ':twisted_rightwards_arrows: revert',
            name: '🔀 merge:  分支合并',
        },
        {
            value: ':package: build',
            name: '📦️ build:  打包',
        },
        {
            value: ':wrench: chore',
            name: '🔧 chore:  构建/工程依赖/工具',
        },
        {
            value: ':tada: init',
            name: '🎉 init:  初始化',
        },
    ],
    messages: {
        type: '选择一种你的提交类型:',
        customScope: '表示该变更的范围:',
        subject: '短说明:\n',
        body: '长说明,使用"|"换行(可选):\n',
        breaking: '非兼容性说明 (可选):\n',
        footer: '关联关闭的issue,例如:#31, #34(可选):\n',
        confirmCommit: '确定提交说明? yes/no',
    },
    scopes,
    allowCustomScopes: true,
    allowBreakingChanges: [':sparkles: feat', ':bug: fix'],
    skipQuestions: ['body', 'footer'],
    subjectLimit: 72,
};

commitlint.config.js 配置

js
export default { extends: ['git-commit-emoji', 'cz'] };

## lint-stage