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.

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-06-26 16:29:30 +09:00
#!/usr/bin/env node
2026-05-28 01:26:59 +08:00
import fs from "node:fs";
2021-06-26 16:29:30 +09:00
import path from "node:path";
import { parseArgs } from "node:util";
2026-09-23 13:09:12 +08:00
import * as verkit from "verkit";
2021-06-26 16:29:30 +09:00
import {
categories,
2026-05-28 01:26:59 +08:00
changelogUnreleasedDirectory,
2021-06-26 16:29:30 +09:00
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
2026-05-28 01:26:59 +08:00
const entries = fs
.readdirSync(changelogUnreleasedDirectory, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.flatMap((dir) => {
2026-06-28 06:40:45 +08:00
const dirPath = path.join(dir.parentPath, dir.name);
2026-05-28 01:26:59 +08:00
const { title } = categories.find((category) => category.dir === dir.name);
2026-05-28 01:26:59 +08:00
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 ||
2026-09-23 13:09:12 +08:00
!verkit.isGreaterThan(newVersion, previousVersion)
2021-06-26 16:29:30 +09:00
) {
throw new Error(
`Invalid argv, prev-version: ${previousVersion}, new-version: ${newVersion}`,
);
}
return { previousVersion, newVersion };
}