@thinkbun/plugin 1.0.6 → 1.0.7

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.
Files changed (2) hide show
  1. package/README.md +126 -126
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,240 +1,240 @@
1
1
  # ThinkBun Plugin
2
2
 
3
- ThinkBun 框架的官方插件集合,提供常用的功能扩展,包括日志增强和服务器集群支持。
3
+ The official plugin collection for ThinkBun framework, providing common functional extensions including enhanced logging and server cluster support.
4
4
 
5
- ## 子项目概述
5
+ ## Subproject Overview
6
6
 
7
- Plugin 包提供了 ThinkBun 框架的官方插件实现,这些插件可以直接集成到 ThinkBun 应用程序中,为应用提供额外的功能。当前版本包含日志插件和服务器插件,后续将添加更多官方插件。
7
+ The Plugin package provides official plugin implementations for the ThinkBun framework. These plugins can be directly integrated into ThinkBun applications, providing additional functionality. The current version includes a logger plugin and a server plugin, with more official plugins to be added in the future.
8
8
 
9
- ## 与主项目的关系
9
+ ## Relationship with Main Project
10
10
 
11
- Plugin 包依赖于 ThinkBun Core 包,为其提供扩展功能。这些插件遵循 Core 包定义的插件接口和生命周期,与框架无缝集成。
11
+ The Plugin package depends on the ThinkBun Core package, providing extension functionality for it. These plugins follow the plugin interface and lifecycle defined by the Core package, seamlessly integrating with the framework.
12
12
 
13
- ## 核心插件
13
+ ## Core Plugins
14
14
 
15
15
  ### LoggerPlugin
16
16
 
17
- 增强应用程序的日志功能,支持彩色输出、作用域标识和不同日志级别。
17
+ Enhances application logging functionality with support for colored output, scope identifiers, and different log levels.
18
18
 
19
- #### 功能特性
19
+ #### Features
20
20
 
21
- - 彩色日志输出,提高可读性
22
- - 支持日志作用域标识
23
- - 自定义日志级别
24
- - 与框架日志系统无缝集成
21
+ - Colored log output for improved readability
22
+ - Support for log scope identifiers
23
+ - Custom log levels
24
+ - Seamless integration with framework logging system
25
25
 
26
- #### 安装
26
+ #### Installation
27
27
 
28
28
  ```bash
29
- # 使用 Bun
29
+ # Using Bun
30
30
  bun add @thinkbun/plugin
31
31
 
32
- # 使用 npm
32
+ # Using npm
33
33
  npm install @thinkbun/plugin
34
34
 
35
- # 使用 yarn
35
+ # Using yarn
36
36
  yarn add @thinkbun/plugin
37
37
  ```
38
38
 
39
- #### 使用方法
39
+ #### Usage
40
40
 
41
41
  ```typescript
42
42
  import { createApplication } from '@thinkbun/core';
43
43
  import { LoggerPlugin } from '@thinkbun/plugin';
44
44
 
45
- // 创建应用实例
45
+ // Create application instance
46
46
  const app = await createApplication({
47
47
  APP_PATH: './src',
48
48
  ROOT_PATH: __dirname,
49
49
  });
50
50
 
51
- // 注册 LoggerPlugin
51
+ // Register LoggerPlugin
52
52
  app.loader.plugins.push(LoggerPlugin);
53
53
 
54
- // 设置应用
54
+ // Setup application
55
55
  await app.setup();
56
56
 
57
- // 使用增强的日志功能
58
- app.logger.info('应用程序已启动');
59
- app.logger.error('发生错误', 'ErrorScope');
60
- app.logger.debug('调试信息', ['Debug', 'Detail']);
61
- app.logger.warn('警告信息');
57
+ // Use enhanced logging
58
+ app.logger.info('Application started');
59
+ app.logger.error('An error occurred', 'ErrorScope');
60
+ app.logger.debug('Debug information', ['Debug', 'Detail']);
61
+ app.logger.warn('Warning message');
62
62
  ```
63
63
 
64
- #### 日志方法
64
+ #### Log Methods
65
65
 
