Remove esm-utils from "generate-changelog" script (#17559)
This commit is contained in:
1 parent
4973687969
commit
9aa661ac50
1 file changed
+20
-21
@@ -4,19 +4,15 @@
|
||||
* When you run the script, enter the number and category of the Pull Request at the prompt.
|
||||
* Get the PR title and author name via the GitHub API and create a file in ./changelog_unreleased
|
||||
*
|
||||
* $ node ./scripts/generate-changelog.mjs
|
||||
* ✔ Input your Pull Request number: · 10961
|
||||
* ✔ Input category of your Pull Request: · typescript
|
||||
* $ node ./scripts/generate-changelog.js
|
||||
* ✔ Input your Pull Request number: 10961
|
||||
* ✔ Input category of your Pull Request: typescript
|
||||
*/
|
||||
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import enquirer from "enquirer";
|
||||
import createEsmUtils from "esm-utils";
|
||||
import { CHANGELOG_CATEGORIES } from "./utils/changelog-categories.js";
|
||||
|
||||
const { __dirname } = createEsmUtils(import.meta);
|
||||
|
||||
const prNumberPrompt = new enquirer.NumberPrompt({
|
||||
message: "Input your Pull Request number:",
|
||||
});
|
||||
@@ -37,11 +33,14 @@ assertCategory(category);
|
||||
|
||||
const { title, user } = await getPr(prNumber);
|
||||
|
||||
const newChangelog = await createChangelog(title, user, prNumber, category);
|
||||
const content = await createChangelog(title, user, prNumber, category);
|
||||
|
||||
const changelogPath = await addNewChangelog(prNumber, category, newChangelog);
|
||||
const file = await addNewChangelog(prNumber, category, content);
|
||||
|
||||
const relativePath = file.href.slice(
|
||||
new URL("../", import.meta.url).href.length,
|
||||
);
|
||||
|
||||
const relativePath = path.relative(path.join(__dirname, ".."), changelogPath);
|
||||
console.log("Generated changelog file: " + relativePath);
|
||||
|
||||
/**
|
||||
@@ -73,16 +72,16 @@ async function getPr(prNumber) {
|
||||
/**
|
||||
* @param {number} prNumber
|
||||
* @param {string} category
|
||||
* @param {string} newChangelog
|
||||
* @returns {Promise<string>}
|
||||
* @param {string} content
|
||||
* @returns {Promise<URL>}
|
||||
*/
|
||||
async function addNewChangelog(prNumber, category, newChangelog) {
|
||||
const newChangelogPath = path.resolve(
|
||||
__dirname,
|
||||
async function addNewChangelog(prNumber, category, content) {
|
||||
const file = new URL(
|
||||
`../changelog_unreleased/${category}/${prNumber}.md`,
|
||||
import.meta.url,
|
||||
);
|
||||
await fs.writeFile(newChangelogPath, newChangelog);
|
||||
return newChangelogPath;
|
||||
await fs.writeFile(file, content);
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,14 +89,14 @@ async function addNewChangelog(prNumber, category, newChangelog) {
|
||||
* @param {string} user
|
||||
* @param {number} prNumber
|
||||
* @param {string} string
|
||||
* @returns {string}
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async function createChangelog(title, user, prNumber, category) {
|
||||
const changelogTemplatePath = path.resolve(
|
||||
__dirname,
|
||||
const templateFile = new URL(
|
||||
"../changelog_unreleased/TEMPLATE.md",
|
||||
import.meta.url,
|
||||
);
|
||||
const changelogTemplate = await fs.readFile(changelogTemplatePath, "utf8");
|
||||
const changelogTemplate = await fs.readFile(templateFile, "utf8");
|
||||
|
||||
const titlePart = "Title";
|
||||
const prNumberPart = "#XXXX";
|
||||
|
||||
Reference in new issue
Block a user