From 4e64d7fd827284a909dab62bf798a83b896aec95 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 3 Mar 2025 09:07:40 +0800 Subject: [PATCH] Add title to patch release changelog (#17197) --- scripts/changelog-for-patch.js | 9 ++++++++- scripts/draft-blog-post.js | 23 +---------------------- scripts/utils/changelog.js | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/scripts/changelog-for-patch.js b/scripts/changelog-for-patch.js index eca2d3319..eaa472593 100644 --- a/scripts/changelog-for-patch.js +++ b/scripts/changelog-for-patch.js @@ -4,6 +4,7 @@ import path from "node:path"; import minimist from "minimist"; import semver from "semver"; import { + categories, changelogUnreleasedDirPath, changelogUnreleasedDirs, getEntries, @@ -15,7 +16,13 @@ const { previousVersion, newVersion } = parseArgv(); const entries = changelogUnreleasedDirs.flatMap((dir) => { const dirPath = path.join(changelogUnreleasedDirPath, dir.name); - return getEntries(dirPath); + 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 }; + }); }); console.log( diff --git a/scripts/draft-blog-post.js b/scripts/draft-blog-post.js index 1695477a3..1791b9061 100644 --- a/scripts/draft-blog-post.js +++ b/scripts/draft-blog-post.js @@ -6,6 +6,7 @@ import createEsmUtils from "esm-utils"; import fg from "fast-glob"; import semver from "semver"; import { + categories, changelogUnreleasedDirPath, changelogUnreleasedDirs, getEntries, @@ -36,28 +37,6 @@ const postFile = path.join( `${new Date().toISOString().replace(/T.+/u, "")}-${nextVersion}.md`, ); -const categories = [ - { dir: "javascript", title: "JavaScript" }, - { dir: "typescript", title: "TypeScript" }, - { dir: "flow", title: "Flow" }, - { dir: "json", title: "JSON" }, - { dir: "css", title: "CSS" }, - { dir: "scss", title: "SCSS" }, - { dir: "less", title: "Less" }, - { dir: "html", title: "HTML" }, - { dir: "vue", title: "Vue" }, - { dir: "angular", title: "Angular" }, - { dir: "lwc", title: "LWC" }, - { dir: "handlebars", title: "Ember / Handlebars" }, - { dir: "graphql", title: "GraphQL" }, - { dir: "markdown", title: "Markdown" }, - { dir: "mdx", title: "MDX" }, - { dir: "yaml", title: "YAML" }, - { dir: "api", title: "API" }, - { dir: "cli", title: "CLI" }, - { dir: "misc", title: "Miscellaneous" }, -]; - const categoriesByDir = new Map( categories.map((category) => [category.dir, category]), ); diff --git a/scripts/utils/changelog.js b/scripts/utils/changelog.js index 3699c02c3..39008cbf8 100644 --- a/scripts/utils/changelog.js +++ b/scripts/utils/changelog.js @@ -10,6 +10,28 @@ export const changelogUnreleasedDirPath = path.join( "../../changelog_unreleased", ); +export const categories = [ + { dir: "javascript", title: "JavaScript" }, + { dir: "typescript", title: "TypeScript" }, + { dir: "flow", title: "Flow" }, + { dir: "json", title: "JSON" }, + { dir: "css", title: "CSS" }, + { dir: "scss", title: "SCSS" }, + { dir: "less", title: "Less" }, + { dir: "html", title: "HTML" }, + { dir: "vue", title: "Vue" }, + { dir: "angular", title: "Angular" }, + { dir: "lwc", title: "LWC" }, + { dir: "handlebars", title: "Ember / Handlebars" }, + { dir: "graphql", title: "GraphQL" }, + { dir: "markdown", title: "Markdown" }, + { dir: "mdx", title: "MDX" }, + { dir: "yaml", title: "YAML" }, + { dir: "api", title: "API" }, + { dir: "cli", title: "CLI" }, + { dir: "misc", title: "Miscellaneous" }, +]; + export const changelogUnreleasedDirs = fs .readdirSync(changelogUnreleasedDirPath, { withFileTypes: true,