2026-05-10 16:57:12 +08:00
|
|
|
import { Inject, Provide, Scope, ScopeEnum } from "@midwayjs/core";
|
2025-04-06 00:20:05 +08:00
|
|
|
import { logger } from "@certd/basic";
|
|
|
|
|
import { PluginService } from "../plugin/service/plugin-service.js";
|
2026-01-05 23:04:07 +08:00
|
|
|
import { registerPaymentProviders } from "../suite/payments/index.js";
|
2025-04-06 00:20:05 +08:00
|
|
|
|
2026-05-10 16:57:12 +08:00
|
|
|
@Provide()
|
2025-04-06 00:20:05 +08:00
|
|
|
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
2026-05-10 16:57:12 +08:00
|
|
|
export class AutoLoadPlugins {
|
2025-04-06 00:20:05 +08:00
|
|
|
@Inject()
|
|
|
|
|
pluginService: PluginService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async init() {
|
2025-12-31 17:01:37 +08:00
|
|
|
logger.info(`加载插件开始,加载模式:${process.env.certd_plugin_loadmode}`);
|
|
|
|
|
if (process.env.certd_plugin_loadmode === "metadata") {
|
|
|
|
|
await this.pluginService.registerFromLocal("./metadata")
|
|
|
|
|
}else{
|
2026-01-08 00:11:46 +08:00
|
|
|
// await import("../../plugins/index.js")
|
|
|
|
|
const fs = await import("fs");
|
2026-01-08 00:31:18 +08:00
|
|
|
const list = fs.readdirSync("./dist/plugins");
|
|
|
|
|
console.log("list", list);
|
2026-01-08 00:11:46 +08:00
|
|
|
for (const file of list) {
|
2026-01-08 00:31:18 +08:00
|
|
|
if (!file.includes(".")){
|
|
|
|
|
logger.info(`加载插件文件:${file}`);
|
|
|
|
|
await import(`../../plugins/${file}/index.js`);
|
2026-01-08 00:11:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-12-31 17:01:37 +08:00
|
|
|
}
|
2025-12-30 11:09:50 +08:00
|
|
|
// await import("../../plugins/index.js")
|
2025-04-06 00:20:05 +08:00
|
|
|
await this.pluginService.registerFromDb()
|
2026-01-05 23:04:07 +08:00
|
|
|
|
|
|
|
|
await registerPaymentProviders();
|
2025-12-31 17:01:37 +08:00
|
|
|
logger.info(`加载插件完成,加载模式:${process.env.certd_plugin_loadmode}`);
|
2025-04-06 00:20:05 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|