66
- - `app.logger.info(message, scope)`: 输出信息级别的日志
67
- - `app.logger.error(message, scope)`: 输出错误级别的日志
68
- - `app.logger.debug(message, scope)`: 输出调试级别的日志
69
- - `app.logger.warn(message, scope)`: 输出警告级别的日志
66
+ - `app.logger.info(message, scope)`: Output information-level log
67
+ - `app.logger.error(message, scope)`: Output error-level log
68
+ - `app.logger.debug(message, scope)`: Output debug-level log
69
+ - `app.logger.warn(message, scope)`: Output warning-level log
70
70
 
71
- **参数**:
71
+ **Parameters**:
72
72
 
73
- - `message`: 日志消息内容
74
- - `scope`: 可选,日志作用域,可以是字符串或字符串数组
73
+ - `message`: Log message content
74
+ - `scope`: Optional, log scope, can be a string or string array
75
75
 
76
76
  ### ServerPlugin
77
77
 
78
- 提供服务器启动和集群支持功能,优化应用程序的性能和可靠性。
78
+ Provides server startup and cluster support functionality, optimizing application performance and reliability.
79
79
 
80
- #### 功能特性
80
+ #### Features
81
81
 
82
- - 基于 Bun.serve 的高性能服务器
83
- - 自动集群管理,充分利用多核 CPU
84
- - 工作进程自动重启
85
- - 优雅的关闭流程
86
- - 配置化的服务器参数
82
+ - High-performance server based on Bun.serve
83
+ - Automatic cluster management, fully utilizing multi-core CPUs
84
+ - Automatic worker process restart
85
+ - Graceful shutdown process
86
+ - Configurable server parameters
87
87
 
88
- #### 安装
88
+ #### Installation
89
89
 
90
90
  ```bash
91
- # 使用 Bun
91
+ # Using Bun
92
92
  bun add @thinkbun/plugin
93
93
 
94
- # 使用 npm
94
+ # Using npm
95
95
  npm install @thinkbun/plugin
96
96
 
97
- # 使用 yarn
97
+ # Using yarn
98
98
  yarn add @thinkbun/plugin
99
99
  ```
100
100
 
101
- #### 使用方法
101
+ #### Usage
102
102
 
103
103
  ```typescript
104
104
  import { createApplication } from '@thinkbun/core';
105
105
  import { ServerPlugin } from '@thinkbun/plugin';
106
106
 
107
- // 创建应用实例
107
+ // Create application instance
108
108
  const app = await createApplication({
109
109
  APP_PATH: './src',
110
110
  ROOT_PATH: __dirname,
111
111
  });
112
112
 
113
- // 注册 ServerPlugin
113
+ // Register ServerPlugin
114
114
  app.loader.plugins.push(ServerPlugin);
115
115
 
116
- // 设置应用
116
+ // Setup application
117
117
  await app.setup();
118
118
 
119
- // 运行应用(ServerPlugin 会自动启动服务器)
119
+ // Run application (ServerPlugin will automatically start the server)
120
120
  await app.run();
121
121
  ```
122
122
 
123
- #### 配置选项
123
+ #### Configuration Options
124
124
 
125
- 在应用配置文件中配置服务器参数:
125
+ Configure server parameters in the application configuration file:
126
126
 
127
127
  ```typescript
128
128
  // src/config/index.ts
129
129
  export default {
130
- port: 3000, // 服务器端口
131
- host: '0.0.0.0', // 服务器主机
132
- workers: 4, // 工作进程数量,默认自动检测 CPU 核心数
133
- // 其他配置...
130
+ port: 3000, // Server port
131
+ host: '0.0.0.0', // Server host
132
+ workers: 4, // Number of worker processes, defaults to auto-detecting CPU cores
133
+ // Other configurations...
134
134
  };
135
135
  ```
136
136
 
137
- #### 集群模式
137
+ #### Cluster Mode
138
138
 
139
- ServerPlugin 自动支持集群模式:
139
+ ServerPlugin automatically supports cluster mode:
140
140
 
141
- - 主进程管理工作进程的创建和重启
142
- - 工作进程处理实际的 HTTP 请求
143
- - 当工作进程意外退出时,自动创建新的工作进程
144
- - 支持优雅关闭,确保请求处理完成后再退出
141
+ - Master process manages worker process creation and restarts
142
+ - Worker processes handle actual HTTP requests
143
+ - When a worker process exits unexpectedly, a new worker process is automatically created
144
+ - Supports graceful shutdown, ensuring requests are completed before exiting
145
145
 
