Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ITxiaohao committed Jul 10, 2019
0 parents commit bd84f0b
Show file tree
Hide file tree
Showing 18 changed files with 1,048 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
/test/tmp
package-lock.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 ZengShunHao

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
141 changes: 141 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<h1 align="center">conventional-changelog-custom-config</h1>
<p>
<img src="https://img.shields.io/badge/version-0.1.0-blue.svg?cacheSeconds=2592000" />
<a href="https://github.com/ITxiaohao/conventional-changelog-custom-config#readme">
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" target="_blank" />
</a>
<a href="https://github.com/ITxiaohao/conventional-changelog-custom-config/blob/master/LICENSE">
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" target="_blank" />
</a>
</p>

> This preset extends the [conventional-changelog-angular](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/README.md) preset
### Differences to [conventional-changelog-angular](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/README.md)

- 使用 **redmine** 或者其他工具管理项目,可以将 GitHub/GitLab 的 **issues** 地址替换成 **bugsUrl** 中的地址
- 显示 commit 对应的**提交人****邮箱地址**
- 使用 **emojis**

前置插件准备

- [commitizen](https://github.com/commitizen/cz-cli) 针对开发者简单的 commit 规范
- [cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog) 使用 cz-conventional-changelog 的构建标准
- [conventional-changelog-cli](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-cli#readme) conventional-changelog 核心模块
- 这里我使用 [release-it](https://github.com/release-it/release-it#readme) 作为发布版本插件,也可以选择 [standard-version](https://github.com/conventional-changelog/standard-version)

```sh
npm i commitizen cz-conventional-changelog conventional-changelog-cli --save-dev

npm install --save-dev release-it
```

```sh
npm install conventional-changelog-custom-config --save-dev
```

## Configuration

在 package.json 中配置参数

### 不填配置的话则会按照 angular 的预设模版生成 CHANGELOG

```json
{
"scripts": {
"commit": "git-cz && git push",
"release": "release-it",
"changelog": "conventional-changelog -p custom-config -i CHANGELOG.md -s -r 0"
},
"repository": {
"type": "git",
"url": "https://github.com/example.git"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"changelog": {
"bugsUrl": "https://redmine.example.com/issues/",
"emojis": true,
"authorName": true,
"authorEmail": true
}
}
```

**bugsUrl**

Type: `string` Default: `false`

当你需要将 issues URL 替换成其他 URL 时,使用该参数,例如使用 **redmine** 管理项目, `bugsUrl: 'https://redmine.example.com/issues/'`

如果不填 `bugsUrl` 则会根据 **package.json** 中的 `repository.url` 来作为 issues URL

如果你使用了第三方的协作系统(例如 **bitbucket**), 推荐你使用这个插件 [conventional-changelog-angular-bitbucket](https://github.com/uglow/conventional-changelog-angular-bitbucket)

**emojis**

Type: `boolean` Default: `false`

### emojis types 参考 [gitmoji](https://gitmoji.carloscuesta.me/)

| Commit Type | Title | Description | Emojis |
| ----------- | ------------------------ | ----------------------------------------------------------------------------------------------------------- | ------ |
| `feat` | Features | A new feature ||
| `fix` | Bug Fixes | A bug Fix | 🐛 |
| `docs` | Documentation | Documentation only changes | 📝 |
| `style` | Styles | Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) | 💄 |
| `refactor` | Code Refactoring | A code change that neither fixes a bug nor adds a feature | ♻️ |
| `perf` | Performance Improvements | A code change that improves performance | ⚡️ |
| `test` | Tests | Adding missing tests or correcting existing tests ||
| `build` | Build | Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) | 👷 |
| `ci` | Continuous Integrations | Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs) | 🔧 |
| `chore` | Chores | Other changes that don't modify src or test files | 🎫 |
| `revert` | Reverts | Reverts a previous commit ||

**authorName**

Type: `boolean` Default: `false`

在 CHANGELOG 中生成用户名

**authorEmail**

Type: `boolean` Default: `false`

在 CHANGELOG 中生成邮箱

## Usage

生成 CHANGELOG 之前得**** commit,记得在 **master** **主分支**上发布版本,再生成 CHANGELOG,流程如下:

```sh
git add .

npm run commit

npm run release

npm run changelog
```

## Examples

![](https://raw.githubusercontent.com/ITxiaohao/blog-img/master/img/vue-admin/20190710133722.png)

## Show your support

如果感觉不错,给个 Star 吧~

Give a ⭐️ if this project helped you!

## 📝 License

Copyright © 2019 [zengshunhao](https://github.com/ITxiaohao).<br />
This project is [MIT](https://github.com/ITxiaohao/conventional-changelog-custom-config/blob/master/LICENSE) licensed.

## Thanks

Thanks to [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)
11 changes: 11 additions & 0 deletions conventional-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'

const Q = require(`q`)
const parserOpts = require(`./parser-opts`)
const writerOpts = require(`./writer-opts`)

module.exports = Q.all([parserOpts, writerOpts]).spread(
(parserOpts, writerOpts) => {
return { parserOpts, writerOpts }
}
)
33 changes: 33 additions & 0 deletions conventional-recommended-bump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'

const parserOpts = require(`./parser-opts`)

module.exports = {
parserOpts,

whatBump: commits => {
let level = 2
let breakings = 0
let features = 0

commits.forEach(commit => {
if (commit.notes.length > 0) {
breakings += commit.notes.length
level = 0
} else if (commit.type === `feat`) {
features += 1
if (level === 2) {
level = 1
}
}
})

return {
level: level,
reason:
breakings === 1
? `There is ${breakings} BREAKING CHANGE and ${features} features`
: `There are ${breakings} BREAKING CHANGES and ${features} features`
}
}
}
4 changes: 4 additions & 0 deletions git-raw-commit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
format:
'%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci%n-authorName-%n%an%n-authorEmail-%n%ae'
}
32 changes: 32 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict'
const Q = require(`q`)
const conventionalChangelog = require(`./conventional-changelog`)
const parserOpts = require(`./parser-opts`)
const recommendedBumpOpts = require(`./conventional-recommended-bump`)
const writerOpts = require(`./writer-opts`)
// 格式化 git log 信息
const gitRawCommitsOpts = require('./git-raw-commit')

module.exports = Q.all([
conventionalChangelog,
parserOpts,
recommendedBumpOpts,
writerOpts,
gitRawCommitsOpts
]).spread(
(
conventionalChangelog,
parserOpts,
recommendedBumpOpts,
writerOpts,
gitRawCommitsOpts
) => {
return {
conventionalChangelog,
parserOpts,
recommendedBumpOpts,
writerOpts,
gitRawCommitsOpts
}
}
)
58 changes: 58 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "conventional-changelog-custom-config",
"version": "0.1.3",
"description": "This preset extends the angular preset",
"main": "index.js",
"scripts": {
"commit": "git-cz && git push",
"changelog": "conventional-changelog -i CHANGELOG.md -s -r 0 -n ./index.js",
"release": "release-it",
"test-windows": "mocha --timeout 30000"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ITxiaohao/conventional-changelog-custom-config.git"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"keywords": [
"conventional-changelog",
"angular",
"preset",
"changelog",
"emoji"
],
"author": "Zeng Shunhao <shunhaozeng@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/ITxiaohao/conventional-changelog-custom-config/issues"
},
"homepage": "https://github.com/ITxiaohao/conventional-changelog-custom-config#readme",
"devDependencies": {
"better-than-before": "^1.0.0",
"chai": "^4.2.0",
"commitizen": "^3.1.1",
"conventional-changelog-cli": "^2.0.21",
"conventional-changelog-core": "^3.2.2",
"coveralls": "^3.0.4",
"cz-conventional-changelog": "^2.1.0",
"git-dummy-commit": "^1.3.0",
"istanbul": "^0.4.5",
"jscs": "^3.0.7",
"jshint": "^2.10.2",
"mocha": "*",
"shelljs": "^0.8.3",
"through2": "^3.0.1",
"github-url-from-git": "^1.5.0",
"compare-func": "^1.3.2",
"q": "^1.5.1"
},
"changelog": {
"emojis": true,
"authorName": true,
"authorEmail": true
}
}
9 changes: 9 additions & 0 deletions parser-opts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

module.exports = {
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: [`type`, `scope`, `subject`],
noteKeywords: [`BREAKING CHANGE`],
revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
revertCorrespondence: [`header`, `hash`]
}
65 changes: 65 additions & 0 deletions templates/commit.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
*{{#if scope}} **{{scope}}:**
{{~/if}} {{#if subject}}
{{~subject}}
{{~else}}
{{~header}}
{{~/if}}

{{~!-- commit link --}} {{#if @root.linkReferences~}}
([{{hash}}](
{{~#if @root.repository}}
{{~#if @root.host}}
{{~@root.host}}/
{{~/if}}
{{~#if @root.owner}}
{{~@root.owner}}/
{{~/if}}
{{~@root.repository}}
{{~else}}
{{~@root.repoUrl}}
{{~/if}}/
{{~@root.commit}}/{{hash}})) {{gitUserInfo}}
{{~else}}
{{~hash}}
{{~/if}}

{{~!-- commit references --}}
{{~#if references~}}
, closes
{{~#each references}} {{#if @root.linkReferences~}}
[
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}#{{this.issue}}](
{{~#if this.bugsUrl}}
{{~this.bugsUrl}}{{this.issue}}
{{~else}}
{{~#if @root.repository}}
{{~#if @root.host}}
{{~@root.host}}/
{{~/if}}
{{~#if this.repository}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}
{{~else}}
{{~#if @root.owner}}
{{~@root.owner}}/
{{~/if}}
{{~@root.repository}}
{{~/if}}
{{~else}}
{{~@root.repoUrl}}
{{~/if}}/
{{~@root.issue}}/{{this.issue}}
{{~/if}})
{{~else}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}#{{this.issue}}
{{~/if}}{{/each}}
{{~/if}}

11 changes: 11 additions & 0 deletions templates/footer.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{#if noteGroups}}
{{#each noteGroups}}

### {{title}}

{{#each notes}}
* {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{text}}
{{/each}}
{{/each}}

{{/if}}
Loading

0 comments on commit bd84f0b

Please sign in to comment.