| 1 | #!/usr/bin/env node |
| 2 | // OpenNext still reads the legacy config shape. Derive it with Cloudflare's |
| 3 | // converter, keeping cloudflare.config.ts as the only Worker configuration. |
| 4 | import { convertToWranglerConfig, loadAndParseConfig } from "@cloudflare/config"; |
| 5 | import { mkdirSync, writeFileSync } from "node:fs"; |
| 6 | import { resolve } from "node:path"; |
| 7 | |
| 8 | const { result } = await loadAndParseConfig(resolve("cloudflare.config.ts"), { |
| 9 | isPreview: false, |
| 10 | mode: undefined, |
| 11 | }); |
| 12 | if (!result.success) throw new Error(`Invalid Cloudflare configuration: ${result.error}`); |
| 13 | const config = convertToWranglerConfig(result.data); |
| 14 | config.main = resolve(config.main); |
| 15 | config.assets = { ...config.assets, directory: resolve(".open-next/assets") }; |
| 16 | mkdirSync(".cloudflare", { recursive: true }); |
| 17 | writeFileSync(".cloudflare/opennext.json", `${JSON.stringify(config, null, 2)}\n`); |
| 18 |