| 1 | #!/usr/bin/env node |
| 2 | // Require existing storage identities before cf deploy can provision namespaces. |
| 3 | import { convertToWranglerConfig, loadAndParseConfig } from "@cloudflare/config"; |
| 4 | import { fileURLToPath } from "node:url"; |
| 5 | |
| 6 | const { result } = await loadAndParseConfig(fileURLToPath(new URL("../cloudflare.config.ts", import.meta.url)), { |
| 7 | isPreview: false, |
| 8 | mode: undefined, |
| 9 | }); |
| 10 | if (!result.success) throw new Error(`Invalid Cloudflare configuration: ${result.error}`); |
| 11 | let dirty = false; |
| 12 | for (const ns of convertToWranglerConfig(result.data).kv_namespaces ?? []) { |
| 13 | if (!/^[a-f0-9]{32}$/i.test(ns.id ?? "")) { |
| 14 | dirty = true; |
| 15 | console.error("KV namespace %s needs its existing namespace ID in cloudflare.config.ts.", ns.binding); |
| 16 | } |
| 17 | } |
| 18 | if (dirty) process.exit(1); |
| 19 | console.log("All KV namespace IDs are set."); |
| 20 |