Skip to content

Commit 114a437

Browse files
authored
Merge pull request #52 from arvinxx/beta
Feature: support semantic release config gitmoji customization
2 parents 8e4995d + 577f3bb commit 114a437

File tree

14 files changed

+367
-62
lines changed

14 files changed

+367
-62
lines changed

packages/release-config/.fatherrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ const config = require('../../.fatherrc');
22

33
module.exports = {
44
...config,
5+
pkgs: ['@gitmoji/commit-types'],
56
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
# semantic-release-config-gitmoji 1.0.0-beta.1 (2021-03-06)
4+
5+
6+
### ✨ Features
7+
8+
* add git options ([cd1ab94](https://github.com/arvinxx/gitmoji-commit-workflow/commit/cd1ab94))
9+
* support config creator ([cf5de70](https://github.com/arvinxx/gitmoji-commit-workflow/commit/cf5de70))

packages/release-config/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# semantic-release-config-gitmoji
1+
# semantic-release-defaultConfig-gitmoji
22

33
[![NPM version][version-image]][version-url] [![NPM downloads][download-image]][download-url]
44

packages/release-config/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const base = require('../../jest.config.base');
22

3-
const packageName = 'semantic-release-config-gitmoji-module-github';
3+
const packageName = 'semantic-release-config-gitmoji';
44

55
const root = '<rootDir>/packages/release-config';
66

packages/release-config/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "semantic-release-config-gitmoji",
3-
"version": "1.0.0",
3+
"version": "1.0.0-beta.1",
44
"description": "a gitmoji commit style presets for semantic-release",
55
"main": "lib/index.js",
66
"files": [
@@ -36,8 +36,9 @@
3636
},
3737
"homepage": "https://github.com/arvinxx/gitmoji-commit-workflow/tree/master/packages/release-config#readme",
3838
"dependencies": {
39-
"conventional-changelog-gitmoji-config": "1.4.2",
39+
"@gitmoji/commit-types": "1.1.5",
4040
"@semantic-release/changelog": "^5.0.1",
41-
"@semantic-release/git": "^9.0.0"
41+
"@semantic-release/git": "^9.0.0",
42+
"conventional-changelog-gitmoji-config": "1.4.2"
4243
}
4344
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import commitAnalyzer from './commitAnalyzer';
2+
3+
describe('commitAnalyzer', () => {
4+
it('default', () => {
5+
expect(commitAnalyzer()).toEqual([
6+
'@semantic-release/commit-analyzer',
7+
{
8+
config: 'conventional-changelog-gitmoji-config',
9+
releaseRules: [
10+
{
11+
release: 'patch',
12+
type: 'style',
13+
},
14+
{
15+
release: 'patch',
16+
type: 'build',
17+
},
18+
],
19+
},
20+
]);
21+
});
22+
23+
it('add new release rules', () => {
24+
expect(commitAnalyzer([{ release: 'patch', type: 'perf' }])).toEqual([
25+
'@semantic-release/commit-analyzer',
26+
{
27+
config: 'conventional-changelog-gitmoji-config',
28+
releaseRules: [
29+
{
30+
release: 'patch',
31+
type: 'style',
32+
},
33+
{
34+
release: 'patch',
35+
type: 'build',
36+
},
37+
{
38+
release: 'patch',
39+
type: 'perf',
40+
},
41+
],
42+
},
43+
]);
44+
});
45+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { ReleaseRule } from './type';
2+
import type { PluginSpec } from 'semantic-release';
3+
4+
/**
5+
* commit analyzer
6+
* @param releaseRules
7+
*/
8+
const commitAnalyzer = (releaseRules: ReleaseRule[] = []): PluginSpec => [
9+
'@semantic-release/commit-analyzer',
10+
{
11+
// 使用 changelog-gitmoji-config 自定义配置,如果不填则是默认的 conventional-changelog-angular
12+
config: 'conventional-changelog-gitmoji-config',
13+
// 默认情况下 style 和 build 都会触发新的构建
14+
releaseRules: [
15+
{ type: 'style', release: 'patch' },
16+
{ type: 'build', release: 'patch' },
17+
].concat(releaseRules),
18+
},
19+
];
20+
21+
export default commitAnalyzer;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { Options as SemRelOptions, PluginSpec } from 'semantic-release';
2+
3+
import type { Options } from './type';
4+
import commitAnalyzer from './commitAnalyzer';
5+
import git from './git';
6+
7+
export const createConfig = (options?: Options): SemRelOptions => {
8+
const opts = {
9+
changelogTitle: '# Changelog',
10+
changelogFile: 'CHANGELOG.md',
11+
enableNPM: true,
12+
enableGithub: true,
13+
...options,
14+
};
15+
const plugins: PluginSpec[] = [
16+
/* 负责解析 commit */
17+
commitAnalyzer(opts.releaseRules),
18+
/* 此处生成 github-release 的日志 */
19+
[
20+
'@semantic-release/release-notes-generator',
21+
{
22+
config: 'conventional-changelog-gitmoji-config',
23+
},
24+
],
25+
/* 此处会调用上一个插件生成的新增日志,然后合并到原有日志中 */
26+
[
27+
'@semantic-release/changelog',
28+
{
29+
changelogFile: opts.changelogFile,
30+
changelogTitle: opts.changelogTitle,
31+
},
32+
],
33+
/* 自动更新版本号 如果没有 private ,会作为 npm 模块进行发布 */
34+
opts.enableNPM ? '@semantic-release/npm' : '',
35+
/* 将生成结果发布到 Github */
36+
opts.enableGithub ? '@semantic-release/github' : '',
37+
/* 推送代码回到 Git */
38+
git(options),
39+
];
40+
41+
return {
42+
plugins: plugins.filter((p) => !!p),
43+
};
44+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import git from './git';
2+
3+
describe('git', () => {
4+
it('default', () => {
5+
expect(git()).toEqual([
6+
'@semantic-release/git',
7+
{
8+
assets: ['CHANGELOG.md', 'package.json'],
9+
message:
10+
// eslint-disable-next-line no-template-curly-in-string
11+
':bookmark: chore(release): ${nextRelease.gitTag} [skip ci] \n\n${nextRelease.notes}',
12+
},
13+
]);
14+
});
15+
16+
it('add new assets rules', () => {
17+
expect(git({ assets: ['file.json'] })).toEqual([
18+
'@semantic-release/git',
19+
{
20+
assets: ['CHANGELOG.md', 'package.json', 'file.json'],
21+
message:
22+
// eslint-disable-next-line no-template-curly-in-string
23+
':bookmark: chore(release): ${nextRelease.gitTag} [skip ci] \n\n${nextRelease.notes}',
24+
},
25+
]);
26+
});
27+
28+
it('custom message', () => {
29+
expect(git({ message: 'chore(release)' })).toEqual([
30+
'@semantic-release/git',
31+
{
32+
assets: ['CHANGELOG.md', 'package.json'],
33+
message: 'chore(release)',
34+
},
35+
]);
36+
});
37+
});

packages/release-config/src/git.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { PluginSpec } from 'semantic-release';
2+
import type { GitPluginOpts } from './type';
3+
4+
/**
5+
* git
6+
* @param options
7+
*/
8+
const git = (options: GitPluginOpts = {}): PluginSpec => {
9+
return [
10+
'@semantic-release/git',
11+
{
12+
assets:
13+
typeof options.assets === 'boolean'
14+
? false
15+
: [
16+
// 这里的 assets 配置的是要重新 push 回去的东西
17+
// 如果不列的话会将全部内容都合并到 release 中
18+
'CHANGELOG.md',
19+
'package.json',
20+
]
21+
.concat(options.assets)
22+
.filter((a) => a),
23+
message: options.message
24+
? options.message
25+
: // eslint-disable-next-line no-template-curly-in-string
26+
':bookmark: chore(release): ${nextRelease.gitTag} [skip ci] \n\n${nextRelease.notes}',
27+
},
28+
];
29+
};
30+
31+
export default git;

0 commit comments

Comments
 (0)