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
30 lines
664 B
TypeScript
30 lines
664 B
TypeScript
import type { NextServerOptions } from 'next/dist/server/next.js'
|
|
|
|
import { createServer } from 'http'
|
|
import next from 'next'
|
|
import open from 'open'
|
|
import path from 'path'
|
|
import { fileURLToPath, parse } from 'url'
|
|
|
|
const dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
|
|
const opts: NextServerOptions = {
|
|
dev: true,
|
|
dir: dirname,
|
|
}
|
|
|
|
// @ts-expect-error next types do not import
|
|
const app = next(opts)
|
|
const handle = app.getRequestHandler()
|
|
|
|
await app.prepare()
|
|
|
|
await open(`http://localhost:3000/admin`)
|
|
|
|
const server = createServer((req, res) => {
|
|
const parsedUrl = parse(req.url!, true)
|
|
void handle(req, res, parsedUrl)
|
|
})
|
|
|
|
server.listen(3000)
|