@@ -5,50 +5,50 @@ import { logger } from "../utils/logger";
55import { pluginManager } from "./plugin-manager" ;
66
77export async function loadPlugins ( pluginDir : string ) {
8- const pluginPath = path . join ( process . cwd ( ) , pluginDir ) ;
9-
10- logger . debug ( `Loading plugins (${ pluginPath } )` ) ;
11-
12- if ( ! fs . existsSync ( pluginPath ) ) {
13- throw new Error ( "Failed to check plugin directory" ) ;
14- }
15- logger . debug ( "Plugin directory exists" ) ;
16-
17- let pluginCount = 0 ;
18- let files : string [ ] ;
19- try {
20- files = fs . readdirSync ( pluginPath ) ;
21- logger . debug ( `Found ${ files . length } files in plugin directory` ) ;
22- } catch ( error ) {
23- throw new Error ( `Failed to read plugin-directory: ${ error } ` ) ;
24- }
25-
26- if ( ! files ) {
27- logger . info ( `No plugins found in ${ pluginPath } ` ) ;
28- return ;
29- }
30-
31- for ( const file of files ) {
32- if ( ! file . endsWith ( ".plugin.ts" ) ) {
33- logger . debug ( `Skipping non-plugin file: ${ file } ` ) ;
34- continue ;
35- }
36-
37- const absolutePath = path . join ( pluginPath , file ) ;
38- logger . info ( `Loading plugin: ${ absolutePath } ` ) ;
39- try {
40- await checkFileForChangeMe ( absolutePath ) ;
41- const module = await import ( absolutePath ) ;
42- const plugin = module . default ;
43- pluginManager . register ( plugin ) ;
44- pluginCount ++ ;
45- } catch ( error ) {
46- pluginManager . fail ( { name : file } ) ;
47- logger . error (
48- `Error while registering plugin ${ absolutePath } : ${ error as string } `
49- ) ;
50- }
51- }
52-
53- logger . info ( `Registered ${ pluginCount } plugin(s)` ) ;
8+ const pluginPath = path . join ( process . cwd ( ) , pluginDir ) ;
9+
10+ logger . debug ( `Loading plugins (${ pluginPath } )` ) ;
11+
12+ if ( ! fs . existsSync ( pluginPath ) ) {
13+ throw new Error ( "Failed to check plugin directory" ) ;
14+ }
15+ logger . debug ( "Plugin directory exists" ) ;
16+
17+ let pluginCount = 0 ;
18+ let files : string [ ] ;
19+ try {
20+ files = fs . readdirSync ( pluginPath ) ;
21+ logger . debug ( `Found ${ files . length } files in plugin directory` ) ;
22+ } catch ( error ) {
23+ throw new Error ( `Failed to read plugin-directory: ${ error } ` ) ;
24+ }
25+
26+ if ( ! files ) {
27+ logger . info ( `No plugins found in ${ pluginPath } ` ) ;
28+ return ;
29+ }
30+
31+ for ( const file of files ) {
32+ if ( ! file . endsWith ( ".plugin.ts" ) ) {
33+ logger . debug ( `Skipping non-plugin file: ${ file } ` ) ;
34+ continue ;
35+ }
36+
37+ const absolutePath = path . join ( pluginPath , file ) ;
38+ logger . info ( `Loading plugin: ${ absolutePath } ` ) ;
39+ try {
40+ await checkFileForChangeMe ( absolutePath ) ;
41+ const module = await import ( absolutePath ) ;
42+ const plugin = module . default ;
43+ pluginManager . register ( plugin ) ;
44+ pluginCount ++ ;
45+ } catch ( error ) {
46+ pluginManager . fail ( { name : file } ) ;
47+ logger . error (
48+ `Error while registering plugin ${ absolutePath } : ${ error as string } ` ,
49+ ) ;
50+ }
51+ }
52+
53+ logger . info ( `Registered ${ pluginCount } plugin(s)` ) ;
5454}
0 commit comments