Files
payloadcms/test/_community/config.ts
2024-03-19 01:46:28 -04:00

44 lines
1.1 KiB
TypeScript

import path from 'path'
import { getFileByPath } from 'payload/uploads'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { devUser } from '../credentials.js'
import { MediaCollection } from './collections/Media/index.js'
import { PostsCollection, postsSlug } from './collections/Posts/index.js'
import { MenuGlobal } from './globals/Menu/index.js'
export default buildConfigWithDefaults({
// ...extend config here
collections: [PostsCollection, MediaCollection],
globals: [
MenuGlobal,
// ...add more globals here
],
onInit: async (payload) => {
await payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
})
await payload.create({
collection: postsSlug,
data: {
text: 'example post',
},
})
// Create image
const imageFilePath = path.resolve(process.cwd(), './test/uploads/image.png')
const imageFile = await getFileByPath(imageFilePath)
await payload.create({
collection: 'media',
data: {},
file: imageFile,
})
},
})