- apps/events/env.template.json (crosscode.env-template/1): every .env variable with its layer (server, defaults, install, generated). - scripts/export-church.ts writes crosscode.church-export/1 (export-only references, no internal ids or secrets) for crosscode export. - Installs made from the Hub register by themselves on first start when HUB_LICENCE_KEY is set (retries while the Hub is unreachable). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
3.0 KiB
TypeScript
58 lines
3.0 KiB
TypeScript
/**
|
|
* Writes the church's data as crosscode.church-export/1 (src/services/churchExport.ts) into a
|
|
* folder: export.json and README.txt. `crosscode export` runs it, copies public/uploads into the
|
|
* folder's uploads/ and zips it. Run from backend/: npx tsx scripts/export-church.ts --out-dir <dir>
|
|
*/
|
|
import 'dotenv/config';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { buildExport, readExportInput } from '../src/services/churchExport';
|
|
import { prisma } from '../src/v2/legacy';
|
|
|
|
const README = `Your church's data from Cross Events
|
|
=====================================
|
|
|
|
export.json holds your events, people, registrations, payments, check-ins and volunteer
|
|
rosters, in plain terms (crosscode.church-export/1). Records refer to each other with short
|
|
references made for this file: "p12" is a person, "e3" an event, "t5" a ticket type and "r40"
|
|
a registration. They mean nothing outside this file.
|
|
|
|
people everyone with an account: name, email, phone, role, what they agreed to
|
|
events each event with its sessions and ticket types (prices in cents)
|
|
registrations who registered for what, the people attending, their answers to the form
|
|
payments amounts in cents, how and when they were paid, the provider's reference
|
|
checkIns who was checked in to which event, and when
|
|
rosters volunteer roles and who served
|
|
settings the site's name, contact details and branding
|
|
files uploaded files, in the uploads/ folder next to this file
|
|
|
|
Not included: passwords, security codes and logs about how the site ran.
|
|
`;
|
|
|
|
function listFiles(dir: string, base = dir): { path: string; bytes: number }[] {
|
|
if (!fs.existsSync(dir)) return [];
|
|
return fs.readdirSync(dir, { withFileTypes: true }).flatMap(d => {
|
|
const full = path.join(dir, d.name);
|
|
if (d.isDirectory()) return d.name === 'tickets-temp' ? [] : listFiles(full, base);
|
|
if (!d.isFile() || !/^[A-Za-z0-9._-]+$/.test(d.name)) return [];
|
|
return [{ path: `uploads/${path.relative(base, full).split(path.sep).join('/')}`, bytes: fs.statSync(full).size }];
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
const i = process.argv.indexOf('--out-dir');
|
|
const out = i > 0 ? process.argv[i + 1] : '';
|
|
if (!out) throw new Error('Usage: export-church.ts --out-dir <dir>');
|
|
fs.mkdirSync(out, { recursive: true });
|
|
const { version } = require('../package.json') as { version: string };
|
|
const data = buildExport(await readExportInput(version));
|
|
data.files = listFiles(path.join(__dirname, '..', 'public', 'uploads'));
|
|
fs.writeFileSync(path.join(out, 'export.json'), `${JSON.stringify(data, null, 2)}\n`);
|
|
fs.writeFileSync(path.join(out, 'README.txt'), README);
|
|
console.log(`export.json: ${data.people.length} people, ${data.events.length} events, ${data.registrations.length} registrations, ${data.files.length} files`);
|
|
}
|
|
|
|
main()
|
|
.catch(e => { console.error(`Export failed: ${(e as Error).message}`); process.exitCode = 1; })
|
|
.finally(() => prisma.$disconnect().catch(() => {}));
|