Skip to content

Commit

Permalink
feat(framework): 新增 Git Commit Message 规范提交能力
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyi2 committed Jul 9, 2020
1 parent afaa458 commit d04e259
Show file tree
Hide file tree
Showing 7 changed files with 3,001 additions and 3 deletions.
64 changes: 64 additions & 0 deletions .cz-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module.exports = {
types: [
{ value: "feat", name: "feat: A new feature" },
{ value: "fix", name: "fix: A bug fix" },
{ value: "docs", name: "docs: Documentation only changes" },
{
value: "style",
name:
"style: Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)",
},
{
value: "refactor",
name:
"refactor: A code change that neither fixes a bug nor adds a feature",
},
{
value: "perf",
name: "perf: A code change that improves performance",
},
{ value: "test", name: "test: Adding missing tests" },
{
value: "chore",
name:
"chore: Changes to the build process or auxiliary tools\n and libraries such as documentation generation",
},
{ value: "revert", name: "revert: Revert to a commit" },
{ value: "WIP", name: "WIP: Work in progress" },
],

// 这里是进行提交的类型配置,因为是框架设计,暂时配置一个 framework
scopes: [{ name: "framework" }],

// it needs to match the value for field type. Eg.: 'fix'
/*
scopeOverrides: {
fix: [
{name: 'merge'},
{name: 'style'},
{name: 'e2eTest'},
{name: 'unitTest'}
]
},
*/
// override the messages, defaults are as follows
messages: {
type: "Select the type of change that you're committing:",
scope: "\nDenote the SCOPE of this change (optional):",
// used if allowCustomScopes is true
customScope: "Denote the SCOPE of this change:",
subject: "Write a SHORT, IMPERATIVE tense description of the change:\n",
body:
'Provide a LONGER description of the change (optional). Use "|" to break new line:\n',
breaking: "List any BREAKING CHANGES (optional):\n",
footer:
"List any ISSUES CLOSED by this change (optional). E.g.: #31, #34:\n",
confirmCommit: "Are you sure you want to proceed with the commit above?",
},

allowCustomScopes: true,
allowBreakingChanges: ["feat", "fix"],

// limit subject length
subjectLimit: 100,
};
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# npm
node_modules
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 1.0.0 (2020-07-09)

### Features

- 项目初始化 ([afaa458](https://github.com/ziyi2/algorithms/commit/afaa4583009ea5ac3ead2f3bfc5c61103ce8533c))
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,28 @@
## 配置环境

- Init
- Git Commit Message

> 温馨提示:如果想知道各个配置的细节信息,可查看各个配置的 Commit 信息。
### Init

采用 NPM 可以对任何普通的项目进行初始化操作,执行 [`npm init`](https://docs.npmjs.com/cli/init) 会在项目根目录下生成 `package.json` 包描述文件。

> 温馨提示:更多详细项目变更可以查看 Commit。
> 温馨提示:更多关于该配置的变更可以查看 [Commit](https://github.com/ziyi2/algorithms/commit/afaa4583009ea5ac3ead2f3bfc5c61103ce8533c)
### Git Commit Message

[Commitizen](https://github.com/commitizen/cz-cli) 是一个规范 Git 提交说明(Commit Message)的 CLI 工具,具体如何配置可查看 [Cz 工具集使用介绍](https://juejin.im/post/5cc4694a6fb9a03238106eb9)。本项目中主要使用了以下功能:

- [cz-customizable](https://github.com/leonardoanalista/cz-customizable)
- [commitlint](https://commitlint.js.org/#/)
- [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog)

配置以后会产生以下能力:

- 使用 `git cz` 代替 `git commit` 进行符合 Angular 规范的 Commit Message 信息提交
- 代码提交之前会通过 [husky](https://github.com/typicode/husky) 配合 git hook 进行提交信息校验,一旦提交信息不符合 Angular 规范,则提交会失败
- 执行 `npm run log` 会在根目录下生成 `CHANGELOG.md` 版本日志

> 温馨提示:如果不知道什么是 CLI (命令行接口),可查看 [使用 NPM 发布和使用 CLI 工具](https://juejin.im/post/5eb89053e51d454de54db501)
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
};
Loading

0 comments on commit d04e259

Please sign in to comment.