// bun tools/pack.ts: the parts `raea make component add` copies in (every folder of examples/parts, a set each: brand, reel ...) and // the project template as strings in src/registry.gen.ts, so `raea make component add` and `raea init` work inside the shell (raea's // V8 reads only the project folder, not this package). Run after changing either; `bun test` fails when the generated // file is stale. A set's tests (*.test.ts) stay behind: they check the example, not a project. import { readdirSync, readFileSync, writeFileSync } from "fs"; import { join } from "path"; const here = join(import.meta.dir, ".."); const PARTS = "../../examples/parts"; const read = (dir: string) => Object.fromEntries( readdirSync(join(here, dir), { withFileTypes: true }) .filter((e) => e.isFile() && !e.name.startsWith(".") && !e.name.includes(".gen.") && !e.name.includes(".test.")) .map((e) => e.name) .sort() .map((f) => [f, readFileSync(join(here, dir, f), "utf8")]), ); export function generated(): string { const sets = readdirSync(join(here, PARTS), { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort(); const registry = Object.fromEntries(sets.map((s) => [s, read(`${PARTS}/${s}`)])); const template = read("template"); return `// generated by tools/pack.ts from examples/parts/ and template/: don't edit, run \`bun tools/pack.ts\`\nexport const REGISTRY: Record> = ${JSON.stringify(registry, null, 2)};\nexport const TEMPLATE: Record = ${JSON.stringify(template, null, 2)};\n`; } if (import.meta.main) writeFileSync(join(here, "src/registry.gen.ts"), generated());