146
- ## 插件生命周期
146
+ ## Plugin Lifecycle
147
147
 
148
- ### LoggerPlugin 生命周期
148
+ ### LoggerPlugin Lifecycle
149
149
 
150
- | 阶段 | 执行顺序 | 功能 |
151
- | ------- | -------- | ------------------------------ |
152
- | `setup` | `pre` | 初始化日志功能,替换默认日志器 |
153
- | `run` | - | |
154
- | `close` | - | |
150
+ | Phase | Execution Order | Functionality |
151
+ | ------ | --------------- | -------------------------------------- |
152
+ | `setup` | `pre` | Initialize logging, replace default logger |
153
+ | `run` | - | None |
154
+ | `close` | - | None |
155
155
 
156
- ### ServerPlugin 生命周期
156
+ ### ServerPlugin Lifecycle
157
157
 
158
- | 阶段 | 执行顺序 | 功能 |
159
- | ------- | -------- | -------------------------------- |
160
- | `setup` | - | |
161
- | `run` | `post` | 启动服务器,根据配置创建工作进程 |
162
- | `close` | - | 优雅关闭服务器和工作进程 |
158
+ | Phase | Execution Order | Functionality |
159
+ | ------ | --------------- | ---------------------------------------- |
160
+ | `setup` | - | None |
161
+ | `run` | `post` | Start server, create worker processes |
162
+ | `close` | - | Gracefully shutdown server and workers |
163
163
 
164
- ## 独立运行/测试
164
+ ## Standalone Running/Testing
165
165
 
166
- ### 运行示例
166
+ ### Running Examples
167
167
 
168
168
  ```bash
169
- # 安装依赖
169
+ # Install dependencies
170
170
  bun install
171
171
 
172
- # 运行测试
172
+ # Run tests
173
173
  bun test
174
174
  ```
175
175
 
176
- ### 测试
176
+ ### Testing
177
177
 
178
178
  ```bash
179
- # 运行单元测试
179
+ # Run unit tests
180
180
  bun test
181
181
 
182
- # 运行测试并生成覆盖率报告
182
+ # Run tests and generate coverage report
183
183
  bun test --coverage
184
184
  ```
185
185
 
186
- ## 自定义插件开发
186
+ ## Custom Plugin Development
187
187
 
188
- Plugin 包不仅提供官方插件,还展示了如何开发自定义插件。以下是开发自定义插件的示例:
188
+ The Plugin package not only provides official plugins but also demonstrates how to develop custom plugins. Here's an example of developing a custom plugin:
189
189
 
190
190
  ```typescript
191
191
  import { type Plugin } from '@thinkbun/core';
192
192
 
193
193
  export const CustomPlugin: Plugin = {
194
194
  name: 'CustomPlugin',
195
- enforce: 'pre', // 插件执行顺序,可以是 'pre''post' 或省略
195
+ enforce: 'pre', // Plugin execution order, can be 'pre', 'post', or omitted
196
196
  setup(app) {
197
- // 插件初始化逻辑
198
- console.log('CustomPlugin 初始化');
197
+ // Plugin initialization logic
198
+ console.log('CustomPlugin initialized');
199
199
  },
200
200
  run(app) {
201
- // 应用运行时逻辑
202
- console.log('CustomPlugin 运行中');
201
+ // Application runtime logic
202
+ console.log('CustomPlugin running');
203
203
  },
204
204
  close(app) {
205
- // 应用关闭时清理逻辑
206
- console.log('CustomPlugin 已关闭');
205
+ // Cleanup logic when application closes
206
+ console.log('CustomPlugin closed');
207
207
  },
208
208
  };
209
209
  ```
210
210
 
211
- ## 插件执行顺序
211
+ ## Plugin Execution Order
212
212
 
213
- 插件的执行顺序由 `enforce` 属性决定:
213
+ Plugin execution order is determined by the `enforce` property:
214
214
 
215
- - `pre`: 在核心功能之前执行
216
- - `post`: 在核心功能之后执行
217
- - 省略: 默认执行顺序
215
+ - `pre`: Execute before core functionality
216
+ - `post`: Execute after core functionality
217
+ - Omitted: Default execution order
218
218
 
219
- ## 最佳实践
219
+ ## Best Practices
220
220
 
