Updates the plugin template and adds it to the monorepo
Includes:
* Integration testing setup
* Adding custom client / server components via a plugin
* The same building setup that we use for our plugins in the monorepo
* `create-payload-app` dynamically configures the project based on the
name:`dev/tsconfig.json`, `src/index.ts`, `dev/payload.config.ts`
For example, from project name: `payload-plugin-cool`
`src/index.ts`:
```ts
export type PayloadPluginCoolConfig = {
/**
* List of collections to add a custom field
*/
collections?: Partial<Record<CollectionSlug, true>>
disabled?: boolean
}
export const payloadPluginCool =
(pluginOptions: PayloadPluginCoolConfig) =>
/// ...
```
`dev/tsconfig.json`:
```json
{
"extends": "../tsconfig.json",
"exclude": [],
"include": [
"**/*.ts",
"**/*.tsx",
"../src/**/*.ts",
"../src/**/*.tsx",
"next.config.mjs",
".next/types/**/*.ts"
],
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@payload-config": [
"./payload.config.ts"
],
"payload-plugin-cool": [
"../src/index.ts"
],
"payload-plugin-cool/client": [
"../src/exports/client.ts"
],
"payload-plugin-cool/rsc": [
"../src/exports/rsc.ts"
]
},
"noEmit": true
}
}
```
`./dev/payload.config.ts`
```
import { payloadPluginCool } from 'payload-plugin-cool'
///
plugins: [
payloadPluginCool({
collections: {
posts: true,
},
}),
],
```
Example of published plugin
https://www.npmjs.com/package/payload-plugin-cool
33 lines
811 B
TypeScript
33 lines
811 B
TypeScript
import type { ServerFunctionClient } from 'payload'
|
|
|
|
import '@payloadcms/next/css'
|
|
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
|
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
|
|
import config from '@payload-config'
|
|
import { handleServerFunctions, RootLayout } from '@payloadcms/next/layouts'
|
|
import React from 'react'
|
|
|
|
import { importMap } from './admin/importMap.js'
|
|
import './custom.scss'
|
|
|
|
type Args = {
|
|
children: React.ReactNode
|
|
}
|
|
|
|
const serverFunction: ServerFunctionClient = async function (args) {
|
|
'use server'
|
|
return handleServerFunctions({
|
|
...args,
|
|
config,
|
|
importMap,
|
|
})
|
|
}
|
|
|
|
const Layout = ({ children }: Args) => (
|
|
<RootLayout config={config} importMap={importMap} serverFunction={serverFunction}>
|
|
{children}
|
|
</RootLayout>
|
|
)
|
|
|
|
export default Layout
|