/** * Loads the demo church (src/demo/demoChurch.ts) into a template and publishes it. * * npm run demo -- --template heritage|bold|community|clean [--force] * * It replaces the site's content, so a site that has been published needs --force. */ import 'dotenv/config'; import { PrismaPg } from '@prisma/adapter-pg'; import { websiteTemplateSchema } from '@crosscode/contracts'; import { PrismaClient } from '../src/generated/prisma/client.js'; import { createCtx } from '../src/context.js'; import { loadDemo } from '../src/demo/demoChurch.js'; import { loadConfig } from '../src/lib/config.js'; const arg = (name: string) => { const i = process.argv.indexOf(`--${name}`); return i > 0 ? process.argv[i + 1] : undefined; }; const template = websiteTemplateSchema.safeParse(arg('template') ?? 'heritage'); if (!template.success) { console.error('Usage: npm run demo -- --template heritage|bold|community|clean [--force]'); process.exit(2); } const db = new PrismaClient({ adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL! }) }); const ctx = createCtx(loadConfig(), db); const published = await db.siteVersion.findFirst({ where: { NOT: { publishedBy: 'demo' } } }); if (published && !process.argv.includes('--force')) { console.error('This site has been published by its admins: loading the demo would replace their content. Add --force to do it anyway.'); await db.$disconnect(); process.exit(1); } const version = await loadDemo(ctx, template.data); console.log(`Demo church loaded on ${template.data} and published (version ${version.number}).`); await db.$disconnect();