-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathplugin.module.ts.template
More file actions
45 lines (43 loc) · 1.29 KB
/
plugin.module.ts.template
File metadata and controls
45 lines (43 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Module } from "@nestjs/common";
import { PluginService } from "../common/plugins/plugin.service";
import * as fs from 'fs';
import * as path from 'path';
// Load compiled plugins
const compiledPluginsPath = path.join(__dirname, 'compiled');
const loadCompiledPlugins = () => {
const plugins = [];
if (fs.existsSync(compiledPluginsPath)) {
const entries = fs.readdirSync(compiledPluginsPath);
for (const entry of entries) {
const pluginPath = path.join(compiledPluginsPath, entry);
if (fs.statSync(pluginPath).isDirectory()) {
const distPath = path.join(pluginPath, 'dist', 'index.js');
if (fs.existsSync(distPath)) {
try {
const plugin = require(distPath);
plugins.push(plugin);
} catch (err) {
console.error(`Failed to load compiled plugin ${entry}:`, err);
}
}
}
}
}
return plugins;
};
@Module({
providers: [
{
provide: PluginService,
useFactory: () => {
const service = new PluginService();
// Load and register compiled plugins
const compiledPlugins = loadCompiledPlugins();
service.registerPlugins(compiledPlugins);
return service;
},
},
],
exports: [PluginService],
})
export class PluginModule { }