Skip to content

Commit ee6230c

Browse files
committed
chore: updated changelog script and templates
1 parent 657ca33 commit ee6230c

4 files changed

Lines changed: 195 additions & 52 deletions

File tree

.auto-changelog

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
{
22
"handlebarsSetup": "./scripts/auto-changelog.js",
3-
"ignoreCommitPattern": "^chore: release v",
3+
"ignoreCommitPattern": "release v",
44
"startingVersion": "v4.0.0-alpha.0",
55
"unreleased": false,
6-
"commitLimit": false
6+
"commitLimit": false,
7+
"replaceText": {
8+
"([bB]reaking: )": "",
9+
"([bB]reaking change: )": "",
10+
"(^[fF]eat: )": "",
11+
"(^[fF]eat\\()": "(",
12+
"(^[fF]ix: )": "",
13+
"(^[fF]ix\\()": "(",
14+
"(^[cC]hore: )": "",
15+
"(^[cC]hore\\()": "(",
16+
"(^[dD]ocs: )": "",
17+
"(^[dD]ocs\\()": "(",
18+
"(^[rR]efactor: )": "",
19+
"(^[rR]efactor\\()": "(",
20+
"(^[tT]est: )": "",
21+
"(^[tT]est\\()": "(",
22+
"(^[sS]tyle: )": "",
23+
"(^[sS]tyle\\()": "(",
24+
"(^[pP]erf: )": "",
25+
"(^[pP]erf\\()": "("
26+
}
727
}

