clone

a deno framework for local-first web apps that open instantly, work offline and sync when users choose

fix/175-template-quality-pass
lofi / package / commands / provision.ts
provision.ts 2.0K
1#!/usr/bin/env -S deno run -A23/**4 * The `deno task jazz:provision` command: generates a managed Jazz app and5 * writes its configuration into `.env`, so the project can offer synced,6 * backed-up accounts. Prints the new app id and how to claim it — never the7 * secrets, which live only in the git-ignored `.env`.8 *9 * @module10 */1112import {13 JAZZ_CLAIM_WINDOW_DAYS,14 JAZZ_DASHBOARD_URL,15 ProvisionError,16 provisionJazzApp,17} from "../tooling/provision.ts";1819function parseArgs(args: string[]): { path: string; force: boolean } {20 let path = ".env";21 let force = false;22 for (let index = 0; index < args.length; index++) {23 const arg = args[index];24 if (arg === "--force") force = true;25 else if (arg === "--env") {26 const value = args[++index];27 if (!value) {28 console.error("usage: deno task jazz:provision [--env <path>] [--force]");29 Deno.exit(2);30 }31 path = value;32 } else {33 console.error(`error: unknown argument ${JSON.stringify(arg)}`);34 console.error("usage: deno task jazz:provision [--env <path>] [--force]");35 Deno.exit(2);36 }37 }38 return { path, force };39}4041const { path, force } = parseArgs(Deno.args);4243try {44 const result = await provisionJazzApp({ path, force });45 console.log(`Provisioned Jazz app ${result.app.appId}`);46 console.log(` Sync server: ${result.serverUrl}`);47 console.log(48 ` ${49 result.replaced ? "Replaced" : "Wrote"50 } JAZZ_APP_ID / JAZZ_SERVER_URL / JAZZ_ADMIN_SECRET / BACKEND_SECRET in ${result.path}`,51 );52 console.log("");53 console.log(54 `Claim this app within ${JAZZ_CLAIM_WINDOW_DAYS} days at ${JAZZ_DASHBOARD_URL} (use the admin`,55 );56 console.log(57 `secret saved in ${result.path}); unclaimed apps expire. Keep ${result.path} private`,58 );59 console.log("— it holds server-only secrets and is already git-ignored.");60} catch (error) {61 if (error instanceof ProvisionError) {62 console.error(`error: ${error.message}`);63 Deno.exit(1);64 }65 console.error(`error: ${error instanceof Error ? error.message : String(error)}`);66 Deno.exit(1);67}