24 lines
1.4 KiB
JavaScript
24 lines
1.4 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { createHash } from "node:crypto";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
export function assembleDesktopRelease(root) {
|
|
const directory = path.join(root, ".desktop-release");
|
|
const manifestPath = path.join(directory, "manifest.json");
|
|
if (!fs.existsSync(manifestPath)) return;
|
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
if (!/^MineGeo-[\d.]+-windows-x64\.exe$/.test(manifest.name)) throw new Error("Invalid desktop release name");
|
|
if (!Number.isInteger(manifest.parts) || manifest.parts < 1 || manifest.parts > 100) throw new Error("Invalid desktop release parts");
|
|
const binary = Buffer.concat(Array.from({ length: manifest.parts }, (_, i) => fs.readFileSync(path.join(directory, `part-${i}`))));
|
|
if (binary.length !== manifest.bytes || createHash("sha256").update(binary).digest("hex") !== manifest.sha256) throw new Error("Desktop release checksum mismatch");
|
|
const destination = path.join(root, "public", "desktop");
|
|
fs.mkdirSync(destination, { recursive: true });
|
|
fs.writeFileSync(path.join(destination, manifest.name), binary);
|
|
console.log(`Verified and assembled desktop release: ${manifest.name}`);
|
|
}
|
|
|
|
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
assembleDesktopRelease(path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."));
|
|
}
|