221
- 1. **插件注册**:
222
- - 将插件注册放在 `plugins.ts` 文件中,集中管理
223
- - 按照依赖关系和执行顺序注册插件
221
+ 1. **Plugin Registration**:
222
+ - Place plugin registration in the `plugins.ts` file for centralized management
223
+ - Register plugins in dependency order and execution order
224
224
 
225
- 2. **插件配置**:
226
- - 将插件配置放在应用配置文件中
227
- - 支持环境特定的配置
225
+ 2. **Plugin Configuration**:
226
+ - Place plugin configuration in the application configuration file
227
+ - Support environment-specific configuration
228
228
 
229
- 3. **错误处理**:
230
- - 在插件中添加适当的错误处理
231
- - 提供清晰的错误信息
229
+ 3. **Error Handling**:
230
+ - Add appropriate error handling in plugins
231
+ - Provide clear error messages
232
232
 
233
- 4. **性能考虑**:
234
- - 避免在插件中执行耗时操作
235
- - 合理使用插件生命周期阶段
233
+ 4. **Performance Considerations**:
234
+ - Avoid executing time-consuming operations in plugins
235
+ - Use plugin lifecycle stages appropriately
236
236
 
237
- ## API 参考
237
+ ## API Reference
238
238
 
239
239
  ### LoggerPlugin
240
240
 
@@ -257,54 +257,54 @@ interface Plugin {
257
257
  }
258
258
  ```
259
259
 
260
- ## 常见问题
260
+ ## FAQ
261
261
 
262
- ### Q: 如何自定义日志颜色?
262
+ ### Q: How to customize log colors?
263
263
 
264
- A: 目前 LoggerPlugin 支持的颜色是预定义的,可以通过修改源代码来自定义:
264
+ A: Currently LoggerPlugin supports predefined colors. You can customize by modifying the source code:
265
265
 
266
266
  ```typescript
267
- // logger.ts 中修改 colorMap 对象
267
+ // Modify colorMap object in logger.ts
268
268
  const colorMap = {
269
269
  app: 'yellow',
270
270
  PluginManager: 'yellow',
271
- // 添加自定义颜色映射
271
+ // Add custom color mappings
272
272
  CustomScope: 'cyan',
273
273
  };
274
274
  ```
275
275
 
276
- ### Q: 如何配置服务器端口?
276
+ ### Q: How to configure server port?
277
277
 
278
- A: 在应用配置文件中设置 `port` 选项:
278
+ A: Set the `port` option in the application configuration file:
279
279
 
280
280
  ```typescript
281
281
  // src/config/index.ts
282
282
  export default {
283
- port: 8080, // 设置为不同的端口
283
+ port: 8080, // Set to a different port
284
284
  };
285
285
  ```
286
286
 
287
- ### Q: 如何禁用集群模式?
287
+ ### Q: How to disable cluster mode?
288
288
 
289
- A: 在应用配置文件中将 `workers` 设置为 1
289
+ A: Set `workers` to 1 in the application configuration file:
290
290
 
291
291
  ```typescript
292
292
  // src/config/index.ts
293
293
  export default {
294
- workers: 1, // 禁用集群模式,只使用一个进程
294
+ workers: 1, // Disable cluster mode, use only one process
295
295
  };
296
296
  ```
297
297
 
298
- ## 许可证
298
+ ## License
299
299
 
300
300
  [MIT License](LICENSE)
301
301
 
302
- ## 联系方式
302
+ ## Contact
303
303
 
304
- - 📧 邮箱:contact@thinkbun.dev
305
- - 📦 GitHub[https://github.com/thinkbun/thinkbun](https://github.com/thinkbun/thinkbun)
306
- - 💬 Discord[ThinkBun Community](https://discord.gg/thinkbun)
304
+ - 📧 Email: contact@thinkbun.dev
305
+ - 📦 GitHub: [https://github.com/thinkbun/thinkbun](https://github.com/thinkbun/thinkbun)
306
+ - 💬 Discord: [ThinkBun Community](https://discord.gg/thinkbun)
307
307
 
308
308
  ---
309
309
 
310
- **ThinkBun Plugin** - ThinkBun 框架提供强大的扩展功能 🧩
310
+ **ThinkBun Plugin** - Providing powerful extension functionality for ThinkBun framework 🧩
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkbun/plugin",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.mjs",