Something went wrong. Try again.
r/place on the atmosphere, targeting cloudflare's free tier
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445// Builds and deploys with this operator's settings from deploy.env (see// deploy.env.example), so wrangler.jsonc stays generic. Run with `pnpm run deploy`;// extra arguments go to wrangler, e.g. `pnpm run deploy -- --dry-run`.
import { spawnSync } from "node:child_process";import { existsSync } from "node:fs";import { parseAtUri } from "../src/shared/aturi.ts";import { CANVAS_NSID } from "../src/shared/lexicon.ts";
const ENV_FILE = "deploy.env";// Worker vars an operator may set; anything unset keeps its wrangler.jsonc default.const OVERRIDABLE_VARS = ["MAX_WIDTH", "MAX_HEIGHT", "MAX_PALETTE_SIZE", "MIN_COOLDOWN_SECONDS"];
if (existsSync(ENV_FILE)) process.loadEnvFile(ENV_FILE);
const canvases = (process.env.CANVAS_ALLOWLIST ?? "").split(",").map((s) => s.trim()).filter(Boolean);if (canvases.length === 0) fail(`set CANVAS_ALLOWLIST in ${ENV_FILE}`);for (const uri of canvases) { if (parseAtUri(uri)?.collection !== CANVAS_NSID) fail(`not a ${CANVAS_NSID} AT-URI: ${uri}`);}
const args = ["deploy", "--var", `CANVAS_ALLOWLIST:${canvases.join(",")}`];for (const name of OVERRIDABLE_VARS) { const value = process.env[name]; if (value) args.push("--var", `${name}:${value}`);}// Without a domain, the Worker is only reachable on workers.dev.if (process.env.DEPLOY_DOMAIN) args.push("--domain", process.env.DEPLOY_DOMAIN);// pnpm forwards the `--` separator itself; wrangler would treat flags after it as positional.args.push(...process.argv.slice(2).filter((arg, i) => !(i === 0 && arg === "--")));
run("vite", ["build"]);run("wrangler", args);
// Through pnpm so the project's pinned binaries run, not global ones.function run(command: string, commandArgs: string[]): void { const { status } = spawnSync("pnpm", ["exec", command, ...commandArgs], { stdio: "inherit" }); if (status !== 0) process.exit(status ?? 1);}
function fail(message: string): never { console.error(`deploy: ${message}`); process.exit(1);}