Skip to content

Commit

Permalink
Improve changelog rendering template
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalmaster committed Mar 29, 2024
1 parent b17f74d commit 713947d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/extension.js
tailwind.config.js
webpack.config.js
changelog-setup.js
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/extension.js.map
/extension.js.LICENSE.txt

# Change log debug data
changelog-data.json

# Ignore: Just adding so that we get tailwindcss completions in vscode
tailwind.config.js

Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/extension.js

/changelog-template.hbs
59 changes: 59 additions & 0 deletions changelog-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports = function (Handlebars) {
Handlebars.registerHelper('full-commit-list', (commits, merges, fixes, options) => {
commits = commits
.concat(merges.map((merge) => merge.commit))
.concat(fixes.map((fix) => fix.commit));

if (!commits || commits.length === 0) {
return '';
}

const { exclude, message, subject, heading } = options.hash;

const list = commits
.filter((item) => {
const commit = item.commit || item;

// Exclude commits where subject includes with "Release v"
if (commit.subject.includes('Release v')) {
return false;
}

if (exclude) {
const excludeList = exclude.split('|');
for (const e of excludeList) {
const pattern = new RegExp(e, 'm');
if (pattern.test(commit.message)) {
return false;
}
}
}
if (message) {
const pattern = new RegExp(message, 'm');
return pattern.test(commit.message);
}
if (subject) {
const pattern = new RegExp(subject);
const match = pattern.test(commit.subject);
if (match) {
// remove the message from the commit subject and message and trim
commit.subject = commit.subject.replace(pattern, '').trim();
}
return match;
}
return true;
})
.map((item) => options.fn(item))
.join('');

if (!list) {
return '';
}

if (!heading) {
return list;
}

return `${heading}\n\n${list}`;
});
};
32 changes: 32 additions & 0 deletions changelog-template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
### Changelog

#### All notable changes to this project will be documented in this file.

Generated by the awesome [`auto-changelog`](https://github.com/CookPete/auto-changelog) package 👏🏽.

{{#each releases}}
{{#if href}}
## [{{title}}]({{href}}){{#if tag}} - {{niceDate}}{{/if}}
{{else}}
## {{title}}{{#if tag}} - {{isoDate}}{{/if}}
{{/if}}
{{#if summary}}
{{summary}}
{{/if}}

{{#full-commit-list commits merges fixes heading='### Breaking Changes' subject='Breaking change: '}}
- {{subject}} [`{{shorthash}}`]({{href}})
{{/full-commit-list}}

{{#full-commit-list commits merges fixes heading='### New Features' subject='Feat:' exclude='Breaking change: '}}
- {{subject}} [`{{shorthash}}`]({{href}})
{{/full-commit-list}}

{{#full-commit-list commits merges fixes heading='### Bug Fixes' subject='Bug Fix:' exclude='Breaking change: '}}
- {{subject}} [`{{shorthash}}`]({{href}})
{{/full-commit-list}}

{{#full-commit-list commits merges fixes heading='### Other Changes' exclude='Feat:|Bug Fix:|Breaking change:'}}
- {{subject}} [`{{shorthash}}`]({{href}})
{{/full-commit-list}}
{{/each}}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"lint": "eslint '**/*.{ts,tsx,js,jsx}'",
"typecheck": "tsc",
"test": "jest",
"changelog": "auto-changelog --package --commit-limit false && git add CHANGELOG.md"
"changelog-generate": "auto-changelog --starting-version v16 --handlebars-setup changelog-setup.js --template changelog-template.hbs --commit-limit false",
"changelog-data": "npm run changelog-generate -- --template json --output changelog-data.json",
"changelog": "npm run changelog-data && npm run changelog-generate && git add CHANGELOG.md"
},
"jest": {
"testEnvironment": "jsdom",
Expand Down

0 comments on commit 713947d

Please sign in to comment.