Exact source used by this build. SHA-256: 578bc9286eb9254f1208a80d7be5032db8fdcdda7e11271796f1a7ca8804cd8d.
1 // Build-time only: no filesystem API enters the browser, Worker or pure simulation.
2 import { readdir, mkdir, writeFile } from "node:fs/promises";
3 const root = new URL("../../../", import.meta.url);
4 for (const domain of ["items", "crops"]) {
5 const directory = new URL(`data/${domain}/`, root);
6 const paths = (await readdir(directory, { recursive: true })).filter((path) => path.endsWith(".json")).sort();
7 const entries = (await Promise.all(paths.map(async (path) => {
8 const value: unknown = await Bun.file(new URL(path, directory)).json();
9 return Array.isArray(value) ? value : [value];
10 }))).flat();
11 await mkdir(new URL("generated/", root), { recursive: true });
12 const destination = new URL(`generated/${domain}.json`, root), serialized = JSON.stringify(entries);
13 // Repeated typechecks/builds must not restart an otherwise unchanged dev server.
14 const previous = Bun.file(destination);
15 if (!await previous.exists() || await previous.text() !== serialized) await writeFile(destination, serialized);
16 }
17