Files
certd/packages/ui/certd-server/src/modules/auto/auto-load-plugins.ts
T

35 lines
1.2 KiB
TypeScript
Raw Normal View History

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
@Provide()
2025-04-06 00:20:05 +08:00
@Scope(ScopeEnum.Request, { allowDowngrade: true })
export class AutoLoadPlugins {
2025-04-06 00:20:05 +08:00
@Inject()
pluginService: PluginService;
async init() {
logger.info(`加载插件开始,加载模式:${process.env.certd_plugin_loadmode}`);
if (process.env.certd_plugin_loadmode === "metadata") {
2026-05-31 01:41:33 +08:00
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-05-31 01:41:33 +08:00
if (!file.includes(".")) {
2026-01-08 00:31:18 +08:00
logger.info(`加载插件文件:${file}`);
await import(`../../plugins/${file}/index.js`);
2026-01-08 00:11:46 +08:00
}
}
}
2025-12-30 11:09:50 +08:00
// await import("../../plugins/index.js")
2026-05-31 01:41:33 +08:00
await this.pluginService.registerFromDb();
2026-01-05 23:04:07 +08:00
await registerPaymentProviders();
logger.info(`加载插件完成,加载模式:${process.env.certd_plugin_loadmode}`);
2025-04-06 00:20:05 +08:00
}
}