Update changelog related scripts (#19226)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-05-28 01:26:59 +08:00
1 parent 3672a239ba
commit cf07f287e5
6 files changed
+33 -54

No files matched your search

+13 -10
View File
@@ -1,12 +1,12 @@
#!/usr/bin/env node
import fs from "node:fs";
import path from "node:path";
import { parseArgs } from "node:util";
import semver from "semver";
import {
categories,
changelogUnreleasedDirPath,
changelogUnreleasedDirs,
changelogUnreleasedDirectory,
getEntries,
printEntries,
replaceVersions,
@@ -14,16 +14,19 @@ import {
const { previousVersion, newVersion } = parseArguments();
const entries = changelogUnreleasedDirs.flatMap((dir) => {
const dirPath = path.join(changelogUnreleasedDirPath, dir.name);
const { title } = categories.find((category) => category.dir === dir.name);
const entries = fs
.readdirSync(changelogUnreleasedDirectory, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.flatMap((dir) => {
const dirPath = path.join(dir.path, 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 };
return getEntries(dirPath).map((entry) => {
const content =
entry.content.slice(0, 4) + ` ${title}:` + entry.content.slice(4);
return { ...entry, content };
});
});
});
console.log(
replaceVersions(
+14 -9
View File
@@ -7,8 +7,7 @@ import fg from "fast-glob";
import semver from "semver";
import {
categories,
changelogUnreleasedDirPath,
changelogUnreleasedDirs,
changelogUnreleasedDirectory,
getEntries,
printEntries,
replaceVersions,
@@ -16,11 +15,11 @@ import {
const { __dirname, require } = createEsmUtils(import.meta);
const blogDir = path.join(__dirname, "../website/blog");
const introTemplateFile = path.join(
changelogUnreleasedDirPath,
const introTemplateFile = new URL(
"BLOG_POST_INTRO_TEMPLATE.md",
changelogUnreleasedDirectory,
);
const introFile = path.join(changelogUnreleasedDirPath, "blog-post-intro.md");
const introFile = new URL("blog-post-intro.md", changelogUnreleasedDirectory);
if (!fs.existsSync(introFile)) {
fs.copyFileSync(introTemplateFile, introFile);
}
@@ -41,12 +40,18 @@ const categoriesByDir = new Map(
categories.map((category) => [category.dir, category]),
);
for (const dir of changelogUnreleasedDirs) {
const dirPath = path.join(changelogUnreleasedDirPath, dir.name);
const category = categoriesByDir.get(dir.name);
for (const entry of fs.readdirSync(changelogUnreleasedDirectory, {
withFileTypes: true,
})) {
if (!entry.isDirectory()) {
continue;
}
const dirPath = path.join(entry.path, entry.name);
const category = categoriesByDir.get(entry.name);
if (!category) {
throw new Error("Unknown category: " + dir.name);
throw new Error("Unknown category: " + entry.name);
}
category.entries = getEntries(dirPath, { useFriendlyHeadingId: true });
+1 -1
View File
@@ -12,7 +12,7 @@
import fs from "node:fs/promises";
import enquirer from "enquirer";
import openEditor from "open-editor";
import { CHANGELOG_CATEGORIES } from "./utilities/changelog-categories.js";
import { CHANGELOG_CATEGORIES } from "./utilities/changelog.js";
const prNumberPrompt = new enquirer.NumberPrompt({
message: "Input your Pull Request number:",
+1 -1
View File
@@ -6,7 +6,7 @@ import indexToPosition from "index-to-position";
import { outdent } from "outdent";
import remarkParse from "remark-parse";
import unified from "unified";
import { CHANGELOG_CATEGORIES } from "./utilities/changelog-categories.js";
import { CHANGELOG_CATEGORIES } from "./utilities/changelog.js";
const CHANGELOG_DIR = "changelog_unreleased";
const TEMPLATE_FILE = "TEMPLATE.md";
-22
View File
@@ -1,22 +0,0 @@
export const CHANGELOG_CATEGORIES = [
"angular",
"api",
"cli",
"css",
"flow",
"graphql",
"handlebars",
"html",
"javascript",
"json",
"less",
"lwc",
"mjml",
"markdown",
"mdx",
"scss",
"typescript",
"vue",
"yaml",
"misc",
];
+4 -11
View File
@@ -1,13 +1,10 @@
import fs from "node:fs";
import path from "node:path";
import createEsmUtils from "esm-utils";
import semver from "semver";
const { __dirname } = createEsmUtils(import.meta);
export const changelogUnreleasedDirPath = path.join(
__dirname,
"../../changelog_unreleased",
export const changelogUnreleasedDirectory = new URL(
"../../changelog_unreleased/",
import.meta.url,
);
export const categories = [
@@ -33,11 +30,7 @@ export const categories = [
{ dir: "misc", title: "Miscellaneous" },
];
export const changelogUnreleasedDirs = fs
.readdirSync(changelogUnreleasedDirPath, {
withFileTypes: true,
})
.filter((entry) => entry.isDirectory());
export const CHANGELOG_CATEGORIES = categories.map(({ dir }) => dir);
export function getEntries(dirPath, options) {
const fileNames = fs