// Writes dist/ui-manifest.json after `vite build`: every file of the build with its size and SHA-256, the version and // when it was built. The desktop app keeps the interface on disk and reads this to download only what changed // (apps/desktop/src-tauri/src/ui.rs). import { createHash } from "node:crypto"; import { readdir, readFile, stat, writeFile } from "node:fs/promises"; import path from "node:path"; import { fileURLToPath } from "node:url"; const NAME = "ui-manifest.json"; const dist = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../dist"); async function walk(dir) { const out = []; for (const entry of await readdir(dir, { withFileTypes: true })) { const full = path.join(dir, entry.name); if (entry.isDirectory()) out.push(...(await walk(full))); else if (entry.isFile()) out.push(full); } return out; } const files = []; for (const full of (await walk(dist)).sort()) { const rel = path.relative(dist, full).split(path.sep).join("/"); if (rel === NAME) continue; const bytes = await readFile(full); files.push({ path: rel, size: (await stat(full)).size, sha256: createHash("sha256").update(bytes).digest("hex") }); } const content = createHash("sha256").update(files.map((f) => `${f.path}:${f.sha256}`).join("\n")).digest("hex").slice(0, 16); const manifest = { version: process.env.VITE_APP_VERSION?.slice(0, 40) || content, builtAt: new Date().toISOString(), files }; await writeFile(path.join(dist, NAME), JSON.stringify(manifest)); console.log(`${NAME}: ${files.length} files, version ${manifest.version}`);