You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -13,6 +13,12 @@ Viewing the [**official plugin code**](https://github.com/apache/answer-plugins)
13
13
14
14
:::
15
15
16
+
:::info
17
+
18
+
**Recommended**: Use the official scaffolding tool [`create-answer-plugin`](https://www.npmjs.com/package/create-answer-plugin) to create and manage plugins. It automates most of the setup process, including file generation, Go module configuration, and plugin installation.
19
+
20
+
:::
21
+
16
22
## Introduction
17
23
18
24
### Plugin template types
@@ -52,66 +58,252 @@ The **name** field in package.json is the name of the package we add dependencie
52
58
53
59
:::
54
60
55
-
1. Go to the `ui > src > plugin` directory of the project.
61
+
### Using the Scaffolding Tool (Recommended)
62
+
63
+
The easiest way to create a plugin is using the official scaffolding tool:
64
+
65
+
```shell
66
+
# Install the tool globally (optional)
67
+
npm install -g create-answer-plugin
68
+
# or
69
+
pnpm add -g create-answer-plugin
70
+
71
+
# Or use npx directly (recommended)
72
+
npx create-answer-plugin create <pluginName>
73
+
# or use the alias
74
+
npx answer-plugin create <pluginName>
75
+
# or use the simplified form
76
+
npx answer-plugin <pluginName>
77
+
```
78
+
79
+
**Note**: The package name is `create-answer-plugin`, but you can use either `create-answer-plugin` or `answer-plugin` as the command (both work!).
80
+
81
+
The tool will:
82
+
1. Guide you through an interactive wizard to select the plugin type
83
+
2. Generate all required files with the correct structure
84
+
3. Create the Go wrapper file (required for Backend plugins)
85
+
4. Set up proper `go.mod` with all dependencies
86
+
5. Generate i18n files with the correct structure
56
87
57
-
2. Execute the following commands in that directory:
88
+
**Options:**
89
+
-`pluginName` (optional): Pre-fill the plugin name
90
+
-`--path, -p`: Path to Answer project (root directory). If not specified, defaults to current directory.
3. Use `go mod edit` to add the plugin to the `go.mod` file:
237
+
```shell
238
+
go mod edit -replace=github.com/apache/answer/ui/src/plugins/my-plugin=./ui/src/plugins/my-plugin
239
+
```
240
+
241
+
4. Update the dependencies:
242
+
```shell
243
+
go mod tidy
244
+
```
245
+
246
+
5. Merge i18n resources:
247
+
```shell
248
+
go run ./cmd/answer/main.go i18n
249
+
```
250
+
251
+
6. Start the project:
252
+
```shell
253
+
go run cmd/answer/main.go run -C ./answer-data
254
+
```
98
255
99
256
### Run the Standard UI Plugin
100
257
101
-
1. Go to the `ui` directory.
102
-
2. Install the dependencies.
258
+
#### Using the Scaffolding Tool (Recommended)
103
259
104
-
```shell
105
-
pnpm pre-install
106
-
```
260
+
1. Install the plugin using the scaffolding tool:
261
+
```shell
262
+
cd /path/to/answer
263
+
npx create-answer-plugin install my-plugin
264
+
```
107
265
108
-
3. Start the project.
266
+
2. Go to the `ui` directory and install dependencies:
267
+
```shell
268
+
cd ui
269
+
pnpm pre-install
270
+
```
109
271
110
-
```shell
111
-
pnpm start
112
-
```
272
+
3. Build the frontend:
273
+
```shell
274
+
pnpm build
275
+
```
113
276
114
-
4. Refer to the [Run the BackendPlugin](/docs/development/plugins#debugging-plugins) and add the plugin to the project.
277
+
4. For development, start the dev server:
278
+
```shell
279
+
pnpm start
280
+
```
281
+
282
+
5. Merge i18n resources (if not done automatically):
283
+
```shell
284
+
cd ..
285
+
go run ./cmd/answer/main.go i18n
286
+
```
287
+
288
+
#### Manual Installation
289
+
290
+
1. Go to the `ui` directory.
291
+
2. Install the dependencies:
292
+
```shell
293
+
pnpm pre-install
294
+
```
295
+
296
+
3. Build the frontend:
297
+
```shell
298
+
pnpm build
299
+
```
300
+
301
+
4. For development, start the dev server:
302
+
```shell
303
+
pnpm start
304
+
```
305
+
306
+
5. Refer to the [Run the Backend Plugin](/docs/development/plugins#run-the-backend-plugin) section and manually add the plugin to the project (import in `main.go`, add `replace` directive, etc.).
0 commit comments