prepare-sites-build.mjs 910 B

12345678910111213141516171819202122
  1. #!/usr/bin/env node
  2. import { copyFileSync, existsSync, mkdirSync } from "node:fs";
  3. import path from "node:path";
  4. import { fileURLToPath } from "node:url";
  5. const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
  6. const dist = path.join(root, "dist");
  7. const index = path.join(dist, "client", "index.html");
  8. const worker = path.join(root, "worker", "index.js");
  9. const hosting = path.join(root, ".openai", "hosting.json");
  10. for (const file of [index, worker, hosting]) {
  11. if (!existsSync(file)) throw new Error("Missing Sites build input: " + file);
  12. }
  13. mkdirSync(path.join(dist, "server"), { recursive: true });
  14. mkdirSync(path.join(dist, ".openai"), { recursive: true });
  15. copyFileSync(worker, path.join(dist, "server", "index.js"));
  16. copyFileSync(hosting, path.join(dist, ".openai", "hosting.json"));
  17. console.log("Prepared Sites build: dist/server/index.js and dist/.openai/hosting.json");