chore: seeds demo

This commit is contained in:
Jacob Fletcher
2022-11-16 14:59:29 -05:00
parent fe62871c75
commit 59a31543c8
10 changed files with 1943 additions and 1714 deletions

Binary file not shown.

View File

@@ -3,3 +3,5 @@ node_modules
dist
demo/uploads
build
.DS_Store
package-lock.json

View File

@@ -5,7 +5,7 @@
"main": "dist/server.js",
"license": "MIT",
"scripts": {
"dev": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts nodemon",
"dev": "cross-env PAYLOAD_SEED=true PAYLOAD_DROP_DATABASE=true PAYLOAD_CONFIG_PATH=src/payload.config.ts nodemon",
"build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
"build:server": "tsc",
"build": "yarn build:payload && yarn build:server",
@@ -13,9 +13,9 @@
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types"
},
"dependencies": {
"payload": "^1.0.9",
"dotenv": "^8.2.0",
"express": "^4.17.1"
"express": "^4.17.1",
"payload": "^1.1.26"
},
"devDependencies": {
"@types/express": "^4.17.9",

View File

@@ -1,7 +1,7 @@
import { GlobalConfig } from 'payload/types';
const HomePage: GlobalConfig = {
slug: 'homePage',
const Settings: GlobalConfig = {
slug: 'settings',
fields: [
{
name: 'title',
@@ -15,4 +15,4 @@ const HomePage: GlobalConfig = {
],
}
export default HomePage;
export default Settings;

View File

@@ -5,7 +5,7 @@ import seo from '../../src';
import Users from './collections/Users';
import Pages from './collections/Pages';
import Media from './collections/Media';
import HomePage from './globals/HomePage';
import HomePage from './globals/Settings';
export default buildConfig({
serverURL: 'http://localhost:3000',
@@ -51,7 +51,7 @@ export default buildConfig({
'pages',
],
globals: [
'homePage',
'settings',
],
uploadsCollection: 'media',
generateTitle: ({ doc }: any) => `Website.com — ${doc?.title?.value}`,

View File

@@ -0,0 +1,22 @@
import { Payload } from 'payload';
export const seed = async (payload: Payload) => {
payload.logger.info('Seeding data...');
await payload.create({
collection: 'users',
data: {
email: 'dev@payloadcms.com',
password: 'test',
}
});
await payload.create({
collection: 'pages',
data: {
title: 'Home Page',
slug: 'home',
excerpt: 'This is the home page'
},
})
}

View File

@@ -1,5 +1,6 @@
import express from 'express';
import payload from 'payload';
import { seed } from './seed';
require('dotenv').config();
const app = express();
@@ -10,15 +11,21 @@ app.get('/', (_, res) => {
});
// Initialize Payload
payload.init({
secret: process.env.PAYLOAD_SECRET,
mongoURL: process.env.MONGODB_URI,
express: app,
onInit: () => {
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
},
});
const start = async () => {
await payload.initAsync({
secret: process.env.PAYLOAD_SECRET,
mongoURL: process.env.MONGODB_URI,
express: app,
onInit: () => {
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
},
})
// Add your own express routes here
if (process.env.PAYLOAD_SEED === 'true') {
await seed(payload);
}
app.listen(3000);
app.listen(3000);
}
start();

File diff suppressed because it is too large Load Diff

View File

@@ -26,8 +26,6 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"devDependencies": {
"@types/react": "^18.0.8",
"@types/react-dom": "^18.0.3",
"payload": "^1.0.9",
"react": "^18.0.0",
"typescript": "^4.5.5"

File diff suppressed because it is too large Load Diff