scripts/auto-changelog.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,44 @@
11
module.exports = function (Handlebars) {
2-
Handlebars.registerHelper('custom', function (context, extra, options) {
3-
if ((!context || context.length === 0) && (!extra || extra.length === 0)) {
4-
return '';
5-
}
2+
Handlebars.registerHelper(
3+
'custom',
4+
function (context, merges, fixes, options) {
5+
if (
6+
(!context || context.length === 0) &&
7+
(!merges || merges.length === 0) &&
8+
(!fixes || fixes.length === 0)
9+
) {
10+
return '';
11+
}
612

7-
const list = [...context, ...extra]
8-
.filter(item => {
9-
const commit = item.commit || item;
10-
if (options.hash.exclude) {
11-
const pattern = new RegExp(options.hash.exclude, 'm');
12-
if (pattern.test(commit.message)) {
13-
return false;
13+
const list = [...context, ...(merges || []), ...(fixes || [])]
14+
.filter(item => {
15+
const commit = item.commit || item;
16+
if (options.hash.exclude) {
17+
const pattern = new RegExp(options.hash.exclude, 'm');
18+
if (pattern.test(commit.message)) {
19+
return false;
20+
}
21+
}
22+
if (options.hash.message) {
23+
const pattern = new RegExp(options.hash.message, 'm');
24+
return pattern.test(commit.message);
25+
}
26+
if (options.hash.subject) {
27+
const pattern = new RegExp(options.hash.subject);
28+
return pattern.test(commit.subject);
1429
}
15-
}
16-
if (options.hash.message) {
17-
const pattern = new RegExp(options.hash.message, 'm');
18-
return pattern.test(commit.message);
19-
}
20-
if (options.hash.subject) {
21-
const pattern = new RegExp(options.hash.subject);
22-
return pattern.test(commit.subject);
23-
}
24-
return true;
25-
})
26-
.map(item => options.fn(item))
27-
.join('');
30+
return true;
31+
})
32+
.map(item => options.fn(item.commit || item))
33+
.join('');
2834

29-
if (!list) {
30-
return '';
31-
}
35+
if (!list) {
36+
return '';
37+
}
3238

33-
return options.hash.heading
34-
? `${options.hash.heading}\n\n${list}`
35-
: `${list}`;
36-
});
39+
return options.hash.heading
40+
? `${options.hash.heading}\n\n${list}`
41+
: `${list}`;
42+
}
43+
);
3744
};

templates/changelog-template.hbs

Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,122 @@
1-
# Changelog
1+
## Changelog
2+
3+
{{!--
4+
Introduction
5+
• This template tries to follow conventional commits format https://www.conventionalcommits.org/en/v1.0.0/
6+
• The template uses regex to filter commit types into their own headings (this is more than just fixes and features headings)
7+
• It also uses the replaceText function in package.json to remove the commit type text from the message, because the headers are shown instead.
8+
9+
• The text 'Breaking:' or 'Breaking changes:' can be located anywhere in the commit.
10+
• The types feat:, fix:, chore:, docs:, refactor:, test:, style:, perf: must be at the beginning of the commit subject with an : on end.
11+
• They can optionally have a scope set to outline the module or component that is affected eg feat(bldAssess):
12+
• There is a short hash on the end of every commit that is currently commented out so that change log did not grow too long (due to some system's file size limitations). You can uncomment if you wish [`{{shorthash}}`]({{href}})
13+
14+
Example Definitions
15+
• feat: A new feature
16+
• fix: A bug fix
17+
• perf: A code change that improves performance
18+
• refactor: A code change that neither fixes a bug nor adds a feature
19+
• style: Changes that do not affect the meaning of the code (white-space, formatting, spelling mistakes, missing semi-colons, etc)
20+
• test: Adding missing tests or correcting existing tests
21+
• docs: Adding/updating documentation
22+
• chore: Something like updating a library version, or moving files to be in a better location and updating all file refs
23+
--}}
24+
25+
26+
{{!-- In package.json need to add this to remove label text from the change log output (because the markdown headers are now used to group them).
27+
NOTES • Individual brackets have been escaped twice to be Json compliant.
28+
• For items that define a scope eg feat(bldAssess): We remove the 1st bracket and then re-add it so we can select the right piece of text
29+
{
30+
"name": "my-awesome-package",
31+
32+
"auto-changelog": {
33+
"replaceText": {
34+
"([bB]reaking:)": "",
35+
"([bB]reaking change:)": "",
36+
"(^[fF]eat:)": "",
37+
"(^[fF]eat\\()": "\\(",
38+
"(^[fF]ix:)": "",
39+
"(^[fF]ix\\()": "\\(",
40+
"(^[cC]hore:)": "",
41+
"(^[cC]hore\\()": "\\(",
42+
"(^[dD]ocs:)": "",
43+
"(^[dD]ocs\\()": "\\(",
44+
"(^[rR]efactor:)": "",
45+
"(^[rR]efactor\\()": "\\(",
46+
"(^[tT]est:)": "",
47+
"(^[tT]est\\()": "\\(",
48+
"(^[sS]tyle:)": "",
49+
"(^[sS]tyle\\()": "\\(",
50+
"(^[pP]erf:)": "",
51+
"(^[pP]erf\\()": "\\("
52+
}
53+
}
54+
55+
}
56+
--}}
57+
58+
{{!--
59+
Regex reminders
60+
^ = starts with
61+
\( = ( character (otherwise it is interpreted as a regex lookup group)
62+
* = zero or more of the previous character
63+
\s = whitespace
64+
. = any character except newline
65+
| = or
66+
[aA] = character a or character A
67+
--}}
68+
269

370
{{#each releases}}
471
{{#if href}}
5-
## [{{title}}]({{href}}){{#if tag}} - {{isoDate}}{{/if}}
72+
##{{#unless major}}#{{/unless}} [{{title}}]({{href}}) - {{#if tag}} {{niceDate}} {{/if}}
73+
674
{{else}}
7-
## {{title}}{{#if tag}} - {{isoDate}}{{/if}}
75+
### {{title}}
876
{{/if}}
977

1078
{{#if summary}}
1179
{{summary}}
1280
{{/if}}
1381

14-
{{#custom merges commits heading="#### Features" subject="feat: "}}
15-
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
82+
{{#custom merges fixes commits heading='#### Breaking Changes :warning:' message='[bB]reaking [cC]hange:|[bB]reaking:' }}
83+
- {{subject}} ([`{{shorthash}}`]({{href}}))
84+
{{/custom}}
85+
86+
{{#custom merges fixes commits heading='#### New Features' message='^[fF]eat:|[fF]eat\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
87+
- {{subject}} ([`{{shorthash}}`]({{href}}))
88+
{{/custom}}
89+
90+
{{#custom merges fixes commits heading='#### Fixes' message='^[fF]ix:|^[fF]ix\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
91+
- {{subject}} ([`{{shorthash}}`]({{href}}))
92+
{{/custom}}
93+
94+
{{#custom merges fixes commits heading='#### Documentation Changes' message='^[dD]ocs:|^[dD]ocs\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
95+
- {{subject}} ([`{{shorthash}}`]({{href}}))
96+
{{/custom}}
97+
98+
{{#custom merges fixes commits heading='#### Refactoring and Updates' message='^[rR]efactor:|^[rR]efactor\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
99+
- {{subject}} ([`{{shorthash}}`]({{href}}))
100+
{{/custom}}
101+
102+
{{#custom merges fixes commits heading='#### Changes to Test Assets' message='^[tT]est:|^[tT]est\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
103+
- {{subject}} ([`{{shorthash}}`]({{href}}))
104+
{{/custom}}
105+
106+
{{#custom merges fixes commits heading='#### Tidying of Code eg Whitespace' message='^[sS]tyle:|^[sS]tyle\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
107+
- {{subject}} ([`{{shorthash}}`]({{href}}))
16108
{{/custom}}
17109

18-
{{#custom merges commits heading="#### Improvements" subject="(chore|refactor|style): "}}
19-
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
110+
{{#custom merges fixes commits heading='#### Performance Improvements' message='^[pP]erf:|^[pP]erf\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
111+
- {{subject}} ([`{{shorthash}}`]({{href}}))
20112
{{/custom}}
21113

22-
{{#custom merges commits heading="#### Fixes" subject="fix: "}}
23-
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
114+
{{#custom merges fixes commits heading='#### Chores And Housekeeping' message='^[cC]hore:|^[cC]hore\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
115+
- {{subject}} ([`{{shorthash}}`]({{href}}))
24116
{{/custom}}
25117

26-
{{#custom merges commits heading="#### Documentations" subject="docs: "}}
27-
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
118+
{{#custom merges fixes commits heading='#### General Changes' exclude='[bB]reaking [cC]hange:|[bB]reaking:|^[fF]eat:|^[fF]eat\(|^[fF]ix:|^[fF]ix\(|^[cC]hore:|^[cC]hore\(|^[dD]ocs:|^[dD]ocs\(|^[rR]efactor:|^[rR]efactor\(|^[tT]est:|^[tT]est\(|^[sS]tyle:|^[sS]tyle\(|^[pP]erf:|^[pP]erf\('}}
119+
- {{subject}} ([`{{shorthash}}`]({{href}}))
28120
{{/custom}}
29121

30122
{{/each}}

templates/release-template.hbs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
11
{{#each releases}}
22
{{#if @first}}
3-
{{#custom merges commits heading="#### Features" subject="feat: "}}
4-
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
3+
{{#custom merges fixes commits heading='#### Breaking Changes :warning:' message='[bB]reaking [cC]hange:|[bB]reaking:' }}
4+
- {{subject}} ([`{{shorthash}}`]({{href}}))
55
{{/custom}}
66

7-
{{#custom merges commits heading="#### Improvements" subject="(chore|refactor|style): "}}
8-
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
7+
{{#custom merges fixes commits heading='#### New Features' message='^[fF]eat:|[fF]eat\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
8+
- {{subject}} ([`{{shorthash}}`]({{href}}))
99
{{/custom}}
1010

11-
{{#custom merges commits heading="#### Fixes" subject="fix: "}}
12-
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
11+
{{#custom merges fixes commits heading='#### Fixes' message='^[fF]ix:|^[fF]ix\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
12+
- {{subject}} ([`{{shorthash}}`]({{href}}))
1313
{{/custom}}
1414

15-
{{#custom merges commits heading="#### Documentations" subject="docs: "}}
16-
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
15+
{{#custom merges fixes commits heading='#### Documentation Changes' message='^[dD]ocs:|^[dD]ocs\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
16+
- {{subject}} ([`{{shorthash}}`]({{href}}))
17+
{{/custom}}
18+
19+
{{#custom merges fixes commits heading='#### Refactoring and Updates' message='^[rR]efactor:|^[rR]efactor\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
20+
- {{subject}} ([`{{shorthash}}`]({{href}}))
21+
{{/custom}}
22+
23+
{{#custom merges fixes commits heading='#### Changes to Test Assets' message='^[tT]est:|^[tT]est\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
24+
- {{subject}} ([`{{shorthash}}`]({{href}}))
25+
{{/custom}}
26+
27+
{{#custom merges fixes commits heading='#### Tidying of Code eg Whitespace' message='^[sS]tyle:|^[sS]tyle\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
28+
- {{subject}} ([`{{shorthash}}`]({{href}}))
29+
{{/custom}}
30+
31+
{{#custom merges fixes commits heading='#### Performance Improvements' message='^[pP]erf:|^[pP]erf\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
32+
- {{subject}} ([`{{shorthash}}`]({{href}}))
33+
{{/custom}}
34+
35+
{{#custom merges fixes commits heading='#### Chores And Housekeeping' message='^[cC]hore:|^[cC]hore\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
36+
- {{subject}} ([`{{shorthash}}`]({{href}}))
37+
{{/custom}}
38+
39+
{{#custom merges fixes commits heading='#### General Changes' exclude='[bB]reaking [cC]hange:|[bB]reaking:|^[fF]eat:|^[fF]eat\(|^[fF]ix:|^[fF]ix\(|^[cC]hore:|^[cC]hore\(|^[dD]ocs:|^[dD]ocs\(|^[rR]efactor:|^[rR]efactor\(|^[tT]est:|^[tT]est\(|^[sS]tyle:|^[sS]tyle\(|^[pP]erf:|^[pP]erf\('}}
40+
- {{subject}} ([`{{shorthash}}`]({{href}}))
1741
{{/custom}}
1842
{{/if}}
1943
{{/each}}

0 commit comments

Comments
 (0)