52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
const [manifestPath, singleDirectory, pthreadDirectory] = process.argv.slice(2);
|
|
if (!manifestPath || !singleDirectory || !pthreadDirectory) {
|
|
throw new Error(
|
|
"usage: update-engine-manifest.mjs <manifest.json> <single-directory> <pthread-directory>",
|
|
);
|
|
}
|
|
|
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
if (typeof manifest.engineVersion !== "string" || manifest.engineVersion.length === 0) {
|
|
throw new Error("engineVersion is missing from the existing engine manifest");
|
|
}
|
|
|
|
function resource(directory, variant, fileName) {
|
|
const filePath = path.join(directory, fileName);
|
|
const bytes = fs.readFileSync(filePath);
|
|
if (bytes.byteLength === 0) throw new Error(`${variant} ${fileName} is empty`);
|
|
return {
|
|
fileName,
|
|
url: `/vendor/blender/${variant}/${fileName}`,
|
|
sha256: crypto.createHash("sha256").update(bytes).digest("hex"),
|
|
};
|
|
}
|
|
|
|
const singleJs = resource(singleDirectory, "single", "web_engine.js");
|
|
const singleWasm = resource(singleDirectory, "single", "web_engine.wasm");
|
|
const pthreadJs = resource(pthreadDirectory, "pthread", "web_engine.js");
|
|
const pthreadWasm = resource(pthreadDirectory, "pthread", "web_engine.wasm");
|
|
const updated = {
|
|
schemaVersion: 2,
|
|
protocolVersion: 1,
|
|
releaseId: typeof manifest.releaseId === "string" ? manifest.releaseId : manifest.engineVersion,
|
|
engineVersion: manifest.engineVersion,
|
|
engine: "blender-wasm",
|
|
variants: [
|
|
{
|
|
id: "single",
|
|
memory: { initialPages: 256, maximumPages: 32768, shared: false },
|
|
resources: { js: singleJs, wasm: singleWasm },
|
|
},
|
|
{
|
|
id: "pthread",
|
|
memory: { initialPages: 256, maximumPages: 32768, shared: true },
|
|
resources: { js: pthreadJs, wasm: pthreadWasm, pthreadWorker: pthreadJs },
|
|
},
|
|
],
|
|
};
|
|
fs.writeFileSync(manifestPath, `${JSON.stringify(updated, null, 2)}\n`);
|