Payload Global configs mirroring proto/src/content/types.ts:
- src/globals/{Home,About,Services,Contact,Common}.ts
- src/globals/fields/stringArray.ts — shared helper: Payload has no
native string[] field, so every plain string array from the old
content types (trustBullets, paragraphs, features, spec items, …)
becomes an array of one-field { value } objects.
- home.partners is intentionally NOT included — that becomes its own
Partners collection (logo -> Media upload) in MITHOME-89, to avoid
two disagreeing sources for the same data.
- contact.form.fields.gdpr.label stays a plain textarea (not lexical
richText): the JSON source is a hand-written HTML string with an
<a> tag; richText's node-tree serialization would need its own
migration/render logic, out of scope for this bootstrap pass.
scripts/migrate-content-to-payload.ts: one-shot, idempotent Local API
migration reading the existing JSON files and calling updateGlobal —
does not touch or delete the JSON files. Run via the new
`npm run migrate:content` script.
Registered the five Globals in payload.config.ts.
Also included here (belongs with the previous "resolve double-root-
layout conflict" commit but didn't actually get staged there —
verified only now by diffing HEAD against the working tree):
(frontend)/layout.tsx's relative imports corrected to ../../ instead
of ../ (one directory deeper than the original src/app/layout.tsx).
Verified:
- npm run build / lint, tsc --noEmit, npm test (58 passed) all clean
- npm run migrate:content against the real dev MongoDB container,
then read back via payload.findGlobal() — hero.title, trustBullets,
services.items[0].features, footer.address, faq.items.length all
match the JSON source
- Real browser: logged into /admin, opened the Home global editor —
Hero/Trust bullets group renders and shows the migrated Hungarian
content correctly (see screenshot shared in chat)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
105 lines
3.1 KiB
TypeScript
105 lines
3.1 KiB
TypeScript
/**
|
|
* MITHOME-87: egyszeri migrációs script — a proto/src/content/pages/*.json
|
|
* + common.json tartalmát átemeli a Payload Globals-ekbe (Home, About,
|
|
* Services, Contact, Common) a Local API-n keresztül.
|
|
*
|
|
* Futtatás (proto/ mappából, futó MongoDB-vel és beállított env-ekkel):
|
|
* node --env-file=.env.local --import tsx scripts/migrate-content-to-payload.ts
|
|
*
|
|
* Idempotens: updateGlobal-t hív, tetszőlegesen többször futtatható —
|
|
* mindig a JSON az aktuális "forrás igazság", felülírja a Payload-ban
|
|
* lévő korábbi állapotot. NEM törli/nem érinti a JSON fájlokat.
|
|
*/
|
|
import { getPayload } from 'payload'
|
|
import config from '../src/payload.config'
|
|
|
|
import homeJson from '../src/content/pages/home.json'
|
|
import aboutJson from '../src/content/pages/about.json'
|
|
import servicesJson from '../src/content/pages/services.json'
|
|
import contactJson from '../src/content/pages/contact.json'
|
|
import commonJson from '../src/content/common.json'
|
|
|
|
/** string[] -> [{ value: string }] — lásd src/globals/fields/stringArray.ts */
|
|
function toStringArray(items: readonly string[]): { value: string }[] {
|
|
return items.map((value) => ({ value }))
|
|
}
|
|
|
|
function buildHomeData(json: typeof homeJson) {
|
|
const { hero, about, services, cta, serviceFeatures } = json
|
|
return {
|
|
hero: {
|
|
...hero,
|
|
trustBullets: toStringArray(hero.trustBullets),
|
|
},
|
|
about,
|
|
services: {
|
|
...services,
|
|
items: services.items.map((item) => ({
|
|
...item,
|
|
features: toStringArray(item.features),
|
|
})),
|
|
},
|
|
cta,
|
|
serviceFeatures,
|
|
}
|
|
}
|
|
|
|
function buildAboutData(json: typeof aboutJson) {
|
|
const { meta, hero, story, mission, team, cta } = json
|
|
return {
|
|
meta,
|
|
hero,
|
|
story: { ...story, paragraphs: toStringArray(story.paragraphs) },
|
|
mission,
|
|
team: { ...team, paragraphs: toStringArray(team.paragraphs) },
|
|
cta,
|
|
}
|
|
}
|
|
|
|
function buildServicesData(json: typeof servicesJson) {
|
|
const { meta, hero, details, support, cta } = json
|
|
return {
|
|
meta,
|
|
hero,
|
|
details: {
|
|
...details,
|
|
services: details.services.map((service) => ({
|
|
...service,
|
|
specs: {
|
|
...service.specs,
|
|
items: toStringArray(service.specs.items),
|
|
},
|
|
})),
|
|
},
|
|
support,
|
|
cta,
|
|
}
|
|
}
|
|
|
|
async function run() {
|
|
const payload = await getPayload({ config })
|
|
|
|
await payload.updateGlobal({ slug: 'home', data: buildHomeData(homeJson) })
|
|
payload.logger.info('Home global migrálva')
|
|
|
|
await payload.updateGlobal({ slug: 'about', data: buildAboutData(aboutJson) })
|
|
payload.logger.info('About global migrálva')
|
|
|
|
await payload.updateGlobal({ slug: 'services', data: buildServicesData(servicesJson) })
|
|
payload.logger.info('Services global migrálva')
|
|
|
|
await payload.updateGlobal({ slug: 'contact', data: contactJson })
|
|
payload.logger.info('Contact global migrálva')
|
|
|
|
await payload.updateGlobal({ slug: 'common', data: commonJson })
|
|
payload.logger.info('Common global migrálva')
|
|
|
|
payload.logger.info('MITHOME-87 migráció kész.')
|
|
process.exit(0)
|
|
}
|
|
|
|
run().catch((error) => {
|
|
console.error('Migráció sikertelen:', error)
|
|
process.exit(1)
|
|
})
|