Files

88 lines
2.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import fs from "fs";
import path from "path";
import { ZipArchive } from "archiver";
const GITEA_URL = process.env.GITEA_URL;
const REPO = process.env.GITEA_REPOSITORY;
const RELEASE_TAG = process.env.GITEA_REF_NAME || "v1.0.0";
const systemJsonPath = path.resolve("./system.json");
const packageJsonPath = path.resolve("./package.json");
// Version aus dem Tag extrahieren (z.B. "v1.2.3" -> "1.2.3")
const cleanVersion = RELEASE_TAG.replace(/^v/, "");
// 1. system.json aktualisieren
if (fs.existsSync(systemJsonPath)) {
const systemJson = JSON.parse(fs.readFileSync(systemJsonPath, "utf8"));
systemJson.version = cleanVersion;
systemJson.manifest = `${GITEA_URL}/${REPO}/releases/download/latest/system.json`;
systemJson.download = `${GITEA_URL}/${REPO}/releases/download/${RELEASE_TAG}/midgard6-lvd.zip`;
fs.writeFileSync(systemJsonPath, JSON.stringify(systemJson, null, 2));
console.log(
`\x1b[32m✅ system.json erfolgreich auf Version ${cleanVersion} aktualisiert.\x1b[0m`,
);
} else {
console.error(`\x1b[31m❌ system.json nicht gefunden unter: ${systemJsonPath}\x1b[0m`);
}
// 2. package.json aktualisieren
if (fs.existsSync(packageJsonPath)) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
packageJson.version = cleanVersion;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log(
`\x1b[32m✅ package.json erfolgreich auf Version ${cleanVersion} aktualisiert.\x1b[0m`,
);
} else {
console.log(`\x1b[33m⚠️ package.json nicht gefunden – Schritt übersprungen.\x1b[0m`);
}
// 3. zip-Archiv für Foundry erstellen
async function zipDirectory(sourceDir, outPath) {
const archive = new ZipArchive("zip", { zlib: { level: 9 } });
const stream = fs.createWriteStream(outPath);
return new Promise((resolve, reject) => {
stream.on("close", () => {
resolve();
});
archive.on("error", (err) => reject(err));
archive.pipe(stream);
archive.directory(sourceDir, false);
archive.finalize();
});
}
const zipTmpDir = path.resolve("./build-zip");
if (fs.existsSync(zipTmpDir)) {
fs.rmSync(zipTmpDir, { recursive: true, force: true });
}
fs.mkdirSync(zipTmpDir);
const filesToInclude = ["system.json", "templates", "dist", "lang", "assets"];
for (const file of filesToInclude) {
if (fs.existsSync(file)) {
const dest = path.join(zipTmpDir, file);
fs.mkdirSync(path.dirname(dest), { recursive: true });
if (fs.lstatSync(file).isDirectory()) {
fs.cpSync(file, dest, { recursive: true });
} else {
fs.copyFileSync(file, dest);
}
}
}
await zipDirectory(zipTmpDir, "./midgard6-lvd.zip");
console.log("\x1b[32m✅ system.zip wurde erfolgreich generiert.\x1b[0m");
fs.rmSync(zipTmpDir, { recursive: true, force: true });