Skip to content

Commit cf5de70

Browse files
committed
✨ feat: support config creator
1 parent d18b635 commit cf5de70

File tree

11 files changed

+287
-61
lines changed

11 files changed

+287
-61
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
};

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type { Options as SemRelOptions, PluginSpec } from 'semantic-release';
2+
3+
import type { Options } from './type';
4+
import commitAnalyzer from './commitAnalyzer';
5+
6+
export const createConfig = (options?: Options): SemRelOptions => {
7+
const opts = {
8+
changelogTitle: '# Changelog',
9+
changelogFile: 'CHANGELOG.md',
10+
enableNPM: true,
11+
enableGithub: true,
12+
...options,
13+
};
14+
const plugins: PluginSpec[] = [
15+
/* 负责解析 commit */
16+
commitAnalyzer(opts.releaseRules),
17+
/* 此处生成 github-release 的日志 */
18+
[
19+
'@semantic-release/release-notes-generator',
20+
{
21+
config: 'conventional-changelog-gitmoji-config',
22+
},
23+
],
24+
/* 此处会调用上一个插件生成的新增日志,然后合并到原有日志中 */
25+
[
26+
'@semantic-release/changelog',
27+
{
28+
changelogFile: opts.changelogFile,
29+
changelogTitle: opts.changelogTitle,
30+
},
31+
],
32+
/* 自动更新版本号 如果没有 private ,会作为 npm 模块进行发布 */
33+
opts.enableNPM ? '@semantic-release/npm' : '',
34+
/* 将生成结果发布到 Github */
35+
opts.enableGithub ? '@semantic-release/github' : '',
36+
/* 推送代码回到 Git */
37+
[
38+
'@semantic-release/git',
39+
{
40+
assets: [
41+
// 这里的 assets 配置的是要重新 push 回去的东西
42+
// 如果不列的话会将全部内容都合并到 release 中
43+
'CHANGELOG.md',
44+
'package.json',
45+
],
46+
message:
47+
// eslint-disable-next-line no-template-curly-in-string
48+
':bookmark: chore(release): ${nextRelease.gitTag} [skip ci] \n\n${nextRelease.notes}',
49+
},
50+
],
51+
];
52+
53+
return {
54+
plugins: plugins.filter((p) => !!p),
55+
};
56+
};
Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,11 @@
11
import type { Options } from 'semantic-release';
22

3-
const config: Options = {
4-
plugins: [
5-
/* 负责解析 commit */
6-
[
7-
'@semantic-release/commit-analyzer',
8-
{
9-
// 使用 changelog-gitmoji-config 自定义配置,如果不填则是默认的 conventional-changelog-angular
10-
config: 'conventional-changelog-gitmoji-config',
11-
// 默认情况下 style 和 build 都会触发新的构建
12-
releaseRules: [
13-
{ type: 'style', release: 'patch' },
14-
{ type: 'build', release: 'patch' },
15-
],
16-
},
17-
],
18-
/* 此处生成 github-release 的日志 */
19-
[
20-
'@semantic-release/release-notes-generator',
21-
{
22-
// 指定配置,这里才是负责生成日志的,也就是说,如果自定义了writerOpts,只有在这里写才会生效
23-
config: 'conventional-changelog-gitmoji-config',
24-
},
25-
],
26-
/* 此处会调用上一个插件生成的新增日志,然后合并到原有日志中 */
27-
[
28-
'@semantic-release/changelog',
29-
{
30-
changelogFile: 'CHANGELOG.md',
31-
changelogTitle: '# Changelog',
32-
},
33-
],
34-
/* 自动更新版本号 如果没有 private ,会作为 npm 模块进行发布 */
35-
'@semantic-release/npm',
36-
/* 将生成结果发布到 Github */
37-
'@semantic-release/github',
38-
/* 推送代码回到 Git */
39-
[
40-
'@semantic-release/git',
41-
{
42-
assets: [
43-
// 这里的 assets 配置的是要重新 push 回去的东西
44-
// 如果不列的话会将全部内容都合并到 release 中
45-
'CHANGELOG.md',
46-
'package.json',
47-
],
48-
message:
49-
// eslint-disable-next-line no-template-curly-in-string
50-
':bookmark: chore(release): ${nextRelease.gitTag} [skip ci] \n\n${nextRelease.notes}',
51-
},
52-
],
53-
],
54-
};
3+
import { createConfig } from './createConfig';
554

