diff --git a/.release-it.js b/.release-it.js index 60035ed..5a6eb88 100644 --- a/.release-it.js +++ b/.release-it.js @@ -1,11 +1,4 @@ -const fs = require("fs"); -const path = require("path"); - -const commits_template = fs - .readFileSync( - path.resolve(__dirname, "release-it", "conventional-changelog-commit.hbs"), - ) - .toString(); +const commitPartial = require("./release-it/conventional-changelog-commit.js"); module.exports = { npm: { @@ -47,11 +40,14 @@ module.exports = { ], }, writerOpts: { - commitPartial: commits_template, + commitPartial, }, }, }, hooks: { + // Format the changelog after it is written, before Git stages it. + "after:@release-it/conventional-changelog:beforeRelease": + "npx prettier --write CHANGES.md", // Run `make bundle` after the version is bumped to get a build with // the new version number comment in the entry scripts. // Use the make target which does a check to not build if the package diff --git a/release-it/conventional-changelog-commit.hbs b/release-it/conventional-changelog-commit.hbs deleted file mode 100644 index d3fc3a0..0000000 --- a/release-it/conventional-changelog-commit.hbs +++ /dev/null @@ -1,72 +0,0 @@ - -*{{#if scope}} **{{scope}}:** -{{~/if}} {{#if subject}} - {{~subject}} -{{~else}} - {{~header}} -{{~/if}} - -{{~!-- commit link --}} {{#if @root.linkReferences~}} - ([{{shortHash}}]( - {{~#if @root.repository}} - {{~#if @root.host}} - {{~@root.host}}/ - {{~/if}} - {{~#if @root.owner}} - {{~@root.owner}}/ - {{~/if}} - {{~@root.repository}} - {{~else}} - {{~@root.repoUrl}} - {{~/if}}/ - {{~@root.commit}}/{{hash}})) -{{~else}} - {{~hash}} -{{~/if}} - -{{#if body}} - - {{body}} -{{/if}} -{{#if footer}} - - {{footer}} -{{/if}} - -{{~!-- commit references --}} -{{~#if references~}} - -closes - {{~#each references}} {{#if @root.linkReferences~}} - [ - {{~#if this.owner}} - {{~this.owner}}/ - {{~/if}} - {{~this.repository}}#{{this.issue}}]( - {{~#if @root.repository}} - {{~#if @root.host}} - {{~@root.host}}/ - {{~/if}} - {{~#if this.repository}} - {{~#if this.owner}} - {{~this.owner}}/ - {{~/if}} - {{~this.repository}} - {{~else}} - {{~#if @root.owner}} - {{~@root.owner}}/ - {{~/if}} - {{~@root.repository}} - {{~/if}} - {{~else}} - {{~@root.repoUrl}} - {{~/if}}/ - {{~@root.issue}}/{{this.issue}}) - {{~else}} - {{~#if this.owner}} - {{~this.owner}}/ - {{~/if}} - {{~this.repository}}#{{this.issue}} - {{~/if}}{{/each}} -{{~/if}} - diff --git a/release-it/conventional-changelog-commit.js b/release-it/conventional-changelog-commit.js new file mode 100644 index 0000000..da0694d --- /dev/null +++ b/release-it/conventional-changelog-commit.js @@ -0,0 +1,45 @@ +// The preset adds the list marker and indents continuation lines. +module.exports = function commitPartial(context, commit) { + const repoUrl = context.repository + ? [context.host, context.owner, context.repository].filter(Boolean).join("/") + : context.repoUrl; + const summary = [ + commit.scope && `**${commit.scope}:**`, + commit.subject || commit.header, + commit.hash && + (context.linkReferences + ? `([${commit.shortHash}](${repoUrl}/${context.commit}/${commit.hash}))` + : commit.hash), + ] + .filter(Boolean) + .join(" "); + + const references = (commit.references || []).map((reference) => { + const label = `${reference.owner ? `${reference.owner}/` : ""}${reference.repository || ""}#${reference.issue}`; + if (!context.linkReferences) { + return label; + } + + const referenceUrl = context.repository + ? [ + context.host, + reference.repository + ? reference.owner || context.owner + : context.owner, + reference.repository || context.repository, + ] + .filter(Boolean) + .join("/") + : context.repoUrl; + return `[${label}](${referenceUrl}/${context.issue}/${reference.issue})`; + }); + + return [ + summary, + commit.body, + commit.footer, + references.length && `closes ${references.join(" ")}`, + ] + .filter(Boolean) + .join("\n\n"); +};