1// Regenerates src/bots.ts from the readable bot sources in bots/*.js.2// The .js files are the source of truth; src/bots.ts is a checked-in build3// artifact so every bundler (Vite, Workers, vitest) gets the sources as plain4// exported strings with zero loader configuration.5//6// Run from the package root: node scripts/gen-bots.mjs7import { readFileSync, writeFileSync } from "node:fs";8import { dirname, join } from "node:path";9import { fileURLToPath } from "node:url";1011const pkgRoot = join(dirname(fileURLToPath(import.meta.url)), "..");12const bots = ["homesteader", "bulwark", "warlord", "magnate", "primitives"];1314const escape = (src) => src.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");1516let out = `// GENERATED FILE — do not edit by hand.17// Source of truth: ../bots/*.js. Regenerate with: node scripts/gen-bots.mjs18`;19for (const name of bots) {20 const src = readFileSync(join(pkgRoot, "bots", `${name}.js`), "utf8");21 out += `\nexport const ${name}Source = \`${escape(src)}\`;\n`;22}23// Note: primitivesSource (exported by the loop above) is a helper library,24// not a runnable bot — keep it out of referenceBots.25out += `\nexport const referenceBots = { homesteader: homesteaderSource, bulwark: bulwarkSource, warlord: warlordSource, magnate: magnateSource } as const;\n`;2627writeFileSync(join(pkgRoot, "src", "bots.ts"), out);28console.log("wrote src/bots.ts");