@@ -11,62 +11,50 @@ export class ModuleManager {
1111 this . provider = new CLIProviderImpl ( ) ;
1212 }
1313
14- /**
15- * 注册一个CLI模块
16- */
1714 registerModule ( module : CLIModule ) : void {
1815 if ( this . modules . has ( module . name ) ) {
1916 throw new Error ( `Module '${ module . name } ' is already registered` ) ;
2017 }
2118
2219 this . modules . set ( module . name , module ) ;
2320
24- // 注册模块的命令
2521 if ( module . commands ) {
2622 for ( const command of module . commands ) {
2723 this . registerCommand ( command ) ;
2824 }
2925 }
3026
31- // 注册模块的工作流
3227 if ( module . workflows ) {
3328 for ( const workflow of module . workflows ) {
3429 this . registerWorkflow ( workflow ) ;
3530 }
3631 }
3732
38- // 初始化模块
3933 if ( module . init ) {
4034 module . init ( this . provider ) ;
4135 }
4236
4337 console . log ( `Module '${ module . name } ' (v${ module . version } ) registered successfully` ) ;
4438 }
4539
46- /**
47- * 注销一个CLI模块
48- */
4940 unregisterModule ( moduleName : string ) : void {
5041 const module = this . modules . get ( moduleName ) ;
5142 if ( ! module ) {
5243 throw new Error ( `Module '${ moduleName } ' is not registered` ) ;
5344 }
5445
55- // 清理模块的命令
5646 if ( module . commands ) {
5747 for ( const command of module . commands ) {
5848 this . commands . delete ( command . name ) ;
5949 }
6050 }
6151
62- // 清理模块的工作流
6352 if ( module . workflows ) {
6453 for ( const workflow of module . workflows ) {
6554 this . workflows . delete ( workflow . name ) ;
6655 }
6756 }
6857
69- // 清理模块
7058 if ( module . cleanup ) {
7159 module . cleanup ( ) ;
7260 }
@@ -75,19 +63,15 @@ export class ModuleManager {
7563 console . log ( `Module '${ moduleName } ' unregistered successfully` ) ;
7664 }
7765
78- /**
79- * 注册单个命令
80- */
66+
8167 registerCommand ( command : CommandDefinition ) : void {
8268 if ( this . commands . has ( command . name ) ) {
8369 throw new Error ( `Command '${ command . name } ' is already registered` ) ;
8470 }
8571 this . commands . set ( command . name , command ) ;
8672 }
8773
88- /**
89- * 注册单个工作流
90- */
74+
9175 registerWorkflow ( workflow : CustomWorkflow ) : void {
9276 if ( this . workflows . has ( workflow . name ) ) {
9377 throw new Error ( `Workflow '${ workflow . name } ' is already registered` ) ;
@@ -96,30 +80,22 @@ export class ModuleManager {
9680 this . provider . registerWorkflow ( workflow ) ;
9781 }
9882
99- /**
100- * 获取所有注册的命令
101- */
83+
10284 getRegisteredCommands ( ) : CommandDefinition [ ] {
10385 return Array . from ( this . commands . values ( ) ) ;
10486 }
10587
106- /**
107- * 获取所有注册的工作流
108- */
88+
10989 getRegisteredWorkflows ( ) : CustomWorkflow [ ] {
11090 return Array . from ( this . workflows . values ( ) ) ;
11191 }
11292
113- /**
114- * 获取所有注册的模块
115- */
93+
11694 getRegisteredModules ( ) : CLIModule [ ] {
11795 return Array . from ( this . modules . values ( ) ) ;
11896 }
11997
120- /**
121- * 执行命令
122- */
98+
12399 async executeCommand ( commandName : string , context : any ) : Promise < any > {
124100 const command = this . commands . get ( commandName ) ;
125101 if ( ! command ) {
@@ -129,23 +105,17 @@ export class ModuleManager {
129105 return await command . handler ( context ) ;
130106 }
131107
132- /**
133- * 执行工作流
134- */
108+
135109 async executeWorkflow ( workflowName : string , context : any ) : Promise < any > {
136110 return await this . provider . executeWorkflow ( workflowName , context ) ;
137111 }
138112
139- /**
140- * 获取CLI提供者实例
141- */
113+
142114 getProvider ( ) : CLIProvider {
143115 return this . provider ;
144116 }
145117
146- /**
147- * 列出所有可用的命令和工作流
148- */
118+
149119 listAll ( ) : void {
150120 console . log ( '\n=== Registered Commands ===' ) ;
151121 for ( const command of this . commands . values ( ) ) {
@@ -164,5 +134,4 @@ export class ModuleManager {
164134 }
165135}
166136
167- // 创建全局模块管理器实例
168137export const moduleManager = new ModuleManager ( ) ;
0 commit comments