Compare commits

...
2 changed files with 35 additions and 17 deletions
+23 -14
View File
@@ -50,6 +50,28 @@ function getChangenotes(): ChangenoteFile[] {
});
}
/**
* Populates the '[UNRELEASED]' section of CHANGELOG.md with the contents
* of the changenotes in {@link CHANGENOTES_DIR} and then deletes those changenotes.
* @param contents The contents of CHANGELOG.md
* @returns The updated contents of CHANGELOG.md
*/
export function transferChangenotesToChangelog(contents: string): string {
const changenotes = getChangenotes();
const changenoteBodies = changenotes.map((c) => c.content.trim());
const changenotePaths = changenotes.map((c) => c.absolutePath);
const changelog = parseChangelog(contents);
addBodyLinesToUnreleasedSection(changelog, changenoteBodies);
const updatedChangelog = renderChangelog(changelog);
for (const p of changenotePaths) {
fs.unlinkSync(p);
}
return updatedChangelog;
}
const entryPoint = process.argv[1];
if (entryPoint && import.meta.url === pathToFileURL(entryPoint).href) {
try {
@@ -91,26 +113,13 @@ function usage(): ExitCode {
function assemble(): ExitCode {
try {
const changenotes = getChangenotes();
const changenoteBodies = changenotes.map((c) => c.content);
const changenotePaths = changenotes.map((c) => c.absolutePath);
withChangelog((contents) => {
const changelog = parseChangelog(contents);
addBodyLinesToUnreleasedSection(changelog, changenoteBodies);
return renderChangelog(changelog);
return transferChangenotesToChangelog(contents);
}, {});
// Delete changenotes only after successful processing.
for (const p of changenotePaths) {
fs.unlinkSync(p);
}
return ExitCode.Success;
} catch (e) {
console.error("Failed to assemble changenotes to 'CHANGELOG.md'", e);
}
return ExitCode.Failure;
}
+12 -3
View File
@@ -23,7 +23,13 @@ import { parseArgs } from "node:util";
import { type ApiClient, getApiClient } from "./api-client";
import * as changelog from "./changelog";
import { DryRunOption, REPO_ROOT } from "./config";
import { transferChangenotesToChangelog } from "./changenotes";
import {
CHANGELOG_FILE,
CHANGENOTES_DIR,
DryRunOption,
REPO_ROOT,
} from "./config";
import {
getCurrentVersion,
replaceVersionInPackageJson,
@@ -693,11 +699,14 @@ export async function prepareNewBranch(
console.log("Updating changelog");
changelog.withChangelog(
(contents) => changelog.setVersionAndDate(version, contents),
(contents) => {
const populatedContents = transferChangenotesToChangelog(contents);
return changelog.setVersionAndDate(version, populatedContents);
},
{ ...options, initChangelog: true },
);
runGit(["add", "CHANGELOG.md"], {
runGit(["add", CHANGELOG_FILE, CHANGENOTES_DIR], {
dryRun: options.dryRun,
});
runGit(["commit", "-m", `Update changelog for v${version}`], {