1- import type { CollectionConfig , Config } from 'payload'
2-
3- import fs from 'fs'
1+ import fs from 'node:fs/promises'
42import { fileURLToPath } from 'node:url'
53import path from 'path'
4+ import { type CollectionConfig , type Config } from 'payload'
65
76import { resetDB } from '../__helpers/shared/clearAndSeed/reset.js'
87import { devUser } from '../credentials.js'
@@ -11,13 +10,26 @@ import {
1110 blocksFieldsSlug ,
1211 collectionSlugs ,
1312 relationshipFieldsSlug ,
13+ richTextFieldsSlug ,
1414 tagsSlug ,
1515 textFieldsSlug ,
16+ uploadsSlug ,
1617} from './slugs.js'
1718
1819const filename = fileURLToPath ( import . meta. url )
1920const dirname = path . dirname ( filename )
2021
22+ // Load file at module level, manually construct to avoid file-type dynamic import issue
23+ const imagePath = path . resolve ( dirname , '../lexical/collections/Upload/payload.jpg' )
24+ const imageData = await fs . readFile ( imagePath )
25+ const imageStat = await fs . stat ( imagePath )
26+ const imageFile = {
27+ name : path . basename ( imagePath ) ,
28+ data : imageData ,
29+ mimetype : 'image/jpeg' ,
30+ size : imageStat . size ,
31+ }
32+
2133import ArrayFields from './collections/Array/index.js'
2234import Autosave from './collections/Autosave/index.js'
2335import BlocksFields from './collections/Blocks/index.js'
@@ -47,6 +59,13 @@ import TextareaFields from './collections/Textarea/index.js'
4759import Rubbish from './collections/Trash/index.js'
4860import Uploads from './collections/Upload/index.js'
4961import UploadFields from './collections/UploadField/index.js'
62+ import {
63+ codeContent ,
64+ getRichTextContent ,
65+ getTypographyContent ,
66+ listsContent ,
67+ tableContent ,
68+ } from './seed/richTextData.js'
5069
5170export const collections : CollectionConfig [ ] = [
5271 {
@@ -151,6 +170,45 @@ export const baseConfig: Partial<Config> = {
151170 createdPosts . push ( created )
152171 }
153172
173+ const richTextCount = await payload . count ( { collection : richTextFieldsSlug } )
174+ if ( richTextCount . totalDocs === 0 ) {
175+ const uploadDoc = await payload . create ( {
176+ collection : uploadsSlug ,
177+ data : { alt : 'Farming image' } ,
178+ file : imageFile ,
179+ } )
180+
181+ const formattedUploadID =
182+ payload . db . defaultIDType === 'number' ? uploadDoc . id : `"${ uploadDoc . id } "`
183+
184+ const devUserDoc = await payload . find ( {
185+ collection : 'users' ,
186+ where : { email : { equals : devUser . email } } ,
187+ limit : 1 ,
188+ } )
189+ const userId = devUserDoc . docs [ 0 ] ?. id
190+ const formattedUserID =
191+ userId !== undefined
192+ ? payload . db . defaultIDType === 'number'
193+ ? userId
194+ : `"${ userId } "`
195+ : undefined
196+
197+ const richTextContent = getRichTextContent ( formattedUploadID , formattedUserID )
198+
199+ await payload . create ( {
200+ collection : richTextFieldsSlug ,
201+ data : {
202+ title : 'Data harvest \u2013 how AI and sensors are revolutionizing farming' ,
203+ content : richTextContent ,
204+ lists : listsContent ,
205+ typography : getTypographyContent ( formattedUserID ) ,
206+ table : tableContent ,
207+ code : codeContent ,
208+ } ,
209+ } )
210+ }
211+
154212 // Seed relationship-fields to test join field
155213 await payload . create ( {
156214 collection : relationshipFieldsSlug ,
0 commit comments