8080 working-directory : ${{ runner.temp }}/cna-cloudflare
8181 run : >-
8282 vp exec vinext init --skip-check --platform=cloudflare
83+ --cdn-cache=data-cache
8384 --data-cache=kv
8485 --image-optimization=cloudflare-images
8586
@@ -88,16 +89,18 @@ jobs:
8889 run : |
8990 node -e '
9091 const fs = require("node:fs");
91- const configPath = "wrangler.jsonc";
92- const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
93- config.name = process.env.CNA_CLOUDFLARE_WORKER;
94- config.preview_urls = true;
95- for (const namespace of config.kv_namespaces ?? []) {
96- if (namespace.binding === "VINEXT_KV_CACHE") {
97- namespace.id = process.env.CNA_CLOUDFLARE_KV_NAMESPACE_ID;
98- }
99- }
100- fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
92+ const configPath = "cloudflare.config.ts";
93+ const config = fs.readFileSync(configPath, "utf8")
94+ .replace(
95+ "name: \"cna-cloudflare\",",
96+ "name: " + JSON.stringify(process.env.CNA_CLOUDFLARE_WORKER) + ",\n previewUrls: true,",
97+ )
98+ // Reuse the CI namespace even when init emits bindings.kv().
99+ .replace(
100+ /VINEXT_KV_CACHE: bindings\.kv\([^)]*\)/,
101+ "VINEXT_KV_CACHE: bindings.kv({ id: " + JSON.stringify(process.env.CNA_CLOUDFLARE_KV_NAMESPACE_ID) + " })",
102+ );
103+ fs.writeFileSync(configPath, config);
101104 '
102105
103106 - name : Build generated Cloudflare project
@@ -106,7 +109,11 @@ jobs:
106109
107110 - name : Verify generated Cloudflare build output
108111 working-directory : ${{ runner.temp }}/cna-cloudflare
109- run : test -f dist/server/wrangler.json
112+ run : |
113+ test -f cloudflare.config.ts
114+ test -f .cloudflare/output/v0/config.json
115+ test -f .cloudflare/output/v0/workers/default/worker.config.json
116+ test ! -f wrangler.jsonc
110117
111118 - name : Deploy generated Cloudflare project
112119 working-directory : ${{ runner.temp }}/cna-cloudflare
0 commit comments