payload run starts the CLI with `void start()` and imports the script; when the script's top-level await is left without live handles, Node exits with code 0 and no output — a success in Coolify's Terminal. guardSeedExit() (@intecion/ipal-kit/seed, dependency-free) listens for beforeExit: until summary() runs it prints "[seed] ended before Payload initialized" / "… before the seed finished" and exits 1. createSeeder marks the run initialized, summary() finished; process.exit paths (normal, errors, the production refusals) are untouched. Wired into the ipal-site and ipal-form seed templates and the reference seed, so ipal-kit create sites get it. Tests include a real child process started like payload run. Docs: seeding.md, deployment.md §4.7, AGENT.md, ipal-reference (+ api.md), CHANGELOG Unreleased. Co-Authored-By: Claude Opus 5.5 <[email protected]>
74 lines
3.1 KiB
TypeScript
74 lines
3.1 KiB
TypeScript
/**
|
|
* Seeds of the reference site — rules: node_modules/@intecion/ipal-kit/docs/seeding.md.
|
|
*
|
|
* pnpm seed # the reference site: demo layer first (filled pages win), then the base layer;
|
|
* # a site made by `ipal-kit create`: the base layer only
|
|
* pnpm seed:base # only what every new site keeps
|
|
* pnpm seed:demo # reference site only: the made-up company's content (needs the base forms)
|
|
* SEED_DRY_RUN=1 pnpm seed # print the plan, write nothing
|
|
*
|
|
* VERY IMPORTANT — after launch: never the whole seed again. Name the records the run may touch:
|
|
* SEED_ONLY="pages:kontakt" SEED_DRY_RUN=1 pnpm seed → Backup now (Coolify) → the same without SEED_DRY_RUN
|
|
* createSeeder refuses a run without SEED_ONLY on production or a non-local database (IPAL_SEED_ALLOW_FULL=1
|
|
* only with the owner's explicit OK). Pages are create-only; an edited record is skipped.
|
|
*/
|
|
import config from '@payload-config'
|
|
import { createSeeder, guardSeedExit } from '@intecion/ipal-kit/seed'
|
|
import { getPayload } from 'payload'
|
|
|
|
import { seedBaseGlobals, seedBaseNavigation, seedBasePages, seedBaseTexts } from './base'
|
|
// @starter:if demo
|
|
import { DEMO_NOTIFY_EMAIL, seedDemoGlobals, seedDemoNavigation, seedDemoPages } from './demo'
|
|
// @starter:endif
|
|
import { seedForms } from './forms'
|
|
// @starter:if demo
|
|
import { seedMedia } from './media'
|
|
// @starter:endif
|
|
|
|
// @starter:if demo
|
|
const layer = process.env.SEED_LAYER ?? 'all'
|
|
const withDemo = layer === 'all' || layer === 'demo'
|
|
const withBase = layer === 'all' || layer === 'base'
|
|
// @starter:else
|
|
//: const withBase = true // a new site has only the base layer (the reference site's demo is not copied)
|
|
// @starter:endif
|
|
|
|
// An early exit (Payload never up, the run cut short) fails with exit 1 instead of a silent 0 (seeding.md).
|
|
guardSeedExit()
|
|
const payload = await getPayload({ config })
|
|
const seed = createSeeder(payload)
|
|
|
|
// @starter:if demo
|
|
const media = withDemo ? await seedMedia(payload) : {}
|
|
if (withDemo) {await seedDemoGlobals(seed, media)}
|
|
// @starter:endif
|
|
if (withBase) {await seedBaseGlobals(seed)}
|
|
|
|
// Forms need the inbox that receives submissions: SEED_NOTIFY_EMAIL, else the Company global — never a guess.
|
|
const company = (await payload.findGlobal({ slug: 'company' })) as { email?: null | string }
|
|
// @starter:if demo
|
|
const notifyTo = process.env.SEED_NOTIFY_EMAIL?.trim() || (withDemo ? DEMO_NOTIFY_EMAIL : company.email?.trim()) || ''
|
|
// @starter:else
|
|
//: const notifyTo = process.env.SEED_NOTIFY_EMAIL?.trim() || company.email?.trim() || ''
|
|
// @starter:endif
|
|
if (/^[^\s@,;]+@[^\s@,;]+\.[^\s@,;]+$/.test(notifyTo)) {
|
|
await seedForms(seed, notifyTo)
|
|
} else {
|
|
console.error('[seed] Forms skipped: fill Company → E-mail in the panel or run with SEED_NOTIFY_EMAIL=… (ask the client which inbox).')
|
|
}
|
|
|
|
// @starter:if demo
|
|
if (withDemo) {
|
|
await seedDemoPages(seed, media)
|
|
await seedDemoNavigation(seed)
|
|
}
|
|
// @starter:endif
|
|
if (withBase) {
|
|
await seedBasePages(seed)
|
|
await seedBaseNavigation(seed)
|
|
await seedBaseTexts(seed)
|
|
}
|
|
|
|
const { errors } = seed.summary()
|
|
process.exit(errors ? 1 : 0)
|