From afe795edd588b823e5459a6762f787152a49a8cb Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Wed, 16 Jul 2025 08:37:25 -0500 Subject: [PATCH] feat(scripts): 2 new scripts for the build process --- scripts/get-changelog-entry.js | 42 ++++++++++++++++++++++++++++++++++ scripts/read-build-number.js | 24 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 scripts/get-changelog-entry.js create mode 100644 scripts/read-build-number.js diff --git a/scripts/get-changelog-entry.js b/scripts/get-changelog-entry.js new file mode 100644 index 0000000..76324f2 --- /dev/null +++ b/scripts/get-changelog-entry.js @@ -0,0 +1,42 @@ +import fs from "fs-extra"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const version = process.argv[2]; +if (!version) { + console.error("Version argument is required"); + process.exit(1); +} + +async function getChangelogEntry() { + try { + const changelogPath = path.resolve(__dirname, "../../CHANGELOG.md"); + const content = await fs.readFile(changelogPath, "utf8"); + + // Find the section for this version + const versionHeader = `## [${version}]`; + const sections = content.split(versionHeader); + + if (sections.length < 2) { + console.warn(`No changelog entry found for version ${version}`); + return `Release ${version}`; + } + + // Extract the content for this version + const versionContent = sections[1].split("\n## ")[0].trim(); + + // Add the version header back + return `${versionHeader}\n${versionContent}`; + } catch (error) { + console.error("Error reading changelog:", error); + return `Release ${version}`; + } +} + +// Output the changelog entry (release-it will capture this stdout) +getChangelogEntry() + .then(console.log) + .catch(() => process.exit(1)); diff --git a/scripts/read-build-number.js b/scripts/read-build-number.js new file mode 100644 index 0000000..97d8813 --- /dev/null +++ b/scripts/read-build-number.js @@ -0,0 +1,24 @@ +/** + * This is for release-it to be able to post the new build number in the releases + */ + +import fs from "fs-extra"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +async function readBuildNumber() { + try { + const buildNumberPath = path.resolve(__dirname, "../BUILD_NUMBER"); + const buildNumber = (await fs.readFile(buildNumberPath, "utf8")).trim(); + process.env.BUILD_NUMBER = buildNumber; + console.log(`Build number: ${buildNumber}`); + } catch (error) { + console.error("Error reading BUILD_NUMBER:", error); + process.exit(1); + } +} + +readBuildNumber();