diff --git a/scripts/generate-changelog.js b/scripts/generate-changelog.js index ac58cacd3..f2912f246 100755 --- a/scripts/generate-changelog.js +++ b/scripts/generate-changelog.js @@ -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} + * @param {string} content + * @returns {Promise} */ -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} */ 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";