diff --git a/.release-it.json b/.release-it.json index b887a7e..bc70280 100644 --- a/.release-it.json +++ b/.release-it.json @@ -3,11 +3,11 @@ "push": true, "tagName": "v${version}", "commitMessage": "chore: release v${version}", - "changelog": "auto-changelog --stdout --commit-limit false --ignore-commit-pattern \"^chore: release v\" --unreleased --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\"" + "changelog": "auto-changelog --stdout --commit-limit false --ignore-commit-pattern \"^chore: release v\" --unreleased --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\" --handlebars-setup ./scripts/auto-changelog.js" }, "github": { "release": true, - "releaseNotes": "auto-changelog --stdout --commit-limit false --ignore-commit-pattern \"^chore: release v\" --unreleased --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\"" + "releaseNotes": "auto-changelog --stdout --commit-limit false --ignore-commit-pattern \"^chore: release v\" --unreleased --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\" --handlebars-setup ./scripts/auto-changelog.js" }, "npm": { "publish": false @@ -18,6 +18,6 @@ } }, "hooks": { - "after:bump": "auto-changelog -p --ignore-commit-pattern \"^chore: release v\" --template \"keepachangelog\" --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\"" + "after:bump": "auto-changelog -p --ignore-commit-pattern \"^chore: release v\" --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\" --handlebars-setup ./scripts/auto-changelog.js" } -} \ No newline at end of file +} diff --git a/release-template.hbs b/release-template.hbs index 37a497c..400525b 100644 --- a/release-template.hbs +++ b/release-template.hbs @@ -1,13 +1,39 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +{{#unless options.hideCredit}} + Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +{{/unless}} + {{#each releases}} -{{#if @first}} -{{#each merges}} -- {{{message}}}{{#if href}} [`#{{id}}`]({{href}}){{/if}} -{{/each}} -{{#each fixes}} -- {{{commit.subject}}}{{#each fixes}}{{#if href}} [`#{{id}}`]({{href}}){{/if}}{{/each}} -{{/each}} -{{#each commits}} -- {{#if breaking}}**Breaking change:** {{/if}}{{{subject}}}{{#if href}} [`{{shorthash}}`]({{href}}){{/if}} -{{/each}} -{{/if}} + {{#if href}} + ## [{{title}}]({{href}}){{#if tag}} - {{isoDate}}{{/if}} + {{else}} + ## {{title}}{{#if tag}} - {{isoDate}}{{/if}} + {{/if}} + + {{#if summary}} + {{summary}} + {{/if}} + + {{#custom merges commits heading="#### Features" subject="feat: "}} + - {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})). + {{/custom}} + + {{#custom merges commits heading="#### Improvements" subject="(chore|refactor|style): "}} + - {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})). + {{/custom}} + + {{#custom merges commits heading="#### Fixes" subject="fix: "}} + - {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})). + {{/custom}} + + {{#custom merges commits heading="#### Documentations" subject="docs: "}} + - {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})). + {{/custom}} + {{/each}} \ No newline at end of file diff --git a/scripts/auto-changelog.js b/scripts/auto-changelog.js new file mode 100644 index 0000000..0f90d06 --- /dev/null +++ b/scripts/auto-changelog.js @@ -0,0 +1,37 @@ +module.exports = function (Handlebars) { + Handlebars.registerHelper('custom', function (context, extra, options) { + if ((!context || context.length === 0) && (!extra || extra.length === 0)) { + return ''; + } + + const list = [...context, ...extra] + .filter(item => { + const commit = item.commit || item; + if (options.hash.exclude) { + const pattern = new RegExp(options.hash.exclude, 'm'); + if (pattern.test(commit.message)) { + return false; + } + } + if (options.hash.message) { + const pattern = new RegExp(options.hash.message, 'm'); + return pattern.test(commit.message); + } + if (options.hash.subject) { + const pattern = new RegExp(options.hash.subject); + return pattern.test(commit.subject); + } + return true; + }) + .map(item => options.fn(item)) + .join(''); + + if (!list) { + return ''; + } + + return options.hash.heading + ? `${options.hash.heading}\n\n${list}` + : `${list}`; + }); +};