feat: 2.0 template updates (#3488)

* feat: update templates to 2.0 and support create-payload-app

* chore: rich text updates

* chore(templates): remove mongoURL

* chore: migrates rich text fields in website

* chore: manually aliases dotenv in templates

* chore: installs new beta in website template

* chore: type issues

* chore (template): add alias for fs to website template

* chore: more template updates

---------

Co-authored-by: James <james@trbl.design>
Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
This commit is contained in:
Elliot DeNolf
2023-10-08 23:23:51 -04:00
committed by GitHub
parent b32b156f9f
commit 25d20cf87b
57 changed files with 2650 additions and 1994 deletions

3
.gitignore vendored
View File

@@ -15,9 +15,6 @@ test-results
.AppleDouble .AppleDouble
.LSOverride .LSOverride
# Icon must end with two \r
Icon
# Thumbnails # Thumbnails
._* ._*

View File

@@ -1,2 +1,2 @@
MONGODB_URI=mongodb://127.0.0.1/payload-template-blank DATABASE_URI=mongodb://127.0.0.1/payload-template-blank
PAYLOAD_SECRET=YOUR_SECRET_HERE PAYLOAD_SECRET=YOUR_SECRET_HERE

View File

@@ -2,7 +2,7 @@
A blank template for [Payload](https://github.com/payloadcms/payload) to help you get up and running quickly. This repo may have been created by running `npx create-payload-app` and selecting the "blank" template or by cloning this template on [Payload Cloud](https://payloadcms.com/new/clone/blank). A blank template for [Payload](https://github.com/payloadcms/payload) to help you get up and running quickly. This repo may have been created by running `npx create-payload-app` and selecting the "blank" template or by cloning this template on [Payload Cloud](https://payloadcms.com/new/clone/blank).
See the official [Examples Directory](https://github.com/payloadcms/payload/tree/main/examples) for details on how to use Payload in a variety of different ways. See the official [Examples Directory](https://github.com/payloadcms/payload/tree/master/examples) for details on how to use Payload in a variety of different ways.
## Development ## Development

View File

@@ -1,11 +1,10 @@
version: '3' version: '3'
services: services:
payload: payload:
image: node:18-alpine image: node:18-alpine
ports: ports:
- "3000:3000" - '3000:3000'
volumes: volumes:
- .:/home/node/app - .:/home/node/app
- node_modules:/home/node/app/node_modules - node_modules:/home/node/app/node_modules
@@ -19,7 +18,7 @@ services:
mongo: mongo:
image: mongo:latest image: mongo:latest
ports: ports:
- "27017:27017" - '27017:27017'
command: command:
- --storageEngine=wiredTiger - --storageEngine=wiredTiger
volumes: volumes:

View File

@@ -1,4 +1,6 @@
{ {
"$schema": "https://json.schemastore.org/nodemon.json",
"ext": "ts", "ext": "ts",
"exec": "ts-node src/server.ts" "exec": "ts-node src/server.ts -- -I",
"stdin": false
} }

View File

@@ -15,11 +15,14 @@
"generate:graphQLSchema": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema" "generate:graphQLSchema": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema"
}, },
"dependencies": { "dependencies": {
"@payloadcms/bundler-webpack": "latest",
"@payloadcms/db-mongodb": "latest",
"@payloadcms/plugin-cloud": "^0.0.10", "@payloadcms/plugin-cloud": "^0.0.10",
"@payloadcms/richtext-slate": "latest",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"payload": "latest" "payload": "beta"
}, },
"devDependencies": { "devDependencies": {
"@types/express": "^4.17.9", "@types/express": "^4.17.9",
@@ -28,4 +31,4 @@
"ts-node": "^9.1.1", "ts-node": "^9.1.1",
"typescript": "^4.8.4" "typescript": "^4.8.4"
} }
} }

View File

