import { mkdir, readFile, writeFile } from "node:fs/promises"; // BiImage and AppHeader both depend on the same processImage utility. // Rollup can otherwise move it to a shared chunk, leaving a downloadable // BiImage.js with an extra network dependency. Keep this file self-contained // while deriving the implementation DIRECTLY from the library utility source. const remoteSource = await readFile("src/remote/ui/BiImage/BiImage.remote.js", "utf8"); const utilitySource = await readFile("src/utils/images.js", "utf8"); const styleSource = await readFile("src/remote/ui/BiImage/style-props.js", "utf8"); const styleImport = 'import { createImagePresentation, imagePresentationCSS } from "./style-props.js";'; const remoteImport = 'import { processImage } from "../../../utils/images.js";'; const utilityExport = "export const processImage ="; if (!remoteSource.includes(remoteImport) || !remoteSource.includes(styleImport) || !utilitySource.includes(utilityExport)) { throw new Error("BiImage remote or processImage signature has changed; update the standalone remote builder."); } const remoteJs = remoteSource .replace(remoteImport, utilitySource.replace(utilityExport, "const processImage =").trim()) .replace(styleImport, styleSource.replace(/export (const|function) /g, "$1 ").trim()); await mkdir("dist/remote", { recursive: true }); await writeFile("dist/remote/BiImage.js", remoteJs);