// Embeds assets/reader (css, js, fonts) into a TS module for iOS, where WKWebView cannot // load file:// subresources into a chapter whose base URL is the source's site. // Run by `pnpm postinstall` and the iOS build script; the output is not committed. import { readdirSync, readFileSync, writeFileSync } from 'node:fs'; import { join, parse } from 'node:path'; const root = join(import.meta.dirname, '..', 'assets', 'reader'); const read = (dir, encoding) => Object.fromEntries( readdirSync(join(root, dir)).sort().map(file => [parse(file).name, readFileSync(join(root, dir, file), encoding)]), ); const out = join(import.meta.dirname, '..', 'src', 'utils', 'readerAssets', 'embedded.generated.ts'); writeFileSync( out, '// Generated by scripts/embed-reader-assets.mjs from assets/reader. Do not edit.\n' + `export const css: Record = ${JSON.stringify(read('css', 'utf8'))};\n` + `export const js: Record = ${JSON.stringify(read('js', 'utf8'))};\n` + `export const fonts: Record = ${JSON.stringify(read('fonts', 'base64'))};\n`, ); console.log(`reader assets embedded: ${out}`);