feat(scripts): 2 new scripts for the build process
This commit is contained in:
42
scripts/get-changelog-entry.js
Normal file
42
scripts/get-changelog-entry.js
Normal file
@@ -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));
|
||||
24
scripts/read-build-number.js
Normal file
24
scripts/read-build-number.js
Normal file
@@ -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();
|
||||
Reference in New Issue
Block a user