Skip to content

Commit

Permalink
refactor: minir changelog template adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
qoomon committed May 26, 2023
1 parent 5901fc5 commit 36f78d9
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 2,870 deletions.
40 changes: 16 additions & 24 deletions lib/changelogGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,17 @@ module.exports = function (config) {

changelogMarkdown +=
`## **${releaseName || lastChangelogCommit.hash}**` +
`&emsp;<sub><sup>${yyyy_mm_dd(lastChangelogCommit.date)} (${changelogCommitRangeMarkdown})</sup></sub>\n`;
`&emsp;<sub><sup>${yyyy_mm_dd(lastChangelogCommit.date)} (${changelogCommitRangeMarkdown})</sup></sub>\n\n`;

if (changesSectionCommits.length > 0 || breakingSectionCommits.length > 0) {
// ------ generate changes section
const groupedChangelog = bucketAggregation(changesSectionCommits, (commit) => commit.type);
const commitTypes = Object.keys(groupedChangelog).sort();
commitTypes.forEach((commitType) => {
changelogMarkdown += "\n" +
generateMarkdownCommitTypeSection(
commitType,
groupedChangelog[commitType]
);
changelogMarkdown += generateMarkdownCommitTypeSection(
commitType,
groupedChangelog[commitType]
);
});

// ------ generate breaking section
Expand All @@ -100,21 +99,17 @@ module.exports = function (config) {
generateCustomMarkdownSection(customMarkdown);
}
} else {
changelogMarkdown += "\n" +
"*no relevant changes*\n";
changelogMarkdown += "*no relevant changes*\n";
}

changelogMarkdown +=
"\n" +
"<br>\n" +
"\n";
changelogMarkdown +="<br>\n\n";

return changelogMarkdown;
};

function generateMarkdownCommitTypeSection(commitType, commits) {
const typeSectionHeadline = config.headlines[commitType !== 'undefined' ? commitType : '?'] || commitType;
let typeSectionMarkdown = `### ${typeSectionHeadline}\n`;
let typeSectionMarkdown = `### ${typeSectionHeadline}\n\n`;

const scopedCommits = bucketAggregation(commits, commit => commit.scope);
// sort scopes by name with, undefined scope at front, if present
Expand All @@ -124,9 +119,6 @@ module.exports = function (config) {
return l > r ? 1 : -1;
})
commitScopes.forEach(scope => {
if (scope !== 'undefined') {
typeSectionMarkdown += "\n";
}
typeSectionMarkdown += generateMarkdownScopeSection(scope, scopedCommits[scope]);
});

Expand All @@ -136,12 +128,12 @@ module.exports = function (config) {
function generateMarkdownScopeSection(scope, commits) {
let scopeSectionMarkdown = '';
if (scope !== 'undefined') {
scopeSectionMarkdown += `&ensp;##### \`${scope}\`\n`;
scopeSectionMarkdown += `##### &ensp;\`${scope}\`\n\n`;
}
commits.forEach(commit => {
scopeSectionMarkdown += `* ${generateMarkdownCommit(commit)}`;
scopeSectionMarkdown += `- ${generateMarkdownCommit(commit)}`;
});
return scopeSectionMarkdown;
return scopeSectionMarkdown + '\n'
}

function generateMarkdownCommit(commit) {
Expand Down Expand Up @@ -177,18 +169,18 @@ module.exports = function (config) {
const msgBody = breakingChange.split('\n').splice(1).join("\n")
.replace(/\n\n\n/, "\n\n").replace(/\n*$/, ""); // remove multiple empty lines and trailing spaces

let breakingChangeMarkdown = "* ";
let breakingChangeMarkdown = "- ";
if (commit.scope) {
breakingChangeMarkdown += `\`${commit.scope}\``;
}
if (msgSubject) {
breakingChangeMarkdown += ` ${escapeMarkdown(msgSubject)}`;
}
breakingChangeMarkdown += ` (${markdownCommitHash(commit.hash)})`;
breakingChangeMarkdown += ` (${markdownCommitHash(commit.hash)})\n`;
if (msgBody) {
breakingChangeMarkdown += `<br>${escapeMarkdown(msgBody)}`;
breakingChangeMarkdown += "\n";
breakingChangeMarkdown += `${escapeMarkdown(msgBody)}\n`;
}
breakingChangeMarkdown += "\n";

changelogMarkdown += breakingChangeMarkdown;
}));
Expand Down Expand Up @@ -241,7 +233,7 @@ module.exports = function (config) {
function escapeMarkdown(text) {
const markdownEscapeChars = ['\\', '`', '*', '{', '}', '[', ']', '(', ')', '#', '+', '-', '.', '!', '_', '>'];
const markdownEscapeRegex = RegExp("[" + markdownEscapeChars.join("\\") + "]", "g");
return text.replace(markdownEscapeRegex, "\\$&").replace(/\n/g, "<br>");
return text.replace(markdownEscapeRegex, "\\$&").replace(/\n/g, "\n ");
}

function yyyy_mm_dd(date) {
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function defaultConfig() {
"perf": "Performance Improvements",
"merge": "Merges",
"breakingChange": "BREAKING CHANGES",
"?": "???"
"?": "? ? ?"
},
commitUrl: null,
commitRangeUrl: null,
Expand Down
Loading

0 comments on commit 36f78d9

Please sign in to comment.