Prune obsolete dist artifacts after builds

This commit is contained in:
NuklearRabbit
2026-07-26 01:03:48 +02:00
parent 3e5e3d2a8b
commit b7daef3cd9
5 changed files with 52 additions and 6 deletions
+41
View File
@@ -0,0 +1,41 @@
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
const projectRoot = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
"..",
);
const distDirectory = path.join(projectRoot, "dist");
const manifest = JSON.parse(
await fs.readFile(path.join(projectRoot, "package.json"), "utf8"),
);
const currentVersion = String(manifest.version || "").trim();
if (!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(currentVersion)) {
throw new Error("package.json contains an invalid release version.");
}
const entries = await fs
.readdir(distDirectory, { withFileTypes: true })
.catch((error) => {
if (error.code === "ENOENT") return [];
throw error;
});
const removed = [];
for (const entry of entries) {
if (!entry.isFile() || !entry.name.startsWith("ForgeFlow-")) continue;
if (entry.name.includes(`-${currentVersion}-`)) continue;
await fs.rm(path.join(distDirectory, entry.name), { force: true });
removed.push(entry.name);
}
if (removed.length) {
console.log(`Removed ${removed.length} obsolete dist artifact(s):`);
for (const name of removed) console.log(`- ${name}`);
} else {
console.log(
`No ForgeFlow dist artifacts older than ${currentVersion} found.`,
);
}
+1
View File
@@ -46,6 +46,7 @@ const required = [
"scripts/validate-installed-connections.cjs",
"scripts/publish-binary-release.cjs",
"scripts/write-release-checksums.mjs",
"scripts/prune-dist.mjs",
"scripts/generate-source-manifest.mjs",
"setup-windows.ps1",
"START-FORGEFLOW-OVERLAY.ps1",