import { createHash } from "node:crypto";
import { readFile, writeFile } from "node:fs/promises";
import path from "node:path";
import ts from "typescript";
// Tokens have only type imports. Compile them with the project's TypeScript
// dependency so this works even when Node was built without type stripping.
const { outputText } = ts.transpileModule(
await readFile(
new URL("../../components/src/lib/theme/tokens.ts", import.meta.url),
"utf8",
),
{ compilerOptions: { module: ts.ModuleKind.ESNext } },
);
const {
borderRadius,
colors,
loadingIndicator,
spacing,
surfaces,
textAlphas,
touchTargets,
typeScale,
} = await import(
`data:text/javascript;base64,${Buffer.from(outputText).toString("base64")}`
);
// Expo's shared chunk is eager even when every app screen is lazy. Keep its
// generated bundles intact, but let a tiny bootloader start them after paint.
const output = process.argv[2] ?? "dist";
const htmlPath = path.join(output, "index.html");
let html = await readFile(htmlPath, "utf8");
const scripts = [];
html = html.replace(
/