@tembty/commitlint-config

1.0.0 • Public • Published

@tembty/commitlint-config

Git 规范(Commitlint 可共享配置),用于对 git commit message 进行校验。

安装

npm install @tembty/commitlint-config --save-dev

or

yarn add @tembty/commitlint-config --dev

使用

// .commitlintrc.js
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

const scopes = fs
  .readdirSync(path.resolve(__dirname, 'src'), { withFileTypes: true })
  .filter((dirent) => dirent.isDirectory())
  .map((dirent) => dirent.name);

// precomputed scope
const scopeComplete = execSync('git status --porcelain || true')
  .toString()
  .trim()
  .split('\n')
  .find((r) => r.indexOf('M  ') !== -1)
  ?.replace(/(\/)/g, '%%')
  ?.match(/src%%((\w|-)*)/)?.[1];

module.exports = {
  extends: ['@midea-infra'],
  prompt: {
    customScopesAlign: !scopeComplete ? 'top-bottom' : 'bottom',
    defaultScope: scopeComplete,
    scopes: [...scopes],
  },
};

设置 Git hook

可通过 husky 设置在 git commit 时触发 commitlint。

首先安装 husky:

npm install husky --save-dev

or

yarn add husky --dev

然后在 package.json 中增加:

{
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  }
}

更多信息可参考 commitlint 文档

设置 Commitizen

预置 cz-git 引导式书写规范的 commit message,十分适合于不熟悉的同学。

package.json 中增加:

{
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-git"
    }
  }
}

Package Sidebar

Install

npm i @tembty/commitlint-config

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

6.92 kB

Total Files

3

Last publish

Collaborators

  • tembty