npm run demo loads Acacia Hill; --profile/--scenario any of the eight demo churches, around @crosscode/demo's people (the same account ids as Accounts), in the scenario's active-member band: a prayer wall with three months of commitments and the scenario's gaps, a campaign, testimonies, prayer requests, announcements, the church's own devotionals or Cross Code's from the Hub, and events (Cross Events' or the Website's through the feed when linked, else the App's own). The devotionals' passages are copied word for word from the public- domain KJV and BSB by scripts/demo-passages.ts (no Bible text written by hand). The sender never sends anything to a demo person. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
3.8 KiB
TypeScript
69 lines
3.8 KiB
TypeScript
/**
|
|
* Loads a demo scenario into the App (APP-1.0-PLAN §12, src/demo/load.ts).
|
|
*
|
|
* npm run demo Acacia Hill (community-family), for development
|
|
* npm run demo -- --profile <scenario> [--force] one of the eight demo churches
|
|
* npm run demo -- --profile <s> --scenario <s> --force as part of loading that scenario (the Hub, the agent)
|
|
* npm run demo -- --list the scenarios
|
|
*
|
|
* It replaces the App's content and its demo members, so an App with real members (any address not
|
|
* at example.com) needs --force. On a server, `crosscode demo <church> app --profile …` runs it as
|
|
* the App's user, after a backup.
|
|
*/
|
|
import 'dotenv/config';
|
|
import { PrismaPg } from '@prisma/adapter-pg';
|
|
import { agent, DEMO_EMAIL_DOMAIN } 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 { loadDemo } from '../src/demo/load.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.appDemoProfileSchema.safeParse(arg('profile') ?? 'community-family');
|
|
if (!profile.success) {
|
|
console.error(`Unknown profile "${arg('profile')}" (npm run demo -- --list).`);
|
|
process.exit(2);
|
|
}
|
|
// A demo scenario loads the profile of the same name (contracts agent.DEMO_SCENARIOS).
|
|
const scenarioArg = arg('scenario');
|
|
if (scenarioArg !== undefined && scenarioArg !== profile.data) {
|
|
console.error(agent.demoScenarioSchema.safeParse(scenarioArg).success
|
|
? `The ${scenarioArg} scenario loads the ${scenarioArg} profile: --profile ${scenarioArg} --scenario ${scenarioArg}.`
|
|
: `Unknown scenario "${scenarioArg}" (npm run demo -- --list).`);
|
|
process.exit(2);
|
|
}
|
|
|
|
const db = new PrismaClient({ adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL! }) });
|
|
const ctx = createCtx(loadConfig(), db);
|
|
// Real members (the Hub's first Owner, say) are kept; what they made isn't.
|
|
const real = (await db.member.findMany({ where: { NOT: { email: { endsWith: `@${DEMO_EMAIL_DOMAIN}` } } }, select: { id: true } })).map((m) => m.id);
|
|
const where = { memberId: { in: real } };
|
|
const made = (await db.prayerCommitment.count({ where })) + (await db.prayerRequest.count({ where })) + (await db.testimony.count({ where }));
|
|
if (made > 0 && !process.argv.includes('--force')) {
|
|
console.error(`Real members have prayed, asked or shared in this App (${made} in all): loading the demo replaces the prayer wall, requests, announcements and events. Add --force to do it anyway.`);
|
|
await db.$disconnect();
|
|
process.exit(1);
|
|
}
|
|
try {
|
|
const r = await loadDemo(ctx, profile.data);
|
|
console.log(`Demo ${r.scenario} loaded: ${r.church}, ${r.members} members, ${r.commitments} prayer commitments.`);
|
|
const d = r.devotionals;
|
|
if (d.source === 'church') console.log(`The church's own devotionals: ${d.saved}.`);
|
|
else if (d.error) console.warn(`Cross Code's devotionals weren't fetched (${d.error}); the nightly fetch brings them.`);
|
|
else console.log(`Cross Code's devotionals fetched from the Hub: ${d.saved} days.`);
|
|
const e = r.events;
|
|
if (e.from === 'app') console.log(`The App's own events: ${e.made}.`);
|
|
else if (e.sync?.ok) console.log(`Showing ${e.from === 'events' ? 'Cross Events\'' : 'the Website\'s'} events: ${e.sync.imported} fetched.`);
|
|
else console.warn(`${e.from === 'events' ? 'Cross Events\'' : 'The Website\'s'} events couldn't be fetched yet (${e.sync?.error}); the next sync, within 15 minutes, brings them.`);
|
|
} finally {
|
|
await db.$disconnect();
|
|
}
|