From 6b02cb219ea8253892e1b6c656bc24af3c83c825 Mon Sep 17 00:00:00 2001 From: Jiaxin Peng Date: Wed, 4 Mar 2026 09:30:32 +0000 Subject: [PATCH] feat: Enhance version bumping process to update CHANGELOG.md with new version header --- package.json | 2 +- version-bump.mjs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6bf2f54..30fd399 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "dev": "node esbuild.config.mjs", "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", - "version": "node version-bump.mjs && git add manifest.json versions.json" + "version": "node version-bump.mjs && git add manifest.json versions.json CHANGELOG.md" }, "keywords": [], "author": "Jiaxin PENG", diff --git a/version-bump.mjs b/version-bump.mjs index d409fa0..1a80122 100644 --- a/version-bump.mjs +++ b/version-bump.mjs @@ -12,3 +12,40 @@ writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t")); let versions = JSON.parse(readFileSync("versions.json", "utf8")); versions[targetVersion] = minAppVersion; writeFileSync("versions.json", JSON.stringify(versions, null, "\t")); + +// tag the changelog by converting "Unreleased" to the new version section +function bumpChangelog(version) { + const changelogPath = "CHANGELOG.md"; + const content = readFileSync(changelogPath, "utf8"); + + const unreleasedHeader = "## Unreleased"; + if (!content.includes(unreleasedHeader)) { + console.warn(`[version-bump] ${unreleasedHeader} not found in ${changelogPath}, skipping changelog tagging`); + return; + } + + const today = new Date().toISOString().slice(0, 10); + const releaseHeader = `## v${version} (${today})`; + const updated = content.replace(unreleasedHeader, releaseHeader); + + const marker = "# Changelog\n\n"; + if (!updated.startsWith(marker)) { + writeFileSync(changelogPath, updated); + return; + } + + const newUnreleased = [ + "## Unreleased", + "", + "### Added", + "", + "### Changed", + "", + "### Fixed", + "", + ].join("\n"); + + writeFileSync(changelogPath, marker + newUnreleased + updated.slice(marker.length)); +} + +bumpChangelog(targetVersion);