Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

43 lines · 2.0 KB · executableRaw History
1#!/usr/bin/env node
2// Render apps/diffinery/wrangler.deploy.jsonc from wrangler.jsonc plus values
3// discovered by scripts/bootstrap.sh (real D1 id, Access team domain and AUD).
4//
5// node scripts/render-config.mjs --d1 <uuid> [--team <x.cloudflareaccess.com>] [--aud <tag>]
6import { readFileSync, writeFileSync } from "node:fs";
7import { dirname, join } from "node:path";
8import { fileURLToPath } from "node:url";
9import { parseArgs } from "node:util";
10
11const { values } = parseArgs({ options: { d1: { type: "string" }, team: { type: "string" }, aud: { type: "string" }, "public-url": { type: "string" } } });
12if (!values.d1) throw new Error("--d1 <database id> is required");
13
14/** Strip // and /* *\/ comments and trailing commas from JSONC, leaving strings intact. */
15export function parseJsonc(text) {
16 let out = "";
17 for (let i = 0; i < text.length; i++) {
18 const ch = text[i];
19 if (ch === '"') {
20 let j = i + 1;
21 while (j < text.length && text[j] !== '"') j += text[j] === "\\" ? 2 : 1;
22 out += text.slice(i, j + 1);
23 i = j;
24 } else if (ch === "/" && text[i + 1] === "/") {
25 while (i < text.length && text[i] !== "\n") i++;
26 out += "\n";
27 } else if (ch === "/" && text[i + 1] === "*") {
28 i = text.indexOf("*/", i + 2) + 1;
29 } else out += ch;
30 }
31 return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
32}
33
34const appDir = join(dirname(fileURLToPath(import.meta.url)), "..", "apps", "diffinery");
35const cfg = parseJsonc(readFileSync(join(appDir, "wrangler.jsonc"), "utf8"));
36delete cfg.env;
37delete cfg.$schema;
38cfg.d1_databases[0].database_id = values.d1;
39if (values.team) cfg.vars.ACCESS_TEAM_DOMAIN = values.team;
40if (values.aud) cfg.vars.ACCESS_AUD = values.aud;
41if (values["public-url"]) cfg.vars.PUBLIC_URL = values["public-url"];
42writeFileSync(join(appDir, "wrangler.deploy.jsonc"), `// Generated by scripts/render-config.mjs; do not edit.\n${JSON.stringify(cfg, null, 2)}\n`);
43console.log(`wrote ${join(appDir, "wrangler.deploy.jsonc")}`);