import { mongooseAdapter } from '@payloadcms/db-mongodb' import { lexicalEditor } from '@payloadcms/richtext-lexical' import path from 'path' import { buildConfig } from 'payload' import { fileURLToPath } from 'url' import sharp from 'sharp' import { Users } from './collections/Users' import { Media } from './collections/Media' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) export default buildConfig({ admin: { user: Users.slug, importMap: { baseDir: path.resolve(dirname), }, }, collections: [ Users, Media, { slug: 'posts', fields: [ { name: 'title', label: 'Title', type: 'text', required: true, }, ], }, ], editor: lexicalEditor(), secret: process.env.PAYLOAD_SECRET || '', typescript: { outputFile: path.resolve(dirname, 'payload-types.ts'), }, async onInit(payload) { const { totalDocs: postsCount } = await payload.count({ collection: 'posts', overrideAccess: true, }) if (!postsCount) { await payload.create({ collection: 'posts', data: { title: 'Post 1' }, overrideAccess: true }) } }, db: mongooseAdapter({ url: process.env.DATABASE_URL || '', }), sharp, plugins: [], })