Update your-fisrt-plugin.md
This commit is contained in:
		
							parent
							
								
									db2c686ddf
								
							
						
					
					
						commit
						5e76ccb4de
					
				@ -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)
 | 
			
		||||
- [Git 源码安装](/getting-started/installation/git-clone)
 | 
			
		||||
- [create-nocobase-app installation](/welcome/getting-started/installation/create-nocobase-app)
 | 
			
		||||
- [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
 | 
			
		||||
yarn pm create hello
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
插件所在目录 `packages/plugins/hello`,插件目录结构为:
 | 
			
		||||
The directory where the plugin is located ``packages/plugins/hello`` and the plugin directory structure is
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
|- /hello
 | 
			
		||||
  |- /src
 | 
			
		||||
    |- /client      # 插件客户端代码
 | 
			
		||||
    |- /server      # 插件服务端代码
 | 
			
		||||
    |- /client # plugin client code
 | 
			
		||||
    |- /server # plugin server code
 | 
			
		||||
  |- client.d.ts
 | 
			
		||||
  |- client.js
 | 
			
		||||
  |- package.json   # 插件包信息
 | 
			
		||||
  |- package.json # plugin package information
 | 
			
		||||
  |- server.d.ts
 | 
			
		||||
  |- server.js
 | 
			
		||||
```
 | 
			
		||||
package.json
 | 
			
		||||
 | 
			
		||||
package.json 信息
 | 
			
		||||
package.json information
 | 
			
		||||
 | 
			
		||||
```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
 | 
			
		||||
import { InstallOptions, Plugin } from '@nocobase/server';
 | 
			
		||||
@ -81,21 +81,21 @@ export class HelloPlugin extends Plugin {
 | 
			
		||||
export default HelloPlugin;
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## 注册插件
 | 
			
		||||
## Register the plugin
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
yarn pm add hello
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## 激活插件
 | 
			
		||||
## Activate the plugin
 | 
			
		||||
 | 
			
		||||
插件激活时,会自动创建刚才编辑插件配置的 hello 表。
 | 
			
		||||
When the plugin is activated, the hello table that you just configured is automatically created.
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
yarn pm enable hello
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## 启动应用
 | 
			
		||||
## Start the application
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
# for development
 | 
			
		||||
@ -106,9 +106,9 @@ yarn build
 | 
			
		||||
yarn start
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## 体验插件功能
 | 
			
		||||
## Experience the plugin
 | 
			
		||||
 | 
			
		||||
向插件的 hello 表里插入数据
 | 
			
		||||
Insert data into the hello table of the plugin
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
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
 | 
			
		||||
curl --location --request GET 'http://localhost:13000/api/hello:list'
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user