Eight demo churches, two per template (the second on the template's other recommended variants and header), loaded from the Hub on demo sites with `crosscode demo <church> website --profile <p>`. A profile replaces the content only: the church's profile from Accounts, the site settings, the site icon and the admins stay, and the copy names the church. - contracts: WEBSITE_DEMO_PROFILES, DEMO_PRODUCTS, SEED_WEBSITE_DEMO_MIN_AGENT; seed-demo takes an optional product (events by default) - agent: a Website seed-demo job runs `crosscode demo <church> website` - crosscode script: backup, demo as the site's user, reload, health check Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2.4 KiB
TypeScript
49 lines
2.4 KiB
TypeScript
/**
|
|
* Loads a demo into the site and publishes it.
|
|
*
|
|
* npm run demo -- --template heritage|bold|community|clean [--force] the Acacia Hill church (development)
|
|
* npm run demo -- --profile <profile> [--force] one of the eight demo churches (1.3.0),
|
|
* keeping the church's profile and settings
|
|
* npm run demo -- --list the profiles
|
|
*
|
|
* It replaces the site's content, so a site that has been published needs --force. On a server,
|
|
* `crosscode demo <church> website --profile …` runs it (backup first), for the Hub's demo sites.
|
|
*/
|
|
import 'dotenv/config';
|
|
import { PrismaPg } from '@prisma/adapter-pg';
|
|
import { agent, 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 { demoSeeds } from '../src/demo/seeds.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 usage = 'Usage: npm run demo -- --template heritage|bold|community|clean | --profile <profile> [--force] | --list';
|
|
|
|
if (process.argv.includes('--list')) {
|
|
for (const s of demoSeeds()) console.log(`${s.id.padEnd(18)} ${s.label}`);
|
|
process.exit(0);
|
|
}
|
|
const profileArg = arg('profile');
|
|
const what = profileArg !== undefined ? agent.websiteDemoProfileSchema.safeParse(profileArg) : websiteTemplateSchema.safeParse(arg('template') ?? 'heritage');
|
|
if (!what.success) {
|
|
console.error(profileArg !== undefined ? `Unknown profile "${profileArg}" (npm run demo -- --list).` : usage);
|
|
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, what.data);
|
|
console.log(`Demo ${what.data} loaded and published (version ${version.number}).`);
|
|
await db.$disconnect();
|