@@ -1,12 +1,19 @@
import { buildConfig } from 'payload/config'
import path from 'path' import path from 'path'
import Users from './collections/Users'
import { payloadCloud } from '@payloadcms/plugin-cloud' import { payloadCloud } from '@payloadcms/plugin-cloud'
import { mongooseAdapter } from '@payloadcms/db-mongodb' // database-adapter-import
import { webpackBundler } from '@payloadcms/bundler-webpack' // bundler-import
import { slateEditor } from '@payloadcms/richtext-slate' // editor-import
import { buildConfig } from 'payload/config'
import Users from './collections/Users'
export default buildConfig({ export default buildConfig({
admin: { admin: {
user: Users.slug, user: Users.slug,
bundler: webpackBundler(), // bundler-config
}, },
editor: slateEditor({}), // editor-config
collections: [Users], collections: [Users],
typescript: { typescript: {
outputFile: path.resolve(__dirname, 'payload-types.ts'), outputFile: path.resolve(__dirname, 'payload-types.ts'),
@@ -15,4 +22,9 @@ export default buildConfig({
schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'), schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
}, },
plugins: [payloadCloud()], plugins: [payloadCloud()],
// database-adapter-config-start
db: mongooseAdapter({
url: process.env.DATABASE_URI,
}),
// database-adapter-config-end
}) })

View File

@@ -13,7 +13,6 @@ const start = async () => {
// Initialize Payload // Initialize Payload
await payload.init({ await payload.init({
secret: process.env.PAYLOAD_SECRET, secret: process.env.PAYLOAD_SECRET,
mongoURL: process.env.MONGODB_URI,
express: app, express: app,
onInit: async () => { onInit: async () => {
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`) payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)

View File

@@ -1,11 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"lib": [ "lib": ["dom", "dom.iterable", "esnext"],
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true, "allowJs": true,
"strict": false, "strict": false,
"esModuleInterop": true, "esModuleInterop": true,
@@ -14,21 +10,13 @@
"rootDir": "./src", "rootDir": "./src",
"jsx": "react", "jsx": "react",
"paths": { "paths": {
"payload/generated-types": [ "payload/generated-types": ["./src/payload-types.ts"]
"./src/payload-types.ts",
],
} }
}, },
"include": [ "include": ["src"],
"src" "exclude": ["node_modules", "dist", "build"],
],
"exclude": [
"node_modules",
"dist",
"build",
],
"ts-node": { "ts-node": {
"transpileOnly": true, "transpileOnly": true,
"swc": true, "swc": true
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,17 +1,17 @@
# Payload vars # Payload vars
PORT=3000 PORT=3000
MONGODB_URI=mongodb://127.0.0.1/payload-template-ecommerce DATABASE_URI=mongodb://127.0.0.1/payload-template-ecommerce
PAYLOAD_SECRET=712kjbkuh87234sflj98713b PAYLOAD_SECRET=712kjbkuh87234sflj98713b
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000 PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
STRIPE_SECRET_KEY= STRIPE_SECRET_KEY=
PAYLOAD_PUBLIC_STRIPE_IS_TEST_KEY=true PAYLOAD_PUBLIC_STRIPE_IS_TEST_KEY=true
STRIPE_WEBHOOKS_SIGNING_SECRET= STRIPE_WEBHOOKS_SIGNING_SECRET=
PAYLOAD_PUBLIC_DRAFT_SECRET=EXAMPLE_DRAFT_SECRET PAYLOAD_PUBLIC_DRAFT_SECRET=demo-draft-secret
REVALIDATION_KEY=EXAMPLE_REVALIDATION_KEY REVALIDATION_KEY=demo-revalation-key
# Next.js vars # Next.js vars
NEXT_PUBLIC_SERVER_URL=http://localhost:3000 NEXT_PUBLIC_SERVER_URL=http://localhost:3000
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY= NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=
NEXT_PUBLIC_IS_LIVE= NEXT_PUBLIC_IS_LIVE=
NEXT_PRIVATE_DRAFT_SECRET=EXAMPLE_DRAFT_SECRET NEXT_PRIVATE_DRAFT_SECRET=demo-draft-secret
NEXT_PRIVATE_REVALIDATION_KEY=EXAMPLE_REVALIDATION_KEY NEXT_PRIVATE_REVALIDATION_KEY=demo-revalation-key

View File

@@ -1,11 +1,10 @@
version: '3' version: '3'
services: services:
payload: payload:
image: node:18-alpine image: node:18-alpine
ports: ports:
- "3000:3000" - '3000:3000'
volumes: volumes:
- .:/home/node/app - .:/home/node/app
- node_modules:/home/node/app/node_modules - node_modules:/home/node/app/node_modules
@@ -19,7 +18,7 @@ services:
mongo: mongo:
image: mongo:latest image: mongo:latest
ports: ports:
- "27017:27017" - '27017:27017'
command: command:
- --storageEngine=wiredTiger - --storageEngine=wiredTiger
volumes: volumes:

View File

@@ -1,8 +1,10 @@
{ {
"$schema": "https://json.schemastore.org/nodemon.json",
"watch": ["server.ts"], "watch": ["server.ts"],
"exec": "ts-node --project tsconfig.server.json src/server.ts", "exec": "ts-node --project tsconfig.server.json src/server.ts -- -I",
"ext": "js ts", "ext": "js ts",
"ignore" : [ "ignore" : [
"src/app" "src/app"
] ],
"stdin": false
} }

View File

@@ -14,25 +14,28 @@
"build": "cross-env NODE_ENV=production yarn build:payload && yarn build:server && yarn copyfiles && yarn build:next", "build": "cross-env NODE_ENV=production yarn build:payload && yarn build:server && yarn copyfiles && yarn build:next",
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload/payload.config.js NODE_ENV=production node dist/server.js", "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload/payload.config.js NODE_ENV=production node dist/server.js",
"eject": "yarn remove next react react-dom @next/eslint-plugin-next && ts-node eject.ts", "eject": "yarn remove next react react-dom @next/eslint-plugin-next && ts-node eject.ts",
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/", "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,js}\" dist/",
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload/payload.config.ts payload generate:types", "generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload/payload.config.ts payload generate:types",
"generate:graphQLSchema": "PAYLOAD_CONFIG_PATH=src/payload/payload.config.ts payload generate:graphQLSchema", "generate:graphQLSchema": "PAYLOAD_CONFIG_PATH=src/payload/payload.config.ts payload generate:graphQLSchema",
"lint": "eslint src", "lint": "eslint src",
"lint:fix": "eslint --fix --ext .ts,.tsx src" "lint:fix": "eslint --fix --ext .ts,.tsx src"
}, },
"dependencies": { "dependencies": {
"@payloadcms/bundler-webpack": "^1.0.0-beta.6",
"@payloadcms/db-mongodb": "latest",
"@payloadcms/plugin-cloud": "^2.0.0", "@payloadcms/plugin-cloud": "^2.0.0",
"@payloadcms/plugin-nested-docs": "^1.0.4", "@payloadcms/plugin-nested-docs": "^1.0.4",
"@payloadcms/plugin-redirects": "^1.0.0", "@payloadcms/plugin-redirects": "^1.0.0",
"@payloadcms/plugin-seo": "^1.0.10", "@payloadcms/plugin-seo": "^1.0.10",
"@payloadcms/plugin-stripe": "^0.0.14", "@payloadcms/plugin-stripe": "^0.0.14",
"@payloadcms/richtext-slate": "latest",
"@stripe/react-stripe-js": "^1.16.3", "@stripe/react-stripe-js": "^1.16.3",
"@stripe/stripe-js": "^1.46.0", "@stripe/stripe-js": "^1.46.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"next": "^13.4.8", "next": "^13.4.8",
"payload": "latest", "payload": "beta",
"payload-admin-bar": "^1.0.6", "payload-admin-bar": "^1.0.6",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",

View File

@@ -2,7 +2,7 @@ import { revalidateTag } from 'next/cache'
import type { NextRequest } from 'next/server' import type { NextRequest } from 'next/server'
import { NextResponse } from 'next/server' import { NextResponse } from 'next/server'
export async function GET(request: NextRequest): Promise<unknown> { export async function GET(request: NextRequest): Promise<Response> {
const collection = request.nextUrl.searchParams.get('collection') const collection = request.nextUrl.searchParams.get('collection')
const slug = request.nextUrl.searchParams.get('slug') const slug = request.nextUrl.searchParams.get('slug')
const secret = request.nextUrl.searchParams.get('secret') const secret = request.nextUrl.searchParams.get('secret')

View File

@@ -1,3 +1,4 @@
import { slateEditor } from '@payloadcms/richtext-slate'
import path from 'path' import path from 'path'
import type { CollectionConfig } from 'payload/types' import type { CollectionConfig } from 'payload/types'
@@ -18,9 +19,11 @@ export const Media: CollectionConfig = {
{ {
name: 'caption', name: 'caption',
type: 'richText', type: 'richText',
admin: { editor: slateEditor({
elements: ['link'], admin: {
}, elements: ['link'],
},
}),
}, },
], ],
} }

View File

@@ -1,6 +1,6 @@
import type { AfterChangeHook } from 'payload/dist/collections/config/types' import type { AfterChangeHook } from 'payload/dist/collections/config/types'
import type { Order } from '../../../payload-types' import type { Order, User } from '../../../payload-types'
export const clearUserCart: AfterChangeHook<Order> = async ({ doc, req, operation }) => { export const clearUserCart: AfterChangeHook<Order> = async ({ doc, req, operation }) => {
const { payload } = req const { payload } = req
@@ -18,7 +18,7 @@ export const clearUserCart: AfterChangeHook<Order> = async ({ doc, req, operatio
collection: 'users', collection: 'users',
id: orderedBy, id: orderedBy,
data: { data: {
cart: [], cart: [] as User['cart'],
}, },
}) })
} }

View File

@@ -0,0 +1,3 @@
module.exports = {
config: () => null,
}

View File

@@ -1,4 +1,4 @@
import type { RichTextElement } from 'payload/dist/fields/config/types' import type { RichTextElement } from '@payloadcms/richtext-slate/dist/types'
import label from './label' import label from './label'
import largeBody from './largeBody' import largeBody from './largeBody'

View File

@@ -1,4 +1,10 @@
import type { RichTextElement, RichTextField, RichTextLeaf } from 'payload/dist/fields/config/types' import { slateEditor } from '@payloadcms/richtext-slate'
import type {
AdapterArguments,
RichTextElement,
RichTextLeaf,
} from '@payloadcms/richtext-slate/dist/types'
import type { RichTextField } from 'payload/dist/fields/config/types'
import deepMerge from '../../utilities/deepMerge' import deepMerge from '../../utilities/deepMerge'
import link from '../link' import link from '../link'
@@ -6,7 +12,7 @@ import elements from './elements'
import leaves from './leaves' import leaves from './leaves'
type RichText = ( type RichText = (
overrides?: Partial<RichTextField>, overrides?: Partial<RichTextField> & { admin?: AdapterArguments['admin'] },
additions?: { additions?: {
elements?: RichTextElement[] elements?: RichTextElement[]
leaves?: RichTextLeaf[] leaves?: RichTextLeaf[]
@@ -19,68 +25,84 @@ const richText: RichText = (
elements: [], elements: [],
leaves: [], leaves: [],
}, },
) => ) => {
deepMerge<RichTextField, Partial<RichTextField>>( const slateOptions = deepMerge<AdapterArguments['admin'], AdapterArguments['admin']>(
overrides?.admin || {},
{ {
name: 'richText', upload: {
type: 'richText', collections: {
required: true, media: {
admin: { fields: [
upload: { {
collections: { type: 'richText',
media: { name: 'caption',
fields: [ label: 'Caption',
{ editor: slateEditor({
type: 'richText',
name: 'caption',
label: 'Caption',
admin: { admin: {
elements: [...elements], elements: [...elements],
leaves: [...leaves], leaves: [...leaves],
}, },
},
{
type: 'radio',
name: 'alignment',
label: 'Alignment',
options: [
{
label: 'Left',
value: 'left',
},
{
label: 'Center',
value: 'center',
},
{
label: 'Right',
value: 'right',
},
],
},
{
name: 'enableLink',
type: 'checkbox',
label: 'Enable Link',
},
link({
appearances: false,
disableLabel: true,
overrides: {
admin: {
condition: (_, data) => Boolean(data?.enableLink),
},
},
}), }),
], },
}, {
type: 'radio',
name: 'alignment',
label: 'Alignment',
options: [
{
label: 'Left',
value: 'left',
},
{
label: 'Center',
value: 'center',
},
{
label: 'Right',
value: 'right',
},
],
},
{
name: 'enableLink',
type: 'checkbox',
label: 'Enable Link',
},
link({
appearances: false,
disableLabel: true,
overrides: {
admin: {
condition: (_, data) => Boolean(data?.enableLink),
},
},
}),
],
}, },
}, },
elements: [...elements, ...(additions.elements || [])],
leaves: [...leaves, ...(additions.leaves || [])],
}, },
elements: [...elements, ...(additions.elements || [])],
leaves: [...leaves, ...(additions.leaves || [])],
}, },
overrides || {},
) )
const fieldOverrides = {
...(overrides || {}),
}
delete fieldOverrides.admin
return deepMerge<RichTextField, Partial<RichTextField>>(
{
name: 'richText',
type: 'richText',
required: true,
editor: slateEditor({
admin: slateOptions,
}),
},
fieldOverrides || {},
)
}
export default richText export default richText

View File

@@ -1,7 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
// eslint-disable-next-line no-use-before-define // eslint-disable-next-line no-use-before-define
import React from 'react' import React from 'react'
import { ElementButton } from 'payload/components/rich-text' import ElementButton from '@payloadcms/richtext-slate/dist/field/elements/Button'
import Icon from '../Icon' import Icon from '../Icon'

View File

@@ -1,4 +1,4 @@
import type { RichTextCustomElement } from 'payload/types' import type { RichTextCustomElement } from '@payloadcms/richtext-slate/dist/types'
import Button from './Button' import Button from './Button'
import Element from './Element' import Element from './Element'

View File

@@ -1,4 +1,4 @@
import type { RichTextCustomElement } from 'payload/types' import type { RichTextCustomElement } from '@payloadcms/richtext-slate/dist/types'
import type { BaseEditor } from 'slate' import type { BaseEditor } from 'slate'
type RichTextPlugin = Exclude<RichTextCustomElement['plugins'], undefined>[0] type RichTextPlugin = Exclude<RichTextCustomElement['plugins'], undefined>[0]

View File

@@ -1,7 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
// eslint-disable-next-line no-use-before-define // eslint-disable-next-line no-use-before-define
import React from 'react' import React from 'react'
import { ElementButton } from 'payload/components/rich-text' import ElementButton from '@payloadcms/richtext-slate/dist/field/elements/Button'
import Icon from '../Icon' import Icon from '../Icon'

View File

@@ -1,4 +1,4 @@
import type { RichTextCustomElement } from 'payload/types' import type { RichTextCustomElement } from '@payloadcms/richtext-slate/dist/types'
import Button from './Button' import Button from './Button'
import Element from './Element' import Element from './Element'

View File

@@ -1,4 +1,4 @@
import type { RichTextCustomElement } from 'payload/types' import type { RichTextCustomElement } from '@payloadcms/richtext-slate/dist/types'
import type { BaseEditor } from 'slate' import type { BaseEditor } from 'slate'
type RichTextPlugin = Exclude<RichTextCustomElement['plugins'], undefined>[0] type RichTextPlugin = Exclude<RichTextCustomElement['plugins'], undefined>[0]

View File

@@ -1,4 +1,4 @@
import type { RichTextLeaf } from 'payload/dist/fields/config/types' import type { RichTextLeaf } from '@payloadcms/richtext-slate/dist/types'
const defaultLeaves: RichTextLeaf[] = ['bold', 'italic', 'underline'] const defaultLeaves: RichTextLeaf[] = ['bold', 'italic', 'underline']

View File

@@ -21,6 +21,8 @@ export interface Config {
categories: Category categories: Category
users: User users: User
redirects: Redirect redirects: Redirect
'payload-preferences': PayloadPreference
'payload-migrations': PayloadMigration
} }
globals: { globals: {
settings: Settings settings: Settings
@@ -42,8 +44,8 @@ export interface Page {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -64,8 +66,8 @@ export interface Page {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -89,8 +91,8 @@ export interface Page {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -120,21 +122,21 @@ export interface Page {
limit?: number limit?: number
selectedDocs?: selectedDocs?:
| { | {
value: string
relationTo: 'products' relationTo: 'products'
value: string
}[] }[]
| { | {
value: Product
relationTo: 'products' relationTo: 'products'
value: Product
}[] }[]
populatedDocs?: populatedDocs?:
| { | {
value: string
relationTo: 'products' relationTo: 'products'
value: string
}[] }[]
| { | {
value: Product
relationTo: 'products' relationTo: 'products'
value: Product
}[] }[]
populatedDocsTotal?: number populatedDocsTotal?: number
id?: string id?: string
@@ -195,8 +197,8 @@ export interface Product {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -220,8 +222,8 @@ export interface Product {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -251,21 +253,21 @@ export interface Product {
limit?: number limit?: number
selectedDocs?: selectedDocs?:
| { | {
value: string
relationTo: 'products' relationTo: 'products'
value: string
}[] }[]
| { | {
value: Product
relationTo: 'products' relationTo: 'products'
value: Product
}[] }[]
populatedDocs?: populatedDocs?:
| { | {
value: string
relationTo: 'products' relationTo: 'products'
value: string
}[] }[]
| { | {
value: Product
relationTo: 'products' relationTo: 'products'
value: Product
}[] }[]
populatedDocsTotal?: number populatedDocsTotal?: number
id?: string id?: string
@@ -287,8 +289,8 @@ export interface Product {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -312,8 +314,8 @@ export interface Product {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -343,21 +345,21 @@ export interface Product {
limit?: number limit?: number
selectedDocs?: selectedDocs?:
| { | {
value: string
relationTo: 'products' relationTo: 'products'
value: string
}[] }[]
| { | {
value: Product
relationTo: 'products' relationTo: 'products'
value: Product
}[] }[]
populatedDocs?: populatedDocs?:
| { | {
value: string
relationTo: 'products' relationTo: 'products'
value: string
}[] }[]
| { | {
value: Product
relationTo: 'products' relationTo: 'products'
value: Product
}[] }[]
populatedDocsTotal?: number populatedDocsTotal?: number
id?: string id?: string
@@ -420,18 +422,44 @@ export interface Redirect {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
reference: reference:
| { | {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
| { | {
value: string | Product
relationTo: 'products' relationTo: 'products'
value: string | Product
} }
url: string url: string
} }
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
export interface PayloadPreference {
id: string
user: {
relationTo: 'users'
value: string | User
}
key?: string
value?:
| {
[k: string]: unknown
}
| unknown[]
| string
| number
| boolean
| null
updatedAt: string
createdAt: string
}
export interface PayloadMigration {
id: string
name?: string
batch?: number
updatedAt: string
createdAt: string
}
export interface Settings { export interface Settings {
id: string id: string
productsPage?: string | Page productsPage?: string | Page
@@ -445,8 +473,8 @@ export interface Header {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -463,8 +491,8 @@ export interface Footer {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -474,3 +502,24 @@ export interface Footer {
updatedAt?: string updatedAt?: string
createdAt?: string createdAt?: string
} }
declare module 'payload' {
export interface GeneratedTypes {
collections: {
pages: Page
products: Product
orders: Order
media: Media
categories: Category
users: User
redirects: Redirect
'payload-preferences': PayloadPreference
'payload-migrations': PayloadMigration
}
globals: {
settings: Settings
header: Header
footer: Footer
}
}
}

View File

@@ -1,3 +1,5 @@
import { webpackBundler } from '@payloadcms/bundler-webpack' // bundler-import
import { mongooseAdapter } from '@payloadcms/db-mongodb' // database-adapter-import
import { payloadCloud } from '@payloadcms/plugin-cloud' import { payloadCloud } from '@payloadcms/plugin-cloud'
// import formBuilder from '@payloadcms/plugin-form-builder' // import formBuilder from '@payloadcms/plugin-form-builder'
import nestedDocs from '@payloadcms/plugin-nested-docs' import nestedDocs from '@payloadcms/plugin-nested-docs'
@@ -5,6 +7,7 @@ import redirects from '@payloadcms/plugin-redirects'
import seo from '@payloadcms/plugin-seo' import seo from '@payloadcms/plugin-seo'
import type { GenerateTitle } from '@payloadcms/plugin-seo/types' import type { GenerateTitle } from '@payloadcms/plugin-seo/types'
import stripePlugin from '@payloadcms/plugin-stripe' import stripePlugin from '@payloadcms/plugin-stripe'
import { slateEditor } from '@payloadcms/richtext-slate' // editor-import
import dotenv from 'dotenv' import dotenv from 'dotenv'
import path from 'path' import path from 'path'
import { buildConfig } from 'payload/config' import { buildConfig } from 'payload/config'
@@ -40,6 +43,7 @@ dotenv.config({
export default buildConfig({ export default buildConfig({
admin: { admin: {
user: Users.slug, user: Users.slug,
bundler: webpackBundler(), // bundler-config
components: { components: {
// The `BeforeLogin` component renders a message that you see while logging into your admin panel. // The `BeforeLogin` component renders a message that you see while logging into your admin panel.
// Feel free to delete this at any time. Simply remove the line below and the import `BeforeLogin` statement on line 15. // Feel free to delete this at any time. Simply remove the line below and the import `BeforeLogin` statement on line 15.
@@ -48,24 +52,35 @@ export default buildConfig({
// Feel free to delete this at any time. Simply remove the line below and the import `BeforeDashboard` statement on line 15. // Feel free to delete this at any time. Simply remove the line below and the import `BeforeDashboard` statement on line 15.
beforeDashboard: [BeforeDashboard], beforeDashboard: [BeforeDashboard],
}, },
webpack: config => ({ webpack: config => {
...config, return {
resolve: { ...config,
...config.resolve, resolve: {
alias: { ...config.resolve,
...config.resolve?.alias, alias: {
[path.resolve(__dirname, 'collections/Products/hooks/beforeChange')]: mockModulePath, ...config.resolve?.alias,
[path.resolve(__dirname, 'collections/Users/hooks/createStripeCustomer')]: mockModulePath, dotenv: path.resolve(__dirname, './dotenv.js'),
[path.resolve(__dirname, 'collections/Users/endpoints/customer')]: mockModulePath, [path.resolve(__dirname, 'collections/Products/hooks/beforeChange')]: mockModulePath,
[path.resolve(__dirname, 'endpoints/create-payment-intent')]: mockModulePath, [path.resolve(__dirname, 'collections/Users/hooks/createStripeCustomer')]:
[path.resolve(__dirname, 'endpoints/customers')]: mockModulePath, mockModulePath,
[path.resolve(__dirname, 'endpoints/products')]: mockModulePath, [path.resolve(__dirname, 'collections/Users/endpoints/customer')]: mockModulePath,
stripe: mockModulePath, [path.resolve(__dirname, 'endpoints/create-payment-intent')]: mockModulePath,
express: mockModulePath, [path.resolve(__dirname, 'endpoints/customers')]: mockModulePath,
[path.resolve(__dirname, 'endpoints/products')]: mockModulePath,
[path.resolve(__dirname, 'endpoints/seed')]: mockModulePath,
stripe: mockModulePath,
express: mockModulePath,
},
}, },
}, }
}), },
}, },
editor: slateEditor({}), // editor-config
// database-adapter-config-start
db: mongooseAdapter({
url: process.env.DATABASE_URI,
}),
// database-adapter-config-end
serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL, serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL,
collections: [Pages, Products, Orders, Media, Categories, Users], collections: [Pages, Products, Orders, Media, Categories, Users],
globals: [Settings, Header, Footer], globals: [Settings, Header, Footer],

View File

@@ -40,13 +40,13 @@ export const seed = async (payload: Payload): Promise<void> => {
await Promise.all([ await Promise.all([
...collections.map(async collection => ...collections.map(async collection =>
payload.delete({ payload.delete({
collection, collection: collection as 'media',
where: {}, where: {},
}), }),
), // eslint-disable-line function-paren-newline ), // eslint-disable-line function-paren-newline
...globals.map(async global => ...globals.map(async global =>
payload.updateGlobal({ payload.updateGlobal({
slug: global, slug: global as 'header',
data: {}, data: {},
}), }),
), // eslint-disable-line function-paren-newline ), // eslint-disable-line function-paren-newline

View File

@@ -1,4 +1,6 @@
export const productsPage = { import type { Page } from '../payload-types'
export const productsPage: Omit<Page, 'updatedAt' | 'createdAt' | 'id'> = {
title: 'Products', title: 'Products',
slug: 'products', slug: 'products',
_status: 'published', _status: 'published',
@@ -8,6 +10,7 @@ export const productsPage = {
}, },
hero: { hero: {
type: 'lowImpact', type: 'lowImpact',
media: null,
richText: [ richText: [
{ {
type: 'h1', type: 'h1',

View File

@@ -25,7 +25,6 @@ app.get('/', (_, res) => {
const start = async (): Promise<void> => { const start = async (): Promise<void> => {
await payload.init({ await payload.init({
secret: process.env.PAYLOAD_SECRET || '', secret: process.env.PAYLOAD_SECRET || '',
mongoURL: process.env.MONGODB_URI || '',
express: app, express: app,
onInit: () => { onInit: () => {
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`) payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)

View File

@@ -18,7 +18,6 @@ const PORT = process.env.PORT || 3000
const start = async (): Promise<void> => { const start = async (): Promise<void> => {
await payload.init({ await payload.init({
secret: process.env.PAYLOAD_SECRET || '', secret: process.env.PAYLOAD_SECRET || '',
mongoURL: process.env.MONGODB_URI || '',
express: app, express: app,
onInit: () => { onInit: () => {
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`) payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,6 @@
# Payload vars
PORT=3000 PORT=3000
MONGODB_URI=mongodb://127.0.0.1/payload-template-website DATABASE_URI=mongodb://127.0.0.1/payload-template-website
PAYLOAD_SECRET=098732498612hkjhsfjs2987 PAYLOAD_SECRET=3c543dbf662b4d12d8e30854
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000 PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
PAYLOAD_PUBLIC_DRAFT_SECRET=EXAMPLE_DRAFT_SECRET PAYLOAD_PUBLIC_SITE_URL=http://localhost:3000
REVALIDATION_KEY=EXAMPLE_REVALIDATION_KEY NEXT_PUBLIC_SERVER_URL=http://localhost:3000
# Next.js vars
NEXT_PUBLIC_SERVER_URL=http://localhost:3000
NEXT_PUBLIC_IS_LIVE=
NEXT_PRIVATE_DRAFT_SECRET=EXAMPLE_DRAFT_SECRET
NEXT_PRIVATE_REVALIDATION_KEY=EXAMPLE_REVALIDATION_KEY

View File

@@ -1,11 +1,10 @@
version: '3' version: '3'
services: services:
payload: payload:
image: node:18-alpine image: node:18-alpine
ports: ports:
- "3000:3000" - '3000:3000'
volumes: volumes:
- .:/home/node/app - .:/home/node/app
- node_modules:/home/node/app/node_modules - node_modules:/home/node/app/node_modules
@@ -19,7 +18,7 @@ services:
mongo: mongo:
image: mongo:latest image: mongo:latest
ports: ports:
- "27017:27017" - '27017:27017'
command: command:
- --storageEngine=wiredTiger - --storageEngine=wiredTiger
volumes: volumes:

View File

@@ -1,6 +1,8 @@
{ {
"$schema": "https://json.schemastore.org/nodemon.json",
"ext": "ts", "ext": "ts",
"exec": "ts-node src/server.ts", "exec": "ts-node src/server.ts -- -I",
"stdin": false,
"ignore" : [ "ignore" : [
"src/app" "src/app"
] ]

View File

@@ -13,23 +13,26 @@
"build": "cross-env NODE_ENV=production yarn build:payload && yarn build:server && yarn copyfiles && yarn build:next", "build": "cross-env NODE_ENV=production yarn build:payload && yarn build:server && yarn copyfiles && yarn build:next",
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload/payload.config.js NODE_ENV=production node dist/server.js", "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload/payload.config.js NODE_ENV=production node dist/server.js",
"eject": "yarn remove next react react-dom @next/eslint-plugin-next && ts-node eject.ts", "eject": "yarn remove next react react-dom @next/eslint-plugin-next && ts-node eject.ts",
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/", "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,js}\" dist/",
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload/payload.config.ts payload generate:types", "generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload/payload.config.ts payload generate:types",
"generate:graphQLSchema": "PAYLOAD_CONFIG_PATH=src/payload/payload.config.ts payload generate:graphQLSchema", "generate:graphQLSchema": "PAYLOAD_CONFIG_PATH=src/payload/payload.config.ts payload generate:graphQLSchema",
"lint": "eslint src", "lint": "eslint src",
"lint:fix": "eslint --fix --ext .ts,.tsx src" "lint:fix": "eslint --fix --ext .ts,.tsx src"
}, },
"dependencies": { "dependencies": {
"@payloadcms/bundler-webpack": "latest",
"@payloadcms/db-mongodb": "latest",
"@payloadcms/plugin-cloud": "^2.0.0", "@payloadcms/plugin-cloud": "^2.0.0",
"@payloadcms/plugin-form-builder": "^1.0.13", "@payloadcms/plugin-form-builder": "^1.0.13",
"@payloadcms/plugin-nested-docs": "^1.0.4", "@payloadcms/plugin-nested-docs": "^1.0.4",
"@payloadcms/plugin-redirects": "^1.0.0", "@payloadcms/plugin-redirects": "^1.0.0",
"@payloadcms/plugin-seo": "^1.0.10", "@payloadcms/plugin-seo": "^1.0.10",
"@payloadcms/richtext-slate": "latest",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"next": "^13.4.8", "next": "^13.4.8",
"payload": "latest", "payload": "^2.0.0-beta.31",
"payload-admin-bar": "^1.0.6", "payload-admin-bar": "^1.0.6",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",

View File

@@ -1,3 +1,4 @@
import { slateEditor } from '@payloadcms/richtext-slate'
import path from 'path' import path from 'path'
import type { CollectionConfig } from 'payload/types' import type { CollectionConfig } from 'payload/types'
@@ -18,9 +19,11 @@ export const Media: CollectionConfig = {
{ {
name: 'caption', name: 'caption',
type: 'richText', type: 'richText',
admin: { editor: slateEditor({
elements: ['link'], admin: {
}, elements: ['link'],
},
}),
}, },
], ],
} }

View File

@@ -0,0 +1,3 @@
module.exports = {
config: () => null,
}

View File

@@ -1,4 +1,4 @@
import type { RichTextElement } from 'payload/dist/fields/config/types' import type { RichTextElement } from '@payloadcms/richtext-slate/dist/types'
import label from './label' import label from './label'
import largeBody from './largeBody' import largeBody from './largeBody'

View File

@@ -1,4 +1,10 @@
import type { RichTextElement, RichTextField, RichTextLeaf } from 'payload/dist/fields/config/types' import { slateEditor } from '@payloadcms/richtext-slate'
import type {
AdapterArguments,
RichTextElement,
RichTextLeaf,
} from '@payloadcms/richtext-slate/dist/types'
import type { RichTextField } from 'payload/dist/fields/config/types'
import deepMerge from '../../utilities/deepMerge' import deepMerge from '../../utilities/deepMerge'
import link from '../link' import link from '../link'
@@ -6,7 +12,7 @@ import elements from './elements'
import leaves from './leaves' import leaves from './leaves'
type RichText = ( type RichText = (
overrides?: Partial<RichTextField>, overrides?: Partial<RichTextField> & { admin?: AdapterArguments['admin'] },
additions?: { additions?: {
elements?: RichTextElement[] elements?: RichTextElement[]
leaves?: RichTextLeaf[] leaves?: RichTextLeaf[]
@@ -19,68 +25,84 @@ const richText: RichText = (
elements: [], elements: [],
leaves: [], leaves: [],
}, },
) => ) => {
deepMerge<RichTextField, Partial<RichTextField>>( const slateOptions = deepMerge<AdapterArguments['admin'], AdapterArguments['admin']>(
overrides?.admin || {},
{ {
name: 'richText', upload: {
type: 'richText', collections: {
required: true, media: {
admin: { fields: [
upload: { {
collections: { type: 'richText',
media: { name: 'caption',
fields: [ label: 'Caption',
{ editor: slateEditor({
type: 'richText',
name: 'caption',
label: 'Caption',
admin: { admin: {
elements: [...elements], elements: [...elements],
leaves: [...leaves], leaves: [...leaves],
}, },
},
{
type: 'radio',
name: 'alignment',
label: 'Alignment',
options: [
{
label: 'Left',
value: 'left',
},
{
label: 'Center',
value: 'center',
},
{
label: 'Right',
value: 'right',
},
],
},
{
name: 'enableLink',
type: 'checkbox',
label: 'Enable Link',
},
link({
appearances: false,
disableLabel: true,
overrides: {
admin: {
condition: (_, data) => Boolean(data?.enableLink),
},
},
}), }),
], },
}, {
type: 'radio',
name: 'alignment',
label: 'Alignment',
options: [
{
label: 'Left',
value: 'left',
},
{
label: 'Center',
value: 'center',
},
{
label: 'Right',
value: 'right',
},
],
},
{
name: 'enableLink',
type: 'checkbox',
label: 'Enable Link',
},
link({
appearances: false,
disableLabel: true,
overrides: {
admin: {
condition: (_, data) => Boolean(data?.enableLink),
},
},
}),
],
}, },
}, },
elements: [...elements, ...(additions.elements || [])],
leaves: [...leaves, ...(additions.leaves || [])],
}, },
elements: [...elements, ...(additions.elements || [])],
leaves: [...leaves, ...(additions.leaves || [])],
}, },
overrides || {},
) )
const fieldOverrides = {
...(overrides || {}),
}
delete fieldOverrides.admin
return deepMerge<RichTextField, Partial<RichTextField>>(
{
name: 'richText',
type: 'richText',
required: true,
editor: slateEditor({
admin: slateOptions,
}),
},
fieldOverrides || {},
)
}
export default richText export default richText

View File

@@ -1,7 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
// eslint-disable-next-line no-use-before-define // eslint-disable-next-line no-use-before-define
import React from 'react' import React from 'react'
import { ElementButton } from 'payload/components/rich-text' import ElementButton from '@payloadcms/richtext-slate/dist/field/elements/Button'
import Icon from '../Icon' import Icon from '../Icon'

View File

@@ -0,0 +1,18 @@
/* eslint-disable no-use-before-define */
// eslint-disable-next-line import/no-extraneous-dependencies
import React from 'react'
const Icon = () => (
<svg width="25" height="25" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M8.08884 15.2753L8.79758 17.7598H10.916L7.28663 6.41986H5.46413L1.75684 17.7598H3.88308L4.59962 15.2753H8.08884ZM5.10586 13.5385L6.36759 9.20812L7.59816 13.5385H5.10586Z"
fill="currentColor"
/>
<path
d="M21.1778 15.2753L21.8865 17.7598H24.005L20.3756 6.41986H18.5531L14.8458 17.7598H16.972L17.6886 15.2753H21.1778ZM18.1948 13.5385L19.4565 9.20812L20.6871 13.5385H18.1948Z"
fill="currentColor"
/>
</svg>
)
export default Icon

View File

@@ -1,4 +1,4 @@
import type { RichTextCustomElement } from 'payload/types' import type { RichTextCustomElement } from '@payloadcms/richtext-slate/dist/types'
import Button from './Button' import Button from './Button'
import Element from './Element' import Element from './Element'

View File

@@ -1,4 +1,4 @@
import type { RichTextCustomElement } from 'payload/types' import type { RichTextCustomElement } from '@payloadcms/richtext-slate/dist/types'
import type { BaseEditor } from 'slate' import type { BaseEditor } from 'slate'
type RichTextPlugin = Exclude<RichTextCustomElement['plugins'], undefined>[0] type RichTextPlugin = Exclude<RichTextCustomElement['plugins'], undefined>[0]

View File

@@ -1,7 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
// eslint-disable-next-line no-use-before-define // eslint-disable-next-line no-use-before-define
import React from 'react' import React from 'react'
import { ElementButton } from 'payload/components/rich-text' import ElementButton from '@payloadcms/richtext-slate/dist/field/elements/Button'
import Icon from '../Icon' import Icon from '../Icon'

View File

@@ -0,0 +1,18 @@
/* eslint-disable no-use-before-define */
// eslint-disable-next-line import/no-extraneous-dependencies
import React from 'react'
const Icon = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25">
<path
d="M6.61695 9.94917L3.16602 19.25H4.65415L5.37256 17.2102H9.41361L10.1448 19.25H11.7356L8.23337 9.94917H6.61695ZM5.80874 15.9787L7.37384 11.5399L8.96461 15.9787H5.80874Z"
fill="currentColor"
/>
<path
d="M14.2739 5.75H16.7691L21.8339 19.25H19.2457L18.1843 16.2521H12.7098L11.667 19.25H9.24635L14.2739 5.75ZM13.3988 14.2783H17.4767L15.4284 8.48724L13.3988 14.2783Z"
fill="currentColor"
/>
</svg>
)
export default Icon

View File

@@ -1,4 +1,4 @@
import type { RichTextCustomElement } from 'payload/types' import type { RichTextCustomElement } from '@payloadcms/richtext-slate/dist/types'
import Button from './Button' import Button from './Button'
import Element from './Element' import Element from './Element'

View File

@@ -1,4 +1,4 @@
import type { RichTextCustomElement } from 'payload/types' import type { RichTextCustomElement } from '@payloadcms/richtext-slate/dist/types'
import type { BaseEditor } from 'slate' import type { BaseEditor } from 'slate'
type RichTextPlugin = Exclude<RichTextCustomElement['plugins'], undefined>[0] type RichTextPlugin = Exclude<RichTextCustomElement['plugins'], undefined>[0]

View File

@@ -1,4 +1,4 @@
import type { RichTextLeaf } from 'payload/dist/fields/config/types' import type { RichTextLeaf } from '@payloadcms/richtext-slate/dist/types'
const defaultLeaves: RichTextLeaf[] = ['bold', 'italic', 'underline'] const defaultLeaves: RichTextLeaf[] = ['bold', 'italic', 'underline']

View File

@@ -15,6 +15,9 @@ export interface Config {
categories: Category categories: Category
users: User users: User
comments: Comment comments: Comment
redirects: Redirect
'payload-preferences': PayloadPreference
'payload-migrations': PayloadMigration
} }
globals: { globals: {
settings: Settings settings: Settings
@@ -36,8 +39,8 @@ export interface Page {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -58,8 +61,8 @@ export interface Page {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -83,8 +86,8 @@ export interface Page {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -115,43 +118,43 @@ export interface Page {
selectedDocs?: selectedDocs?:
| ( | (
| { | {
value: string
relationTo: 'posts' relationTo: 'posts'
value: string
} }
| { | {
value: string
relationTo: 'projects' relationTo: 'projects'
value: string
} }
)[] )[]
| ( | (
| { | {
value: Post
relationTo: 'posts' relationTo: 'posts'
value: Post
} }
| { | {
value: Project
relationTo: 'projects' relationTo: 'projects'
value: Project
} }
)[] )[]
populatedDocs?: populatedDocs?:
| ( | (
| { | {
value: string
relationTo: 'posts' relationTo: 'posts'
value: string
} }
| { | {
value: string
relationTo: 'projects' relationTo: 'projects'
value: string
} }
)[] )[]
| ( | (
| { | {
value: Post
relationTo: 'posts' relationTo: 'posts'
value: Post
} }
| { | {
value: Project
relationTo: 'projects' relationTo: 'projects'
value: Project
} }
)[] )[]
populatedDocsTotal?: number populatedDocsTotal?: number
@@ -218,8 +221,8 @@ export interface Post {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -240,8 +243,8 @@ export interface Post {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -265,8 +268,8 @@ export interface Post {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -297,43 +300,43 @@ export interface Post {
selectedDocs?: selectedDocs?:
| ( | (
| { | {
value: string
relationTo: 'posts' relationTo: 'posts'
value: string
} }
| { | {
value: string
relationTo: 'projects' relationTo: 'projects'
value: string
} }
)[] )[]
| ( | (
| { | {
value: Post
relationTo: 'posts' relationTo: 'posts'
value: Post
} }
| { | {
value: Project
relationTo: 'projects' relationTo: 'projects'
value: Project
} }
)[] )[]
populatedDocs?: populatedDocs?:
| ( | (
| { | {
value: string
relationTo: 'posts' relationTo: 'posts'
value: string
} }
| { | {
value: string
relationTo: 'projects' relationTo: 'projects'
value: string
} }
)[] )[]
| ( | (
| { | {
value: Post
relationTo: 'posts' relationTo: 'posts'
value: Post
} }
| { | {
value: Project
relationTo: 'projects' relationTo: 'projects'
value: Project
} }
)[] )[]
populatedDocsTotal?: number populatedDocsTotal?: number
@@ -354,8 +357,8 @@ export interface Post {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -379,8 +382,8 @@ export interface Post {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -411,43 +414,43 @@ export interface Post {
selectedDocs?: selectedDocs?:
| ( | (
| { | {
value: string
relationTo: 'posts' relationTo: 'posts'
value: string
} }
| { | {
value: string
relationTo: 'projects' relationTo: 'projects'
value: string
} }
)[] )[]
| ( | (
| { | {
value: Post
relationTo: 'posts' relationTo: 'posts'
value: Post
} }
| { | {
value: Project
relationTo: 'projects' relationTo: 'projects'
value: Project
} }
)[] )[]
populatedDocs?: populatedDocs?:
| ( | (
| { | {
value: string
relationTo: 'posts' relationTo: 'posts'
value: string
} }
| { | {
value: string
relationTo: 'projects' relationTo: 'projects'
value: string
} }
)[] )[]
| ( | (
| { | {
value: Post
relationTo: 'posts' relationTo: 'posts'
value: Post
} }
| { | {
value: Project
relationTo: 'projects' relationTo: 'projects'
value: Project
} }
)[] )[]
populatedDocsTotal?: number populatedDocsTotal?: number
@@ -497,8 +500,8 @@ export interface Project {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -519,8 +522,8 @@ export interface Project {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -544,8 +547,8 @@ export interface Project {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -576,43 +579,43 @@ export interface Project {
selectedDocs?: selectedDocs?:
| ( | (
| { | {
value: string
relationTo: 'posts' relationTo: 'posts'
value: string
} }
| { | {
value: string
relationTo: 'projects' relationTo: 'projects'
value: string
} }
)[] )[]
| ( | (
| { | {
value: Post
relationTo: 'posts' relationTo: 'posts'
value: Post
} }
| { | {
value: Project
relationTo: 'projects' relationTo: 'projects'
value: Project
} }
)[] )[]
populatedDocs?: populatedDocs?:
| ( | (
| { | {
value: string
relationTo: 'posts' relationTo: 'posts'
value: string
} }
| { | {
value: string
relationTo: 'projects' relationTo: 'projects'
value: string
} }
)[] )[]
| ( | (
| { | {
value: Post
relationTo: 'posts' relationTo: 'posts'
value: Post
} }
| { | {
value: Project
relationTo: 'projects' relationTo: 'projects'
value: Project
} }
)[] )[]
populatedDocsTotal?: number populatedDocsTotal?: number
@@ -645,6 +648,51 @@ export interface Comment {
createdAt: string createdAt: string
_status?: 'draft' | 'published' _status?: 'draft' | 'published'
} }
export interface Redirect {
id: string
from: string
to: {
type?: 'reference' | 'custom'
reference:
| {
relationTo: 'pages'
value: string | Page
}
| {
relationTo: 'posts'
value: string | Post
}
url: string
}
updatedAt: string
createdAt: string
}
export interface PayloadPreference {
id: string
user: {
relationTo: 'users'
value: string | User
}
key?: string
value?:
| {
[k: string]: unknown
}
| unknown[]
| string
| number
| boolean
| null
updatedAt: string
createdAt: string
}
export interface PayloadMigration {
id: string
name?: string
batch?: number
updatedAt: string
createdAt: string
}
export interface Settings { export interface Settings {
id: string id: string
postsPage?: string | Page postsPage?: string | Page
@@ -659,8 +707,8 @@ export interface Header {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -677,8 +725,8 @@ export interface Footer {
type?: 'reference' | 'custom' type?: 'reference' | 'custom'
newTab?: boolean newTab?: boolean
reference: { reference: {
value: string | Page
relationTo: 'pages' relationTo: 'pages'
value: string | Page
} }
url: string url: string
label: string label: string
@@ -688,3 +736,25 @@ export interface Footer {
updatedAt?: string updatedAt?: string
createdAt?: string createdAt?: string
} }
declare module 'payload' {
export interface GeneratedTypes {
collections: {
pages: Page
posts: Post
projects: Project
media: Media
categories: Category
users: User
comments: Comment
redirects: Redirect
'payload-preferences': PayloadPreference
'payload-migrations': PayloadMigration
}
globals: {
settings: Settings
header: Header
footer: Footer
}
}
}

View File

@@ -1,9 +1,11 @@
import { webpackBundler } from '@payloadcms/bundler-webpack' // bundler-import
import { mongooseAdapter } from '@payloadcms/db-mongodb' // database-adapter-import
import { payloadCloud } from '@payloadcms/plugin-cloud' import { payloadCloud } from '@payloadcms/plugin-cloud'
// import formBuilder from '@payloadcms/plugin-form-builder'
import nestedDocs from '@payloadcms/plugin-nested-docs' import nestedDocs from '@payloadcms/plugin-nested-docs'
import redirects from '@payloadcms/plugin-redirects' import redirects from '@payloadcms/plugin-redirects'
import seo from '@payloadcms/plugin-seo' import seo from '@payloadcms/plugin-seo'
import type { GenerateTitle } from '@payloadcms/plugin-seo/types' import type { GenerateTitle } from '@payloadcms/plugin-seo/types'
import { slateEditor } from '@payloadcms/richtext-slate' // editor-import
import dotenv from 'dotenv' import dotenv from 'dotenv'
import path from 'path' import path from 'path'
import { buildConfig } from 'payload/config' import { buildConfig } from 'payload/config'
@@ -33,6 +35,7 @@ dotenv.config({
export default buildConfig({ export default buildConfig({
admin: { admin: {
user: Users.slug, user: Users.slug,
bundler: webpackBundler(), // bundler-config
components: { components: {
// The `BeforeLogin` component renders a message that you see while logging into your admin panel. // The `BeforeLogin` component renders a message that you see while logging into your admin panel.
// Feel free to delete this at any time. Simply remove the line below and the import `BeforeLogin` statement on line 15. // Feel free to delete this at any time. Simply remove the line below and the import `BeforeLogin` statement on line 15.
@@ -41,7 +44,27 @@ export default buildConfig({
// Feel free to delete this at any time. Simply remove the line below and the import `BeforeDashboard` statement on line 15. // Feel free to delete this at any time. Simply remove the line below and the import `BeforeDashboard` statement on line 15.
beforeDashboard: [BeforeDashboard], beforeDashboard: [BeforeDashboard],
}, },
webpack: config => ({
...config,
resolve: {
...config.resolve,
alias: {
...config.resolve.alias,
dotenv: path.resolve(__dirname, './dotenv.js'),
[path.resolve(__dirname, './endpoints/seed')]: path.resolve(
__dirname,
'./emptyModuleMock.js',
),
},
},
}),
}, },
editor: slateEditor({}), // editor-config
// database-adapter-config-start
db: mongooseAdapter({
url: process.env.DATABASE_URI,
}),
// database-adapter-config-end
serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL, serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL,
collections: [Pages, Posts, Projects, Media, Categories, Users, Comments], collections: [Pages, Posts, Projects, Media, Categories, Users, Comments],
globals: [Settings, Header, Footer], globals: [Settings, Header, Footer],

View File

@@ -42,13 +42,13 @@ export const seed = async (payload: Payload): Promise<void> => {
await Promise.all([ await Promise.all([
...collections.map(async collection => ...collections.map(async collection =>
payload.delete({ payload.delete({
collection, collection: collection as 'media',
where: {}, where: {},
}), }),
), // eslint-disable-line function-paren-newline ), // eslint-disable-line function-paren-newline
...globals.map(async global => ...globals.map(async global =>
payload.updateGlobal({ payload.updateGlobal({
slug: global, slug: global as 'header',
data: {}, data: {},
}), }),
), // eslint-disable-line function-paren-newline ), // eslint-disable-line function-paren-newline

View File

@@ -25,7 +25,6 @@ app.get('/', (_, res) => {
const start = async (): Promise<void> => { const start = async (): Promise<void> => {
await payload.init({ await payload.init({
secret: process.env.PAYLOAD_SECRET || '', secret: process.env.PAYLOAD_SECRET || '',
mongoURL: process.env.MONGODB_URI || '',
express: app, express: app,
onInit: () => { onInit: () => {
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`) payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)

View File

@@ -18,7 +18,6 @@ const PORT = process.env.PORT || 3000
const start = async (): Promise<void> => { const start = async (): Promise<void> => {
await payload.init({ await payload.init({
secret: process.env.PAYLOAD_SECRET || '', secret: process.env.PAYLOAD_SECRET || '',
mongoURL: process.env.MONGODB_URI || '',
express: app, express: app,
onInit: () => { onInit: () => {
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`) payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)

File diff suppressed because it is too large Load Diff