56-
export default config;
5+
const defaultConfig: Options = createConfig();
6+
7+
export default defaultConfig;
8+
9+
export { createConfig } from './createConfig';
10+
11+
export * from './type';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { CommitTypes } from '@gitmoji/commit-types';
2+
import type { Release } from 'semantic-release';
3+
4+
export interface ReleaseRule {
5+
type: CommitTypes;
6+
release: Release['type'];
7+
}
8+
9+
export interface Options {
10+
releaseRules?: ReleaseRule[];
11+
changelogTitle?: string;
12+
changelogFile?: string;
13+
/**
14+
* 开启 npm 插件
15+
* @default true
16+
*/
17+
enableNPM?: boolean;
18+
/**
19+
* 开启 github 插件
20+
* @default true
21+
*/
22+
enableGithub?: boolean;
23+
}
Lines changed: 122 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,124 @@
1-
import config from '../src';
1+
import defaultConfig, { createConfig } from '../src';
22

3-
test('Gitmoji Commit Message Preset', () => {
4-
expect(config.plugins).toBeTruthy();
3+
describe('Release Config', () => {
4+
it('get default config', () => {
5+
expect(defaultConfig).toEqual({
6+
plugins: [
7+
[
8+
'@semantic-release/commit-analyzer',
9+
{
10+
config: 'conventional-changelog-gitmoji-config',
11+
releaseRules: [
12+
{ type: 'style', release: 'patch' },
13+
{ type: 'build', release: 'patch' },
14+
],
15+
},
16+
],
17+
[
18+
'@semantic-release/release-notes-generator',
19+
{
20+
config: 'conventional-changelog-gitmoji-config',
21+
},
22+
],
23+
[
24+
'@semantic-release/changelog',
25+
{
26+
changelogFile: 'CHANGELOG.md',
27+
changelogTitle: '# Changelog',
28+
},
29+
],
30+
'@semantic-release/npm',
31+
'@semantic-release/github',
32+
[
33+
'@semantic-release/git',
34+
{
35+
assets: ['CHANGELOG.md', 'package.json'],
36+
message:
37+
// eslint-disable-next-line no-template-curly-in-string
38+
':bookmark: chore(release): ${nextRelease.gitTag} [skip ci] \n\n${nextRelease.notes}',
39+
},
40+
],
41+
],
42+
});
43+
});
44+
45+
it('disable npm plugin', () => {
46+
expect(createConfig({ enableNPM: false })).toEqual({
47+
plugins: [
48+
[
49+
'@semantic-release/commit-analyzer',
50+
{
51+
config: 'conventional-changelog-gitmoji-config',
52+
releaseRules: [
53+
{ type: 'style', release: 'patch' },
54+
{ type: 'build', release: 'patch' },
55+
],
56+
},
57+
],
58+
[
59+
'@semantic-release/release-notes-generator',
60+
{
61+
config: 'conventional-changelog-gitmoji-config',
62+
},
63+
],
64+
[
65+
'@semantic-release/changelog',
66+
{
67+
changelogFile: 'CHANGELOG.md',
68+
changelogTitle: '# Changelog',
69+
},
70+
],
71+
'@semantic-release/github',
72+
[
73+
'@semantic-release/git',
74+
{
75+
assets: ['CHANGELOG.md', 'package.json'],
76+
message:
77+
// eslint-disable-next-line no-template-curly-in-string
78+
':bookmark: chore(release): ${nextRelease.gitTag} [skip ci] \n\n${nextRelease.notes}',
79+
},
80+
],
81+
],
82+
});
83+
});
84+
85+
it('disable github plugin', () => {
86+
expect(createConfig({ enableGithub: false })).toEqual({
87+
plugins: [
88+
[
89+
'@semantic-release/commit-analyzer',
90+
{
91+
config: 'conventional-changelog-gitmoji-config',
92+
releaseRules: [
93+
{ type: 'style', release: 'patch' },
94+
{ type: 'build', release: 'patch' },
95+
],
96+
},
97+
],
98+
[
99+
'@semantic-release/release-notes-generator',
100+
{
101+
config: 'conventional-changelog-gitmoji-config',
102+
},
103+
],
104+
[
105+
'@semantic-release/changelog',
106+
{
107+
changelogFile: 'CHANGELOG.md',
108+
changelogTitle: '# Changelog',
109+
},
110+
],
111+
'@semantic-release/npm',
112+
[
113+
'@semantic-release/git',
114+
{
115+
assets: ['CHANGELOG.md', 'package.json'],
116+
message:
117+
// eslint-disable-next-line no-template-curly-in-string
118+
':bookmark: chore(release): ${nextRelease.gitTag} [skip ci] \n\n${nextRelease.notes}',
119+
},
120+
],
121+
],
122+
});
123+
});
5124
});

0 commit comments

Comments
 (0)