MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / writePreviewConfig

Function writePreviewConfig

apps/host-cloudflare/scripts/preview.ts:201–216  ·  view source on GitHub ↗
(worker: string, databaseName: string, databaseId: string)

Source from the content-addressed store, hash-verified

199 * silently deploying previews against the wrong resources.
200 */
201const 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

Callers 1

deployFunction · 0.85

Calls 2

substituteFunction · 0.85
resolveFunction · 0.50

Tested by

no test coverage detected