payload-ai 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +10 -0
- package/.eslintrc.js +17 -0
- package/.github/workflows/publish.yml +21 -0
- package/.github/workflows/test.yml +20 -0
- package/.prettierrc.js +8 -0
- package/LICENSE +21 -0
- package/README.md +237 -0
- package/dev/.env.example +3 -0
- package/dev/Dockerfile +27 -0
- package/dev/docker-compose.yml +31 -0
- package/dev/jest.config.js +12 -0
- package/dev/nodemon.json +6 -0
- package/dev/package.json +35 -0
- package/dev/plugin.spec.ts +30 -0
- package/dev/src/collections/Examples.ts +18 -0
- package/dev/src/collections/Users.ts +15 -0
- package/dev/src/mocks/fileStub.js +1 -0
- package/dev/src/payload.config.ts +57 -0
- package/dev/src/server.ts +29 -0
- package/dev/tsconfig.json +34 -0
- package/dist/aiTranslate.d.ts +5 -0
- package/dist/aiTranslate.js +206 -0
- package/dist/aiTranslate.js.map +1 -0
- package/dist/components/AfterDashboard/index.d.ts +3 -0
- package/dist/components/AfterDashboard/index.js +17 -0
- package/dist/components/AfterDashboard/index.js.map +1 -0
- package/dist/components/Translator/index.d.ts +2 -0
- package/dist/components/Translator/index.js +87 -0
- package/dist/components/Translator/index.js.map +1 -0
- package/dist/handleTranslate.d.ts +3 -0
- package/dist/handleTranslate.js +55 -0
- package/dist/handleTranslate.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/mocks/mockFile.d.ts +1 -0
- package/dist/mocks/mockFile.js +3 -0
- package/dist/mocks/mockFile.js.map +1 -0
- package/dist/newCollection.d.ts +3 -0
- package/dist/newCollection.js +16 -0
- package/dist/newCollection.js.map +1 -0
- package/dist/onInitExtension.d.ts +3 -0
- package/dist/onInitExtension.js +17 -0
- package/dist/onInitExtension.js.map +1 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.js +171 -0
- package/dist/plugin.js.map +1 -0
- package/dist/types.d.ts +20 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/webpack.d.ts +3 -0
- package/dist/webpack.js +32 -0
- package/dist/webpack.js.map +1 -0
- package/eslint-config/index.js +15 -0
- package/eslint-config/rules/import.js +38 -0
- package/eslint-config/rules/prettier.js +7 -0
- package/eslint-config/rules/style.js +21 -0
- package/eslint-config/rules/typescript.js +628 -0
- package/package.json +52 -0
- package/src/aiTranslate.ts +150 -0
- package/src/components/AfterDashboard/index.scss +10 -0
- package/src/components/AfterDashboard/index.tsx +18 -0
- package/src/components/Translator/index.scss +10 -0
- package/src/components/Translator/index.tsx +43 -0
- package/src/handleTranslate.ts +41 -0
- package/src/index.ts +2 -0
- package/src/mocks/mockFile.js +1 -0
- package/src/newCollection.ts +16 -0
- package/src/onInitExtension.ts +16 -0
- package/src/plugin.ts +143 -0
- package/src/types.ts +22 -0
- package/src/webpack.ts +28 -0
- package/tsconfig.json +23 -0
package/.editorconfig
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
extends: ['./eslint-config'],
|
|
4
|
+
overrides: [
|
|
5
|
+
// Temporary overrides
|
|
6
|
+
{
|
|
7
|
+
files: ['dev/**/*.ts'],
|
|
8
|
+
rules: {
|
|
9
|
+
'import/no-relative-packages': 'off',
|
|
10
|
+
'no-process-env': 'off',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
excludes: [
|
|
15
|
+
'dev/plugin.spec.ts',
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Publish New Version
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [created]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v2
|
|
12
|
+
- uses: actions/setup-node@v2
|
|
13
|
+
with:
|
|
14
|
+
node-version: '14.x'
|
|
15
|
+
registry-url: 'https://registry.npmjs.org'
|
|
16
|
+
- run: yarn install
|
|
17
|
+
- run: yarn test
|
|
18
|
+
- run: yarn build
|
|
19
|
+
- run: yarn publish
|
|
20
|
+
env:
|
|
21
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v2
|
|
14
|
+
- uses: actions/setup-node@v2
|
|
15
|
+
with:
|
|
16
|
+
node-version: '14.x'
|
|
17
|
+
registry-url: 'https://registry.npmjs.org'
|
|
18
|
+
- run: yarn install
|
|
19
|
+
- run: cd dev && yarn install
|
|
20
|
+
- run: yarn test
|
package/.prettierrc.js
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Payload
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# Payload Plugin Template
|
|
2
|
+
|
|
3
|
+
Translate content to different languages using GPT.
|
|
4
|
+
|
|
5
|
+
Planned features:
|
|
6
|
+
|
|
7
|
+
- generate image alt text from GPT
|
|
8
|
+
- generate by field
|
|
9
|
+
- string translation using i18next
|
|
10
|
+
- generate SEO Text
|
|
11
|
+
- generate structured content
|
|
12
|
+
- custom access control
|
|
13
|
+
- custom overrides for translation
|
|
14
|
+
- generate images based on input
|
|
15
|
+
|
|
16
|
+
Payload is built with a robust infrastructure intended to support Plugins with ease. This provides a simple, modular, and reusable way for developers to extend the core capabilities of Payload.
|
|
17
|
+
|
|
18
|
+
To build your own Payload plugin, all you need is:
|
|
19
|
+
|
|
20
|
+
* An understanding of the basic Payload concepts
|
|
21
|
+
* And some JavaScript/Typescript experience
|
|
22
|
+
|
|
23
|
+
## Background
|
|
24
|
+
|
|
25
|
+
Here is a short recap on how to integrate plugins with Payload, to learn more visit the [plugin overview page](https://payloadcms.com/docs/plugins/overview).
|
|
26
|
+
|
|
27
|
+
### How to install a plugin
|
|
28
|
+
|
|
29
|
+
To install any plugin, simply add it to your payload.config() in the Plugin array.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import samplePlugin from 'sample-plugin';
|
|
33
|
+
|
|
34
|
+
export const config = buildConfig({
|
|
35
|
+
plugins: [
|
|
36
|
+
// You can pass options to the plugin
|
|
37
|
+
samplePlugin({
|
|
38
|
+
enabled: true,
|
|
39
|
+
}),
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Initialization
|
|
45
|
+
|
|
46
|
+
The initialization process goes in the following order:
|
|
47
|
+
|
|
48
|
+
1. Incoming config is validated
|
|
49
|
+
2. **Plugins execute**
|
|
50
|
+
3. Default options are integrated
|
|
51
|
+
4. Sanitization cleans and validates data
|
|
52
|
+
5. Final config gets initialized
|
|
53
|
+
|
|
54
|
+
## Building the Plugin
|
|
55
|
+
|
|
56
|
+
When you build a plugin, you are purely building a feature for your project and then abstracting it outside of the project.
|
|
57
|
+
|
|
58
|
+
### Template Files
|
|
59
|
+
|
|
60
|
+
In the [payload-plugin-template](https://github.com/payloadcms/payload-plugin-template), you will see a common file structure that is used across all plugins:
|
|
61
|
+
|
|
62
|
+
1. root folder
|
|
63
|
+
2. /src folder
|
|
64
|
+
3. /dev folder
|
|
65
|
+
|
|
66
|
+
#### Root
|
|
67
|
+
|
|
68
|
+
In the root folder, you will see various files that relate to the configuration of the plugin. We set up our environment in a similar manner in Payload core and across other projects, so hopefully these will look familiar:
|
|
69
|
+
|
|
70
|
+
* **README**.md* - This contains instructions on how to use the template. When you are ready, update this to contain instructions on how to use your Plugin.
|
|
71
|
+
* **package**.json* - Contains necessary scripts and dependencies. Overwrite the metadata in this file to describe your Plugin.
|
|
72
|
+
* .**editorconfig** - Defines settings to maintain consistent coding styles.
|
|
73
|
+
* .**eslintrc**.js - Eslint configuration for reporting on problematic patterns.
|
|
74
|
+
* .**gitignore** - List specific untracked files to omit from Git.
|
|
75
|
+
* .**prettierrc**.js - Configuration for Prettier code formatting.
|
|
76
|
+
* **LICENSE** - As part of the open-source community, we ship all plugins with an MIT license but it is not required.
|
|
77
|
+
* **tsconfig**.json - Configures the compiler options for TypeScript
|
|
78
|
+
|
|
79
|
+
**IMPORTANT***: You will need to modify these files.
|
|
80
|
+
|
|
81
|
+
#### Dev
|
|
82
|
+
|
|
83
|
+
In the dev folder, you’ll find a basic payload project, created with `npx create-payload-app` and the blank template.
|
|
84
|
+
|
|
85
|
+
The `samplePlugin` has already been installed to the `payload.config()` file in this project.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
plugins: [
|
|
89
|
+
samplePlugin({
|
|
90
|
+
enabled: false,
|
|
91
|
+
})
|
|
92
|
+
]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Later when you rename the plugin or add additional options, make sure to update them here.
|
|
96
|
+
|
|
97
|
+
You may wish to add collections or expand the test project depending on the purpose of your plugin. Just make sure to keep this dev environment as simplified as possible - users should be able to install your plugin without additional configuration required.
|
|
98
|
+
|
|
99
|
+
When you’re ready to start development, navigate into this folder with `cd dev`
|
|
100
|
+
|
|
101
|
+
And then start the project with `yarn dev` and pull up [http://localhost:3000/](http://localhost:3000/) in your browser.
|
|
102
|
+
|
|
103
|
+
#### Src
|
|
104
|
+
|
|
105
|
+
Now that we have our environment setup and we have a dev project ready to - it’s time to build the plugin!
|
|
106
|
+
|
|
107
|
+
**index.ts**
|
|
108
|
+
|
|
109
|
+
First up, the `src/index.ts` file. It is best practice not to build the plugin directly in this file, instead we use this to export the plugin and types from separate files.
|
|
110
|
+
|
|
111
|
+
**Plugin.ts**
|
|
112
|
+
|
|
113
|
+
To reiterate, the essence of a payload plugin is simply to extend the payload config - and that is exactly what we are doing in this file.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
export const samplePlugin =
|
|
117
|
+
(pluginOptions: PluginTypes) =>
|
|
118
|
+
(incomingConfig: Config): Config => {
|
|
119
|
+
let config = { ...incomingConfig }
|
|
120
|
+
|
|
121
|
+
// do something cool with the config here
|
|
122
|
+
|
|
123
|
+
return config
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
First, we receive the existing payload config along with any plugin options.
|
|
129
|
+
|
|
130
|
+
Then we set the variable `config` to be equal to the existing config.
|
|
131
|
+
|
|
132
|
+
From here, you can extend the config as you wish.
|
|
133
|
+
|
|
134
|
+
Finally, you return the config and that is it!
|
|
135
|
+
|
|
136
|
+
##### Spread Syntax
|
|
137
|
+
|
|
138
|
+
Spread syntax (or the spread operator) is a feature in JavaScript that uses the dot notation **(...)** to spread elements from arrays, strings, or objects into various contexts.
|
|
139
|
+
|
|
140
|
+
We are going to use spread syntax to allow us to add data to existing arrays without losing the existing data. It is crucial to spread the existing data correctly – else this can cause adverse behavior and conflicts with Payload config and other plugins.
|
|
141
|
+
|
|
142
|
+
Let’s say you want to build a plugin that adds a new collection:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
config.collections = [
|
|
146
|
+
...(config.collections || []),
|
|
147
|
+
// Add additional collections here
|
|
148
|
+
]
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
First we spread the `config.collections` to ensure that we don’t lose the existing collections, then you can add any additional collections just as you would in a regular payload config.
|
|
152
|
+
|
|
153
|
+
This same logic is applied to other properties like admin, hooks, globals:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
config.globals = [
|
|
157
|
+
...(config.globals || []),
|
|
158
|
+
// Add additional globals here
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
config.hooks = {
|
|
162
|
+
...(incomingConfig.hooks || {}),
|
|
163
|
+
// Add additional hooks here
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Some properties will be slightly different to extend, for instance the onInit property:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import { onInitExtension } from './onInitExtension' // example file
|
|
171
|
+
|
|
172
|
+
config.onInit = async payload => {
|
|
173
|
+
if (incomingConfig.onInit) await incomingConfig.onInit(payload)
|
|
174
|
+
// Add additional onInit code by defining an onInitExtension function
|
|
175
|
+
onInitExtension(pluginOptions, payload)
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
If you wish to add to the onInit, you must include the async/await. We don’t use spread syntax in this case, instead you must await the existing onInit before running additional functionality.
|
|
180
|
+
|
|
181
|
+
In the template, we have stubbed out a basic `onInitExtension` file that you can use, if not needed feel free to delete it.
|
|
182
|
+
|
|
183
|
+
##### File Aliasing
|
|
184
|
+
|
|
185
|
+
If your plugin uses packages or dependencies that are not browser compatible (fs, stripe, nodemailer, etc), you will need to alias them using your bundler to prevent getting errors in build.
|
|
186
|
+
|
|
187
|
+
You can read more about aliasing files with Webpack or Vite in the [excluding server modules](https://payloadcms.com/docs/admin/excluding-server-code#aliasing-server-only-modules) docs.
|
|
188
|
+
|
|
189
|
+
##### Types.ts
|
|
190
|
+
|
|
191
|
+
If your plugin has options, you should define and provide types for these options in a separate file which gets exported from the main index.ts.
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
export interface PluginTypes {
|
|
195
|
+
/**
|
|
196
|
+
* Enable or disable plugin
|
|
197
|
+
* @default false
|
|
198
|
+
*/
|
|
199
|
+
enabled?: boolean
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
If possible, include JSDoc comments to describe the options and their types. This allows a developer to see details about the options in their editor.
|
|
204
|
+
|
|
205
|
+
##### Testing
|
|
206
|
+
|
|
207
|
+
Having a test suite for your plugin is essential to ensure quality and stability. Jest is a popular testing framework, widely used for testing JavaScript and particularly for applications built with React.
|
|
208
|
+
|
|
209
|
+
Jest organizes tests into test suites and cases. We recommend creating individual tests based on the expected behavior of your plugin from start to finish.
|
|
210
|
+
|
|
211
|
+
Writing tests with Jest is very straightforward and you can learn more about how it works in the [Jest documentation.](https://jestjs.io/)
|
|
212
|
+
|
|
213
|
+
For this template, we stubbed out `plugin.spec.ts` in the `dev` folder where you can write your tests.
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
describe('Plugin tests', () => {
|
|
217
|
+
// Create tests to ensure expected behavior from the plugin
|
|
218
|
+
it('some condition that must be met', () => {
|
|
219
|
+
// Write your test logic here
|
|
220
|
+
expect(...)
|
|
221
|
+
})
|
|
222
|
+
})
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Best practices
|
|
226
|
+
|
|
227
|
+
With this tutorial and the `payload-plugin-template`, you should have everything you need to start building your own plugin.
|
|
228
|
+
In addition to the setup, here are other best practices aim we follow:
|
|
229
|
+
|
|
230
|
+
* **Providing an enable / disable option:** For a better user experience, provide a way to disable the plugin without uninstalling it. This is especially important if your plugin adds additional webpack aliases, this will allow you to still let the webpack run to prevent errors.
|
|
231
|
+
* **Include tests in your GitHub CI workflow**: If you’ve configured tests for your package, integrate them into your workflow to run the tests each time you commit to the plugin repository. Learn more about [how to configure tests into your GitHub CI workflow.](https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs)
|
|
232
|
+
* **Publish your finished plugin to NPM**: The best way to share and allow others to use your plugin once it is complete is to publish an NPM package. This process is straightforward and well documented, find out more [creating and publishing a NPM package here.](https://docs.npmjs.com/creating-and-publishing-scoped-public-packages/).
|
|
233
|
+
* **Add payload-plugin topic tag**: Apply the tag **payload-plugin **to your GitHub repository. This will boost the visibility of your plugin and ensure it gets listed with [existing payload plugins](https://github.com/topics/payload-plugin).
|
|
234
|
+
* **Use [Semantic Versioning](https://semver.org/) (SemVar)** - With the SemVar system you release version numbers that reflect the nature of changes (major, minor, patch). Ensure all major versions reference their Payload compatibility.
|
|
235
|
+
|
|
236
|
+
# Questions
|
|
237
|
+
Please contact [Payload](mailto:dev@payloadcms.com) with any questions about using this plugin template.
|
package/dev/.env.example
ADDED
package/dev/Dockerfile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
FROM node:18.8-alpine as base
|
|
2
|
+
|
|
3
|
+
FROM base as builder
|
|
4
|
+
|
|
5
|
+
WORKDIR /home/node/app
|
|
6
|
+
COPY package*.json ./
|
|
7
|
+
|
|
8
|
+
COPY . .
|
|
9
|
+
RUN yarn install
|
|
10
|
+
RUN yarn build
|
|
11
|
+
|
|
12
|
+
FROM base as runtime
|
|
13
|
+
|
|
14
|
+
ENV NODE_ENV=production
|
|
15
|
+
ENV PAYLOAD_CONFIG_PATH=dist/payload.config.js
|
|
16
|
+
|
|
17
|
+
WORKDIR /home/node/app
|
|
18
|
+
COPY package*.json ./
|
|
19
|
+
COPY yarn.lock ./
|
|
20
|
+
|
|
21
|
+
RUN yarn install --production
|
|
22
|
+
COPY --from=builder /home/node/app/dist ./dist
|
|
23
|
+
COPY --from=builder /home/node/app/build ./build
|
|
24
|
+
|
|
25
|
+
EXPOSE 3000
|
|
26
|
+
|
|
27
|
+
CMD ["node", "dist/server.js"]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
version: '3'
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
payload:
|
|
5
|
+
image: node:18-alpine
|
|
6
|
+
ports:
|
|
7
|
+
- '3000:3000'
|
|
8
|
+
volumes:
|
|
9
|
+
- .:/home/node/app
|
|
10
|
+
- node_modules:/home/node/app/node_modules
|
|
11
|
+
working_dir: /home/node/app/
|
|
12
|
+
command: sh -c "yarn install && yarn dev"
|
|
13
|
+
depends_on:
|
|
14
|
+
- mongo
|
|
15
|
+
env_file:
|
|
16
|
+
- .env
|
|
17
|
+
|
|
18
|
+
mongo:
|
|
19
|
+
image: mongo:latest
|
|
20
|
+
ports:
|
|
21
|
+
- '27017:27017'
|
|
22
|
+
command:
|
|
23
|
+
- --storageEngine=wiredTiger
|
|
24
|
+
volumes:
|
|
25
|
+
- data:/data/db
|
|
26
|
+
logging:
|
|
27
|
+
driver: none
|
|
28
|
+
|
|
29
|
+
volumes:
|
|
30
|
+
data:
|
|
31
|
+
node_modules:
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
verbose: true,
|
|
3
|
+
testEnvironment: 'node',
|
|
4
|
+
transform: {
|
|
5
|
+
'^.+\\.(t|j)sx?$': '<rootDir>/node_modules/@swc/jest',
|
|
6
|
+
},
|
|
7
|
+
moduleNameMapper: {
|
|
8
|
+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
|
|
9
|
+
'<rootDir>/src/mocks/fileStub.js',
|
|
10
|
+
'\\.(css|scss)$': '<rootDir>/src/mocks/fileStub.js',
|
|
11
|
+
},
|
|
12
|
+
}
|
package/dev/nodemon.json
ADDED
package/dev/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Payload2Blank",
|
|
3
|
+
"description": "A blank template to get started with Payload",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"main": "dist/server.js",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts nodemon",
|
|
9
|
+
"build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
|
|
10
|
+
"build:server": "tsc",
|
|
11
|
+
"build": "yarn copyfiles && yarn build:payload && yarn build:server",
|
|
12
|
+
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
|
|
13
|
+
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
|
|
14
|
+
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
|
|
15
|
+
"generate:graphQLSchema": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema",
|
|
16
|
+
"payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@payloadcms/bundler-webpack": "^1.0.0",
|
|
20
|
+
"@payloadcms/db-mongodb": "^1.0.0",
|
|
21
|
+
"@payloadcms/plugin-cloud": "^2.0.0",
|
|
22
|
+
"@payloadcms/richtext-slate": "^1.0.0",
|
|
23
|
+
"cross-env": "^7.0.3",
|
|
24
|
+
"dotenv": "^8.2.0",
|
|
25
|
+
"express": "^4.17.1",
|
|
26
|
+
"payload": "^2.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/express": "^4.17.9",
|
|
30
|
+
"copyfiles": "^2.4.1",
|
|
31
|
+
"nodemon": "^2.0.6",
|
|
32
|
+
"ts-node": "^9.1.1",
|
|
33
|
+
"typescript": "^4.8.4"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Server } from 'http'
|
|
2
|
+
import mongoose from 'mongoose'
|
|
3
|
+
import payload from 'payload'
|
|
4
|
+
import { start } from './src/server'
|
|
5
|
+
|
|
6
|
+
describe('Plugin tests', () => {
|
|
7
|
+
let server: Server
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
await start({ local: true })
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
afterAll(async () => {
|
|
14
|
+
await mongoose.connection.dropDatabase()
|
|
15
|
+
await mongoose.connection.close()
|
|
16
|
+
server.close()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// Add tests to ensure that the plugin works as expected
|
|
20
|
+
|
|
21
|
+
// Example test to check for seeded data
|
|
22
|
+
it('seeds data accordingly', async () => {
|
|
23
|
+
const newCollectionQuery = await payload.find({
|
|
24
|
+
collection: 'new-collection',
|
|
25
|
+
sort: 'createdAt',
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
expect(newCollectionQuery.totalDocs).toEqual(1)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CollectionConfig } from 'payload/types'
|
|
2
|
+
|
|
3
|
+
// Example Collection - For reference only, this must be added to payload.config.ts to be used.
|
|
4
|
+
const Examples: CollectionConfig = {
|
|
5
|
+
slug: 'examples',
|
|
6
|
+
admin: {
|
|
7
|
+
useAsTitle: 'someField',
|
|
8
|
+
},
|
|
9
|
+
fields: [
|
|
10
|
+
{
|
|
11
|
+
name: 'richText',
|
|
12
|
+
type: 'text',
|
|
13
|
+
localized: true,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default Examples
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CollectionConfig } from 'payload/types';
|
|
2
|
+
|
|
3
|
+
const Users: CollectionConfig = {
|
|
4
|
+
slug: 'users',
|
|
5
|
+
auth: true,
|
|
6
|
+
admin: {
|
|
7
|
+
useAsTitle: 'email',
|
|
8
|
+
},
|
|
9
|
+
fields: [
|
|
10
|
+
// Email added by default
|
|
11
|
+
// Add more fields as needed
|
|
12
|
+
],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default Users;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default 'file-stub'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { buildConfig } from 'payload/config'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import Users from './collections/Users'
|
|
4
|
+
import Examples from './collections/Examples'
|
|
5
|
+
import { mongooseAdapter } from '@payloadcms/db-mongodb'
|
|
6
|
+
import { webpackBundler } from '@payloadcms/bundler-webpack'
|
|
7
|
+
import { slateEditor } from '@payloadcms/richtext-slate'
|
|
8
|
+
import { aiTranslatorPlugin } from '../../src/index'
|
|
9
|
+
|
|
10
|
+
export default buildConfig({
|
|
11
|
+
admin: {
|
|
12
|
+
user: Users.slug,
|
|
13
|
+
bundler: webpackBundler(),
|
|
14
|
+
webpack: config => {
|
|
15
|
+
const newConfig = {
|
|
16
|
+
...config,
|
|
17
|
+
resolve: {
|
|
18
|
+
...config.resolve,
|
|
19
|
+
alias: {
|
|
20
|
+
...(config?.resolve?.alias || {}),
|
|
21
|
+
react: path.join(__dirname, '../node_modules/react'),
|
|
22
|
+
'react-dom': path.join(__dirname, '../node_modules/react-dom'),
|
|
23
|
+
payload: path.join(__dirname, '../node_modules/payload'),
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
return newConfig
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
editor: slateEditor({}),
|
|
31
|
+
collections: [Examples, Users],
|
|
32
|
+
localization: {
|
|
33
|
+
locales: ['en', 'es', 'de'],
|
|
34
|
+
defaultLocale: 'en',
|
|
35
|
+
fallback: true,
|
|
36
|
+
},
|
|
37
|
+
typescript: {
|
|
38
|
+
outputFile: path.resolve(__dirname, 'payload-types.ts'),
|
|
39
|
+
},
|
|
40
|
+
graphQL: {
|
|
41
|
+
schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
|
|
42
|
+
},
|
|
43
|
+
plugins: [
|
|
44
|
+
aiTranslatorPlugin({
|
|
45
|
+
enabled: true,
|
|
46
|
+
collections: {
|
|
47
|
+
examples: {
|
|
48
|
+
fields: ['richText'],
|
|
49
|
+
// adapter: theAdapterToUse, // see docs for the adapter you want to use
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
54
|
+
db: mongooseAdapter({
|
|
55
|
+
url: process.env.DATABASE_URI,
|
|
56
|
+
}),
|
|
57
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import express from 'express'
|
|
2
|
+
import payload from 'payload'
|
|
3
|
+
import { InitOptions } from 'payload/config'
|
|
4
|
+
|
|
5
|
+
require('dotenv').config()
|
|
6
|
+
const app = express()
|
|
7
|
+
|
|
8
|
+
// Redirect root to Admin panel
|
|
9
|
+
app.get('/', (_, res) => {
|
|
10
|
+
res.redirect('/admin')
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export const start = async (args?: Partial<InitOptions>) => {
|
|
14
|
+
// Initialize Payload
|
|
15
|
+
await payload.init({
|
|
16
|
+
secret: process.env.PAYLOAD_SECRET,
|
|
17
|
+
express: app,
|
|
18
|
+
onInit: async () => {
|
|
19
|
+
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
|
|
20
|
+
},
|
|
21
|
+
...(args || {}),
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// Add your own express routes here
|
|
25
|
+
|
|
26
|
+
app.listen(3000)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
start()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"strict": false,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"outDir": "./dist",
|
|
14
|
+
"rootDir": "./src",
|
|
15
|
+
"jsx": "react",
|
|
16
|
+
"paths": {
|
|
17
|
+
"payload/generated-types": [
|
|
18
|
+
"./src/payload-types.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"include": [
|
|
23
|
+
"src"
|
|
24
|
+
],
|
|
25
|
+
"exclude": [
|
|
26
|
+
"node_modules",
|
|
27
|
+
"dist",
|
|
28
|
+
"build"
|
|
29
|
+
],
|
|
30
|
+
"ts-node": {
|
|
31
|
+
"transpileOnly": true,
|
|
32
|
+
"swc": true
|
|
33
|
+
}
|
|
34
|
+
}
|