(worker: string, databaseName: string, databaseId: string)
| 199 | * silently deploying previews against the wrong resources. |
| 200 | */ |
| 201 | const writePreviewConfig = (worker: string, databaseName: string, databaseId: string): string => { |
| 202 | const basePath = resolve(APP_DIR, "wrangler.jsonc"); |
| 203 | let text = readFileSync(basePath, "utf8"); |
| 204 | const substitute = (pattern: RegExp, replacement: string): void => { |
| 205 | if (!pattern.test(text)) |
| 206 | fail(`wrangler.jsonc no longer matches ${pattern} — update preview.ts`); |
| 207 | text = text.replace(pattern, replacement); |
| 208 | }; |
| 209 | substitute(/"name":\s*"executor-cloudflare"/, `"name": "${worker}"`); |
| 210 | substitute(/"database_name":\s*"[^"]*"/, `"database_name": "${databaseName}"`); |
| 211 | substitute(/"database_id":\s*"[^"]*"/, `"database_id": "${databaseId}"`); |
| 212 | substitute(/"bucket_name":\s*"[^"]*"/, `"bucket_name": "${SHARED_BLOBS_BUCKET}"`); |
| 213 | const outPath = resolve(APP_DIR, "wrangler.preview.jsonc"); |
| 214 | writeFileSync(outPath, `// Generated by scripts/preview.ts — do not edit.\n${text}`); |
| 215 | return outPath; |
| 216 | }; |
| 217 | |
| 218 | // --- commands ---------------------------------------------------------------- |
| 219 |
no test coverage detected