Demo data from the Hub: crosscode demo, the seed-demo job, set-demo fixes
- scripts: `crosscode demo <church> --profile … [--admin-email …]`: backup, set-demo.js as the site's user, reload, wait for /health. - Contracts 1.7.0: the seed-demo job, DEMO_PROFILES, SEED_DEMO_MIN_AGENT. - Agent 1.2.0: seed-demo → crosscode demo. - Events 2.4.1: set-demo.js stops with a clear message when it can't read .env (was "client password must be a string", then a hang); keeps the oldest admin when the default one isn't on the site; --admin-email=. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
{
|
||||
"name": "@crosscode/agent",
|
||||
"version": "1.1.1",
|
||||
"version": "1.2.0",
|
||||
"private": true,
|
||||
"description": "The server agent: runs the crosscode script for signed jobs from Cross Code Hub, reports stats (docs/AGENT-1.0-PLAN.md)",
|
||||
"license": "UNLICENSED",
|
||||
"bin": { "crosscode-agent": "./dist/cli.js" },
|
||||
"bin": {
|
||||
"crosscode-agent": "./dist/cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||
@@ -14,5 +16,7 @@
|
||||
"@crosscode/contracts": "*",
|
||||
"zod": "^4.6.7"
|
||||
},
|
||||
"engines": { "node": ">=24" }
|
||||
"engines": {
|
||||
"node": ">=24"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ export function crosscodeArgs(job: agent.AgentJob, opts: { exportFile?: string }
|
||||
return ["adopt", job.args.church, "--undo"];
|
||||
case "restart":
|
||||
return ["restart", job.args.church, ...(job.args.product ? [job.args.product] : [])];
|
||||
case "seed-demo":
|
||||
return ["demo", job.args.church, "--profile", job.args.profile, ...(job.args.adminEmail ? ["--admin-email", job.args.adminEmail] : [])];
|
||||
case "export":
|
||||
if (!opts.exportFile) throw new Error("export needs a file to write");
|
||||
return ["export", job.args.church, "--out", opts.exportFile];
|
||||
|
||||
@@ -12,7 +12,7 @@ import { paths } from "./paths";
|
||||
* the tools that are there; anything missing is null rather than an error.
|
||||
*/
|
||||
|
||||
export const AGENT_VERSION = "1.1.1";
|
||||
export const AGENT_VERSION = "1.2.0";
|
||||
|
||||
function run(cmd: string, args: string[], timeoutMs = 10_000): Promise<string | null> {
|
||||
return new Promise((resolve) => {
|
||||
|
||||
@@ -39,6 +39,12 @@ describe("crosscode arguments for each job", () => {
|
||||
expect(crosscodeArgs(parsed({ type: "status", args: {} }))).toEqual(["status", "--no-fetch"]);
|
||||
});
|
||||
|
||||
it("seed-demo: crosscode demo with the profile, and the admin kept when the Hub names one", () => {
|
||||
expect(crosscodeArgs(parsed({ type: "seed-demo", args: { church: "hope", profile: "ministry" } }))).toEqual(["demo", "hope", "--profile", "ministry"]);
|
||||
expect(crosscodeArgs(parsed({ type: "seed-demo", args: { church: "hope", profile: "events", adminEmail: "jane@hope.test" } })))
|
||||
.toEqual(["demo", "hope", "--profile", "events", "--admin-email", "jane@hope.test"]);
|
||||
});
|
||||
|
||||
it("export writes to the file the agent gives", () => {
|
||||
const j = parsed({ type: "export", args: { church: "hope", exportId: "exp_abcdefgh" } });
|
||||
expect(crosscodeArgs(j, { exportFile: "/var/lib/crosscode-agent/exports/exp_abcdefgh.zip" })).toEqual(["export", "hope", "--out", "/var/lib/crosscode-agent/exports/exp_abcdefgh.zip"]);
|
||||
|
||||
@@ -5,6 +5,18 @@ All notable changes to this project are documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project follows [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [2.4.1] - 2026-11-19
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Demo data on a server** (`scripts/set-demo.js`): run as anyone but the site's user, `.env`
|
||||
(mode 600) couldn't be read, so `DATABASE_URL` was missing and pg failed with "client password
|
||||
must be a string", then hung. It now stops at once and says to run it as the site's user (or
|
||||
`crosscode demo`, which the Hub uses).
|
||||
- The admin account kept can be named with `--admin-email=` (or `DEMO_ADMIN_EMAIL`, as before).
|
||||
When none is named and joshua@crosscode.co.za isn't on the site, the oldest admin is kept, so a
|
||||
site installed from the Hub (with the church's own admin) can be seeded.
|
||||
|
||||
## [2.4.0] - 2026-11-18
|
||||
|
||||
Protocol v2, Linked products, the event feed and `packages/seo` (ROADMAP-v3 phase 2,
|
||||
|
||||
@@ -12,6 +12,10 @@ Write for church admins, not developers: no environment variables, endpoints or
|
||||
developer log is CHANGELOG.md. A tagged version without a section here shows "No details given".
|
||||
-->
|
||||
|
||||
## 2.4.1
|
||||
|
||||
- Nothing changes for your church: this fixes setting up demonstration sites for Cross Code.
|
||||
|
||||
## 2.4.0
|
||||
|
||||
- **Ready for the Church Website and App.** When your church has them, your events can show on
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@crosscode/events-backend",
|
||||
"version": "2.4.0",
|
||||
"version": "2.4.1",
|
||||
"description": "Event Management System Backend",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
* campus-limited staff, a series across campuses, kids check-in and rosters at two
|
||||
* campuses.
|
||||
*
|
||||
* Everything is removed first EXCEPT the site settings (AppSetting) and the admin
|
||||
* account (DEMO_ADMIN_EMAIL, default joshua@crosscode.co.za). Dates are relative to
|
||||
* Everything is removed first EXCEPT the site settings (AppSetting) and one admin
|
||||
* account (--admin-email= or DEMO_ADMIN_EMAIL; else joshua@crosscode.co.za, else the oldest admin).
|
||||
* Dates are relative to
|
||||
* today, so the upcoming events are always in the future whenever this is run.
|
||||
*
|
||||
* No emails or WhatsApp messages are sent. Demo people use @example.com addresses and
|
||||
@@ -40,7 +41,18 @@ const fs = require('fs');
|
||||
const crypto = require('crypto');
|
||||
const readline = require('readline');
|
||||
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
|
||||
const ENV_FILE = path.resolve(__dirname, '../.env');
|
||||
const loaded = require('dotenv').config({ path: ENV_FILE, quiet: true });
|
||||
|
||||
// Without DATABASE_URL the pg driver fails with "client password must be a string" and hangs. The
|
||||
// usual reason on a server: .env is readable only by the site's own user (mode 600).
|
||||
if (!process.env.DATABASE_URL && !process.argv.includes('--list')) {
|
||||
const denied = loaded.error && loaded.error.code === 'EACCES';
|
||||
console.error(denied
|
||||
? `Can't read ${ENV_FILE}: it belongs to the site's user. Run this as that user, e.g.\n sudo -u <site user> npm run demo:ministry\nor, as root: crosscode demo <church> --profile ministry`
|
||||
: `DATABASE_URL isn't set (${loaded.error ? `${ENV_FILE}: ${loaded.error.code || loaded.error.message}` : `not in ${ENV_FILE}`}). Nothing was changed.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const { hashPassword } = require('../src/config/auth');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
@@ -49,7 +61,11 @@ const { applyBundles } = require('../src/utils/bundles');
|
||||
|
||||
const prisma = createPrismaClient();
|
||||
|
||||
const ADMIN_EMAIL = (process.env.DEMO_ADMIN_EMAIL || 'joshua@crosscode.co.za').trim().toLowerCase();
|
||||
// The account kept: --admin-email= or DEMO_ADMIN_EMAIL (must exist), else joshua@crosscode.co.za
|
||||
// if it's there, else the oldest admin (a site installed from the Hub has its own admin).
|
||||
const ADMIN_ARG = (process.argv.find(a => a.startsWith('--admin-email=')) || '').slice('--admin-email='.length);
|
||||
const ADMIN_NAMED = (ADMIN_ARG || process.env.DEMO_ADMIN_EMAIL || '').trim().toLowerCase();
|
||||
const ADMIN_EMAIL = ADMIN_NAMED || 'joshua@crosscode.co.za';
|
||||
const DEMO_PASSWORD = 'Demo@1234';
|
||||
const SKIP_PROMPT = process.argv.includes('--yes') || process.argv.includes('-y');
|
||||
const PROFILE_NAME = (process.argv.find(a => a.startsWith('--profile=')) || '--profile=events').split('=')[1].trim().toLowerCase();
|
||||
@@ -1846,9 +1862,13 @@ async function main() {
|
||||
return;
|
||||
}
|
||||
admin = await prisma.user.findFirst({ where: { email: { equals: ADMIN_EMAIL, mode: 'insensitive' } } });
|
||||
if (!admin && !ADMIN_NAMED) {
|
||||
admin = await prisma.user.findFirst({ where: { role: 'admin' }, orderBy: { createdAt: 'asc' } });
|
||||
if (admin) console.log(`Keeping the site's first admin, ${admin.email} (${ADMIN_EMAIL} isn't here).`);
|
||||
}
|
||||
if (!admin) {
|
||||
console.error(`Admin account ${ADMIN_EMAIL} was not found — nothing was changed.`);
|
||||
console.error('Set DEMO_ADMIN_EMAIL to the account you want to keep.');
|
||||
console.error(`Admin account ${ADMIN_NAMED || 'to keep'} was not found — nothing was changed.`);
|
||||
console.error('Name the account to keep with --admin-email= or DEMO_ADMIN_EMAIL (or finish /setup first).');
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@crosscode/events-frontend",
|
||||
"version": "2.4.0",
|
||||
"version": "2.4.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@crosscode/events",
|
||||
"version": "2.4.0",
|
||||
"version": "2.4.1",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev:backend": "cd backend && npm run dev",
|
||||
|
||||
Reference in New Issue
Block a user