Files
test-repo/scripts/changelog-for-patch.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-06-26 16:29:30 +09:00
#!/usr/bin/env node
import path from "node:path";
import { parseArgs } from "node:util";
2021-06-26 16:29:30 +09:00
import semver from "semver";
import {
categories,
2021-06-26 16:29:30 +09:00
changelogUnreleasedDirPath,
changelogUnreleasedDirs,
getEntries,
printEntries,
replaceVersions,
2025-12-01 07:25:25 +08:00
} from "./utilities/changelog.js";
2021-06-26 16:29:30 +09:00
const { previousVersion, newVersion } = parseArguments();
2021-06-26 16:29:30 +09:00
const entries = changelogUnreleasedDirs.flatMap((dir) => {
const dirPath = path.join(changelogUnreleasedDirPath, dir.name);
const { title } = categories.find((category) => category.dir === dir.name);
return getEntries(dirPath).map((entry) => {
const content =
entry.content.slice(0, 4) + ` ${title}:` + entry.content.slice(4);
return { ...entry, content };
});
2021-06-26 16:29:30 +09:00
});
console.log(
replaceVersions(
printEntries(entries).join("\n\n"),
previousVersion,
newVersion,
/** isPatch */ true,
),
);
function parseArguments() {
const {
values: { "prev-version": previousVersion, "new-version": newVersion },
} = parseArgs({
options: {
"prev-version": { type: "string" },
"new-version": { type: "string" },
},
});
2021-06-26 16:29:30 +09:00
if (
!previousVersion ||
!newVersion ||
semver.compare(previousVersion, newVersion) !== -1
) {
throw new Error(
`Invalid argv, prev-version: ${previousVersion}, new-version: ${newVersion}`,
);
}
return { previousVersion, newVersion };
}