Skip to content

Commit 5fa778c

Browse files
authored
docs: update plugin development tutorial to include CLI setup instruc… (#146)
* docs: update plugin development tutorial to include CLI setup instructions and remove outdated boilerplate code * docs: update upload plugin tutorial to enhance preview image size configuration with detailed settings
1 parent f5c5566 commit 5fa778c

File tree

2 files changed

+30
-137
lines changed

2 files changed

+30
-137
lines changed

adminforth/documentation/docs/tutorial/05-Plugins/05-upload.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
# Upload
42

53
This plugin allows you to upload files to Amazon S3 bucket.
@@ -305,7 +303,7 @@ new UploadPlugin({
305303
});
306304
```
307305
308-
### Max-width for preview image
306+
### Preview Image Size Configuration
309307
310308
You can set the maximum width for the preview image in the `./resources/apartments.ts` file by adding the `maxWidth` property to the `preview` configuration:
311309
@@ -322,8 +320,18 @@ You can set the maximum width for the preview image in the `./resources/apartmen
322320
s3Path: ({originalFilename, originalExtension, contentType}) =>
323321
`aparts/${new Date().getFullYear()}/${uuid()}-${originalFilename}.${originalExtension}`,
324322
preview: {
325-
//diff-add
326-
maxWidth: '200px', // Set the maximum width for the preview image
323+
// Global width settings (applies to all views if specific view settings not provided)
324+
maxWidth: '200px', // Maximum width for preview images
325+
minWidth: '200px', // Minimum width for preview images
326+
327+
// List view specific settings
328+
maxListWidth: '300px', // Maximum width in list view
329+
minListWidth: '100px', // Minimum width in list view
330+
331+
// Show/detail view specific settings
332+
maxShowWidth: '200px', // Maximum width in show view
333+
minShowWidth: '200px', // Minimum width in show view
334+
327335
...
328336
}
329337

adminforth/documentation/docs/tutorial/06-Advanced/01-plugin-development.md

Lines changed: 17 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -21,112 +21,28 @@ Let's create plugin which auto-completes text in strings
2121
```bash
2222
mkdir -p af-plugin-chatgpt
2323
cd af-plugin-chatgpt
24-
npm init -y
25-
touch index.ts
26-
npm i typescript @types/node -D
27-
```
28-
29-
Edit `package.json`:
30-
31-
```json title='./af-plugin-chatgpt/package.json'
32-
{
33-
...
34-
//diff-remove
35-
"main": "index.js",
36-
//diff-add
37-
"main": "dist/index.js",
38-
//diff-add
39-
"types": "dist/index.d.ts",
40-
//diff-add
41-
"type": "module",
42-
"scripts": {
43-
//diff-remove
44-
"test": "echo \"Error: no test specified\" && exit 1",
45-
//diff-add
46-
"build": "tsc && rsync -av --exclude 'node_modules' custom dist/ && npm version patch"
47-
},
48-
}
49-
```
50-
51-
52-
Install AdminForth for types and classes imports:
53-
54-
```bash
55-
npm i adminforth --save
56-
```
57-
58-
Now create plugin boilerplate in `index.ts`:
59-
60-
```ts title='./af-plugin-chatgpt/index.ts'
61-
62-
import { AdminForthPlugin } from "adminforth";
63-
import type { IAdminForth, IHttpServer, AdminForthResourcePages, AdminForthResourceColumn, AdminForthDataTypes, AdminForthResource } from "adminforth";
64-
import type { PluginOptions } from './types.js';
65-
66-
67-
export default class ChatGptPlugin extends AdminForthPlugin {
68-
options: PluginOptions;
69-
70-
constructor(options: PluginOptions) {
71-
super(options, import.meta.url);
72-
this.options = options;
73-
}
74-
75-
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
76-
super.modifyResourceConfig(adminforth, resourceConfig);
77-
78-
// simply modify resourceConfig or adminforth.config. You can get access to plugin options via this.options;
79-
}
80-
81-
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
82-
// optional method where you can safely check field types after database discovery was performed
83-
}
84-
85-
instanceUniqueRepresentation(pluginOptions: any) : string {
86-
// optional method to return unique string representation of plugin instance.
87-
// Needed if plugin can have multiple instances on one resource
88-
return `single`;
89-
}
90-
91-
setupEndpoints(server: IHttpServer) {
92-
server.endpoint({
93-
method: 'POST',
94-
path: `/plugin/${this.pluginInstanceId}/example`,
95-
handler: async ({ body }) => {
96-
const { name } = body;
97-
return { hey: `Hello ${name}` };
98-
}
99-
});
100-
}
101-
102-
}
24+
npx adminforth create-plugin
10325
```
10426

105-
Create `types.ts` file:
27+
CLI options:
10628

107-
```ts title='./af-plugin-chatgpt/types.ts'
108-
109-
export interface PluginOptions {
110-
111-
}
112-
```
29+
* **`--plugin-name`** - name for your plugin.
11330

31+
This command will:
32+
1. Set up the TypeScript configuration
33+
2. Create initial plugin files
34+
3. Install required dependencies
11435

115-
Create `./af-plugin-chatgpt/tsconfig.json` file:
36+
The CLI will create the following files and directories:
11637

117-
```json title='./af-plugin-chatgpt/tsconfig.json'
118-
{
119-
"compilerOptions": {
120-
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include*/
121-
"module": "node16", /* Specify what module code is generated. */
122-
"outDir": "./dist", /* Specify an output folder for all emitted files. */
123-
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. */
124-
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
125-
"strict": false, /* Enable all strict type-checking options. */
126-
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
127-
},
128-
"exclude": ["node_modules", "dist", "custom"], /* Exclude files from compilation. */
129-
}
38+
```text
39+
af-plugin-chatgpt/
40+
├── custom
41+
│ └── tsconfig.json # TypeScript configuration for custom components
42+
├── index.ts # Main plugin file with boilerplate code
43+
├── package.json # Plugin package configuration
44+
├── tsconfig.json # TypeScript configuration
45+
└── types.ts # TypeScript types for your plugin
13046
13147
```
13248

@@ -204,37 +120,6 @@ export interface PluginOptions {
204120
}
205121
```
206122

207-
Now we have to create custom Vue component which will be used in plugin. To do it create custom folder:
208-
209-
```bash
210-
mkdir -p af-plugin-chatgpt/custom
211-
```
212-
213-
Also create `tsconfig.ts` file so your IDE will be able to resolve adminforth spa imports:
214-
215-
```json title='./af-plugin-chatgpt/custom/tsconfig.json'
216-
{
217-
"compilerOptions": {
218-
"baseUrl": ".", // This should point to your project root
219-
"paths": {
220-
"@/*": [
221-
// "node_modules/adminforth/dist/spa/src/*"
222-
"../../../spa/src/*"
223-
],
224-
"*": [
225-
// "node_modules/adminforth/dist/spa/node_modules/*"
226-
"../../../spa/node_modules/*"
227-
],
228-
"@@/*": [
229-
// "node_modules/adminforth/dist/spa/src/*"
230-
"."
231-
]
232-
}
233-
}
234-
}
235-
```
236-
237-
238123
We will use `vue-suggestion-input` package in our frontend component.
239124
To install package into frontend component, first of all we have to initialize npm package in custom folder:
240125

@@ -535,7 +420,7 @@ Finally, since we want to support multiple installations on one resource (e.g. o
535420
```
536421
537422
538-
Ro compile plugin run:
423+
To compile plugin run:
539424
540425
```bash
541426
npm run build

0 commit comments

Comments
 (0)