/** * Loads a demo scenario's church and people into Accounts (1.9.0, docs/APP-1.0-PLAN.md §12). * * npm run demo -- --profile [--scenario ] --force * npm run demo -- --list * * It replaces the church profile and the demo people, so it needs --force. On a server, * `crosscode demo accounts --profile …` runs it (backup first), for the Hub's demo sites; * Accounts loads first in a scenario, then Cross Events, the Website and the App. */ import 'dotenv/config'; import { PrismaPg } from '@prisma/adapter-pg'; import { agent } from '@crosscode/contracts'; import { PrismaClient } from '../src/generated/prisma/client.js'; import { createCtx } from '../src/context.js'; import { loadConfig } from '../src/lib/config.js'; import { loadScenario } from '../src/demo/scenario.js'; const arg = (name: string) => { const i = process.argv.indexOf(`--${name}`); return i > 0 ? process.argv[i + 1] : undefined; }; if (process.argv.includes('--list')) { for (const s of agent.DEMO_SCENARIOS) console.log(`${s.key.padEnd(18)} ${s.label}`); process.exit(0); } const profile = agent.demoScenarioSchema.safeParse(arg('profile')); if (!profile.success) { console.error(`Usage: npm run demo -- --profile --force (one of ${agent.DEMO_SCENARIO_KEYS.join(', ')}; --list)`); process.exit(2); } const scenario = arg('scenario'); if (scenario !== undefined && scenario !== profile.data) { console.error(`--scenario ${scenario} loads ${agent.demoScenario(agent.demoScenarioSchema.parse(scenario)).profiles.accounts} in Accounts, not ${profile.data}.`); process.exit(2); } if (!process.argv.includes('--force')) { console.error('This replaces the church profile and the demo people. Add --force to do it (demo sites only).'); process.exit(1); } const db = new PrismaClient({ adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL! }) }); const ctx = createCtx(loadConfig(), db); try { const r = await loadScenario(ctx, profile.data); console.log(`${r.church} loaded: ${r.people} people (${r.created} new, ${r.updated} brought back, ${r.removed} from before removed). The linked products are told the church changed.`); } finally { await db.$disconnect(); }