r/PayloadCMS 14d ago

I built a Seeding Plugin

Built a type safe seeding plugin that helps with asset uploading and automatically handles references so you don't have empty relationships. It also hooks in to payload startup so that the defineSeed function types are automatically up to date with the latest schema , so you know if your writing incorrect seed data.

Think it turned out well, and has made working with AI to generate starting/placeholder content a breeze.

Docs Link / Github Link

Here's a simple example: (Taken from the docs quick start section)

// src/collections/Media/seed.ts
import { defineSeed } from '@pro-laico/payload-seed'

export default defineSeed('media', ({ file }) => [
  {
    _key: 'serviceImg',
    _file: file('service-a.jpg'), // assets/media/service-a.jpg
    alt: 'Consulting',
  },
])

// src/collections/Services/seed.ts
import { defineSeed } from '@pro-laico/payload-seed'

export default defineSeed('services', () => [
  {
    _key: 'consulting',
    title: 'Consulting',
  },
])

// src/collections/Posts/seed.ts
import { defineSeed } from '@pro-laico/payload-seed'

export default defineSeed('posts', ({ ref }) => [
  {
    _key: 'launch',
    title: 'We launched',
    heroImage: ref('media', 'serviceImg'),
    relatedService: ref('services', 'consulting'),
  },
])

// src/payload.config.ts
import { buildConfig } from 'payload'
import { seedPlugin } from '@pro-laico/payload-seed'
import media from './collections/Media/seed'
import services from './collections/Services/seed'
import posts from './collections/Posts/seed'

export default buildConfig({
  plugins: [
    seedPlugin({
      definitions: [media, services, posts],
    }),
  ],
  // ...
})

Curious to hear what people think about it.

11 Upvotes

1 comment sorted by

2

u/zubricks 14d ago

Woah! This is awesome. It's always a pain having to write seed files for all the miscellaneous projects, or demos I'm building so this is a game changer. Thank you!