mirror of
https://github.com/xtr-dev/payload-feature-flags.git
synced 2025-12-10 02:43:25 +00:00
Replace redundant components with updated feature flag hooks and views. Add comprehensive documentation and ESLint config for improved development workflow.
This commit is contained in:
131
dev/seed.ts
131
dev/seed.ts
@@ -1,9 +1,10 @@
|
||||
import type { Payload } from 'payload'
|
||||
|
||||
import { devUser } from './helpers/credentials.js'
|
||||
import { devUser, testUsers } from './helpers/credentials.js'
|
||||
|
||||
export const seed = async (payload: Payload) => {
|
||||
const { totalDocs } = await payload.count({
|
||||
// Create admin user
|
||||
const { totalDocs: adminExists } = await payload.count({
|
||||
collection: 'users',
|
||||
where: {
|
||||
email: {
|
||||
@@ -12,10 +13,132 @@ export const seed = async (payload: Payload) => {
|
||||
},
|
||||
})
|
||||
|
||||
if (!totalDocs) {
|
||||
await payload.create({
|
||||
let adminUser
|
||||
if (!adminExists) {
|
||||
adminUser = await payload.create({
|
||||
collection: 'users',
|
||||
data: devUser,
|
||||
})
|
||||
console.log(`✅ Created admin user: ${devUser.email}`)
|
||||
} else {
|
||||
const adminResult = await payload.find({
|
||||
collection: 'users',
|
||||
where: {
|
||||
email: {
|
||||
equals: devUser.email,
|
||||
},
|
||||
},
|
||||
})
|
||||
adminUser = adminResult.docs[0]
|
||||
}
|
||||
|
||||
// Create test users
|
||||
for (const user of testUsers) {
|
||||
const { totalDocs: userExists } = await payload.count({
|
||||
collection: 'users',
|
||||
where: {
|
||||
email: {
|
||||
equals: user.email,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if (!userExists) {
|
||||
await payload.create({
|
||||
collection: 'users',
|
||||
data: user,
|
||||
})
|
||||
console.log(`✅ Created user: ${user.email}`)
|
||||
}
|
||||
}
|
||||
|
||||
// Create sample posts
|
||||
const { totalDocs: postsExist } = await payload.count({
|
||||
collection: 'posts',
|
||||
})
|
||||
|
||||
if (postsExist === 0) {
|
||||
const samplePosts = [
|
||||
{
|
||||
title: 'Welcome to Feature Flag Testing',
|
||||
status: 'published' as const,
|
||||
publishedAt: new Date().toISOString(),
|
||||
},
|
||||
{
|
||||
title: 'Beta Feature Showcase',
|
||||
status: 'draft' as const,
|
||||
},
|
||||
{
|
||||
title: 'A/B Test Content',
|
||||
status: 'published' as const,
|
||||
publishedAt: new Date().toISOString(),
|
||||
},
|
||||
]
|
||||
|
||||
for (const post of samplePosts) {
|
||||
await payload.create({
|
||||
collection: 'posts',
|
||||
data: post,
|
||||
})
|
||||
}
|
||||
console.log('✅ Created sample posts')
|
||||
}
|
||||
|
||||
// Create sample pages
|
||||
const { totalDocs: pagesExist } = await payload.count({
|
||||
collection: 'pages',
|
||||
})
|
||||
|
||||
if (pagesExist === 0) {
|
||||
const samplePages = [
|
||||
{
|
||||
title: 'Home',
|
||||
slug: 'home',
|
||||
layout: 'landing' as const,
|
||||
},
|
||||
{
|
||||
title: 'About',
|
||||
slug: 'about',
|
||||
layout: 'default' as const,
|
||||
},
|
||||
{
|
||||
title: 'Beta Dashboard',
|
||||
slug: 'beta-dashboard',
|
||||
layout: 'sidebar' as const,
|
||||
},
|
||||
]
|
||||
|
||||
for (const page of samplePages) {
|
||||
await payload.create({
|
||||
collection: 'pages',
|
||||
data: page,
|
||||
})
|
||||
}
|
||||
console.log('✅ Created sample pages')
|
||||
}
|
||||
|
||||
// Create simple feature flag for testing
|
||||
const { totalDocs: flagsExist } = await payload.count({
|
||||
collection: 'feature-flags',
|
||||
})
|
||||
|
||||
if (flagsExist === 0) {
|
||||
await payload.create({
|
||||
collection: 'feature-flags',
|
||||
data: {
|
||||
name: 'new-feature',
|
||||
description: 'A simple test feature flag',
|
||||
enabled: true,
|
||||
environment: 'development' as const,
|
||||
owner: adminUser.id,
|
||||
},
|
||||
})
|
||||
console.log('✅ Created simple feature flag for testing')
|
||||
}
|
||||
|
||||
console.log('🎯 Development environment seeded successfully!')
|
||||
console.log('📧 Login with:')
|
||||
console.log(` Admin: ${devUser.email} / ${devUser.password}`)
|
||||
console.log(` Editor: ${testUsers[0].email} / ${testUsers[0].password}`)
|
||||
console.log(` User: ${testUsers[1].email} / ${testUsers[1].password}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user