Update your-fisrt-plugin.md

This commit is contained in:
Zhou 2022-11-06 08:34:06 +08:00 committed by GitHub
parent db2c686ddf
commit 5e76ccb4de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,35 +1,35 @@
# 编写第一个插件 # Develop the first plugin
在此之前,需要先安装好 NocoBase Before start, you need to install NocoBase:.
- [create-nocobase-app 安装](/getting-started/installation/create-nocobase-app) - [create-nocobase-app installation](/welcome/getting-started/installation/create-nocobase-app)
- [Git 源码安装](/getting-started/installation/git-clone) - [Git source installation](/welcome/getting-started/installation/git-clone)
安装好 NocoBase 之后,我们就可以开始插件开发之旅了。 Once NocoBase is installed, we can start our plugin development journey.
## 创建插件 ## Create a plugin
首先,你可以通过 CLI 快速的创建一个空插件,命令如下: First, you can quickly create an empty plugin via the CLI with the following command.
```bash ```bash
yarn pm create hello yarn pm create hello
``` ```
插件所在目录 `packages/plugins/hello`,插件目录结构为: The directory where the plugin is located ``packages/plugins/hello`` and the plugin directory structure is
```bash ```bash
|- /hello |- /hello
|- /src |- /src
|- /client # 插件客户端代码 |- /client # plugin client code
|- /server # 插件服务端代码 |- /server # plugin server code
|- client.d.ts |- client.d.ts
|- client.js |- client.js
|- package.json # 插件包信息 |- package.json # plugin package information
|- server.d.ts |- server.d.ts
|- server.js |- server.js
``` package.json
package.json 信息 package.json information
```json ```json
{ {
@ -43,13 +43,13 @@ package.json 信息
} }
``` ```
NocoBase 插件也是 NPM 包,插件名和 NPM 包名的对应规则为 `${PLUGIN_PACKAGE_PREFIX}-${pluginName}` A NocoBase plugin is also an NPM package, the correspondence rule between plugin name and NPM package name is `${PLUGIN_PACKAGE_PREFIX}-${pluginName}`.
`PLUGIN_PACKAGE_PREFIX` 为插件包前缀,可以在 .env 里自定义,[点此查看 PLUGIN_PACKAGE_PREFIX 说明](/api/env#plugin_package_prefix)。 `PLUGIN_PACKAGE_PREFIX` is the plugin package prefix, which can be customized in .env, [click here for PLUGIN_PACKAGE_PREFIX description](/api/env#plugin_package_prefix).
## 编写插件 ## Code the plugin
查看 `packages/plugins/hello/src/server/plugin.ts` 文件,并修改为: Look at the `packages/plugins/hello/src/server/plugin.ts` file and modify it to
```ts ```ts
import { InstallOptions, Plugin } from '@nocobase/server'; import { InstallOptions, Plugin } from '@nocobase/server';
@ -81,21 +81,21 @@ export class HelloPlugin extends Plugin {
export default HelloPlugin; export default HelloPlugin;
``` ```
## 注册插件 ## Register the plugin
```bash ```bash
yarn pm add hello yarn pm add hello
``` ```
## 激活插件 ## Activate the plugin
插件激活时,会自动创建刚才编辑插件配置的 hello 表。 When the plugin is activated, the hello table that you just configured is automatically created.
```bash ```bash
yarn pm enable hello yarn pm enable hello
``` ```
## 启动应用 ## Start the application
```bash ```bash
# for development # for development
@ -106,9 +106,9 @@ yarn build
yarn start yarn start
``` ```
## 体验插件功能 ## Experience the plugin
向插件的 hello 表里插入数据 Insert data into the hello table of the plugin
```bash ```bash
curl --location --request POST 'http://localhost:13000/api/hello:create' \ curl --location --request POST 'http://localhost:13000/api/hello:create' \
@ -118,7 +118,7 @@ curl --location --request POST 'http://localhost:13000/api/hello:create' \
}' }'
``` ```
查看 hello 表数据 View the data
```bash ```bash
curl --location --request GET 'http://localhost:13000/api/hello:list' curl --location --request GET 'http://localhost:13000/api/hello:list'