Skip to content

Commit 7f41df1

Browse files
Refactor: Order changelog groups by commit type
This commit introduces a `GROUP_ORDER` constant in `generate-changelog.js`, derived directly from the `commitParsers` array. - Changelog entries are now consistently ordered based on the predefined commit types (e.g., Features, Fixes, etc.), rather than the arbitrary order of `Object.keys()`. - This ensures a more predictable and organized changelog structure. - Redundant blank lines between group headers and commit lists have been removed for improved readability. Signed-off-by: CreativeCodeCat <wayne6324@gmail.com>
1 parent c8a0e92 commit 7f41df1

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

generate-changelog.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ const fs = require("fs");
66
const OUTPUT_FILE = "CHANGELOG.md";
77
const TAGS_TO_INCLUDE = 10; // Number of recent tags to include
88
const REPO_URL = "https://github.com/DroidWorksStudio/mLauncher";
9+
910
const HEADER = `# Changelog
1011
11-
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.\n\n`; // Your custom header
12+
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.\n\n`;
1213

1314
const FOOTER = `---
14-
> Generated by DroidWorksStudio`; // Your custom footer
15+
> Generated by DroidWorksStudio`;
1516

1617
// Verbose logging
1718
const VERBOSE = process.argv.includes("--verbose");
@@ -70,6 +71,10 @@ const commitParsers = [
7071
{ message: /^drop|^remove/i, group: "### Feature Removals:" },
7172
];
7273

74+
// Build group order directly from commitParsers
75+
const GROUP_ORDER = commitParsers
76+
.filter((p) => !p.skip)
77+
.map((p) => p.group);
7378

7479

7580
// Helper functions
@@ -141,9 +146,11 @@ if (latestTag) {
141146
groups[c.group] = groups[c.group] || [];
142147
groups[c.group].push(`* ${linkPR(cleanMessage(c.message))} ([${c.hash}](${REPO_URL}/commit/${c.hash}))`);
143148
}
144-
for (const group of Object.keys(groups)) {
145-
log(`Unreleased group: ${group}, commits: ${groups[group].length}`);
146-
changelog += `${group}\n${groups[group].join("\n")}\n\n`;
149+
for (const group of GROUP_ORDER) {
150+
if (groups[group]) {
151+
log(`Unreleased group: ${group}, commits: ${groups[group].length}`);
152+
changelog += `${group}\n\n${groups[group].join("\n")}\n\n`;
153+
}
147154
}
148155
}
149156
}
@@ -193,9 +200,11 @@ for (let i = 0; i < tags.length; i++) {
193200
groups[c.group].push(`* ${linkPR(cleanMessage(c.message))} ([${c.hash}](${REPO_URL}/commit/${c.hash}))`);
194201
}
195202

196-
for (const group of Object.keys(groups)) {
197-
log(`Group: ${group}, commits: ${groups[group].length}`);
198-
changelog += `${group}\n\n${groups[group].join("\n")}\n\n`;
203+
for (const group of GROUP_ORDER) {
204+
if (groups[group]) {
205+
log(`Group: ${group}, commits: ${groups[group].length}`);
206+
changelog += `${group}\n\n${groups[group].join("\n")}\n\n`;
207+
}
199208
}
200209
}
201210

0 commit comments

Comments
 (0)