Skip to content

Commit

Permalink
feat(@142vip/egg-validate): 调整插件加载模式
Browse files Browse the repository at this point in the history
  • Loading branch information
mmdapl committed Jan 5, 2025
1 parent 6aaf579 commit ffc45f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
19 changes: 8 additions & 11 deletions packages/egg-validate/agent.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
const { RegisterEggPluginName, registerPlugin } = require('@142vip/egg')
const { RegisterEggPluginName, EggPluginBoot } = require('@142vip/egg')
const { createEggValidateInstance } = require('./core/validate')

class EggValidateAgentBoot {
constructor(agent) {
this.agent = agent
}

// 所有文件已加载,此时可以启动插件。
async didLoad() {
if (this.agent.config[RegisterEggPluginName.EGG_VALIDATE]) {
registerPlugin(RegisterEggPluginName.EGG_VALIDATE, this.agent, createEggValidateInstance)
}
class EggValidateAgentBoot extends EggPluginBoot {
constructor(app) {
super({
pluginName: RegisterEggPluginName.EGG_VALIDATE,
appOrAgent: app,
createEggPluginInstance: createEggValidateInstance,
})
}
}

Expand Down
17 changes: 7 additions & 10 deletions packages/egg-validate/app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
const { RegisterEggPluginName, registerPlugin } = require('@142vip/egg')
const { RegisterEggPluginName, EggPluginBoot } = require('@142vip/egg')
const { createEggValidateInstance } = require('./core/validate')

class EggValidateAppBoot {
class EggValidateAppBoot extends EggPluginBoot {
constructor(app) {
this.app = app
}

// 所有文件已加载,此时可以启动插件。
async didLoad() {
if (this.app.config[RegisterEggPluginName.EGG_VALIDATE]) {
registerPlugin(RegisterEggPluginName.EGG_VALIDATE, this.app, createEggValidateInstance)
}
super({
pluginName: RegisterEggPluginName.EGG_VALIDATE,
appOrAgent: app,
createEggPluginInstance: createEggValidateInstance,
})
}
}

Expand Down
8 changes: 5 additions & 3 deletions packages/egg-validate/core/validate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { VipEggPluginLogger } = require('@142vip/egg')
const Joi = require('joi')
const { name: pkgName } = require('../package.json')

function createEggValidateInstance(config, app) {
const pluginLogger = VipEggPluginLogger.getInstance(pkgName, app)
/**
* 参数校验
*/
function createEggValidateInstance(pluginConfig, app) {
const pluginLogger = VipEggPluginLogger.getInstance(pluginConfig, app)

const validateSchema = Joi.object({ })

Expand Down

0 comments on commit ffc45f1

Please sign in to comment.