@@ -17,19 +17,19 @@ require(pathToBootstrap);
1717const fileLogService = $injector . resolve < IFileLogService > ( FileLogService , { logFile } ) ;
1818fileLogService . logData ( { message : "Initializing Cleanup process." } ) ;
1919
20- const actionsToExecute : ICleanupAction [ ] = [ ] ;
20+ const commandsInfos : ISpawnCommandInfo [ ] = [ ] ;
2121const filesToDelete : string [ ] = [ ] ;
2222
2323const executeCleanup = async ( ) => {
2424 const $childProcess = $injector . resolve < IChildProcess > ( "childProcess" ) ;
25- for ( const action of actionsToExecute ) {
25+ for ( const commandInfo of commandsInfos ) {
2626 try {
27- fileLogService . logData ( { message : `Start executing action : ${ JSON . stringify ( action ) } ` } ) ;
27+ fileLogService . logData ( { message : `Start executing command : ${ JSON . stringify ( commandInfo ) } ` } ) ;
2828
29- await $childProcess . trySpawnFromCloseEvent ( action . command , action . args , { } , { throwError : true , timeout : action . timeout || 3000 } ) ;
30- fileLogService . logData ( { message : `Successfully executed action : ${ JSON . stringify ( action ) } ` } ) ;
29+ await $childProcess . trySpawnFromCloseEvent ( commandInfo . command , commandInfo . args , { } , { throwError : true , timeout : commandInfo . timeout || 3000 } ) ;
30+ fileLogService . logData ( { message : `Successfully executed command : ${ JSON . stringify ( commandInfo ) } ` } ) ;
3131 } catch ( err ) {
32- fileLogService . logData ( { message : `Unable to execute action : ${ JSON . stringify ( action ) } ` , type : FileLogMessageType . Error } ) ;
32+ fileLogService . logData ( { message : `Unable to execute command : ${ JSON . stringify ( commandInfo ) } ` , type : FileLogMessageType . Error } ) ;
3333 }
3434 }
3535
@@ -42,21 +42,21 @@ const executeCleanup = async () => {
4242 process . exit ( ) ;
4343} ;
4444
45- const addCleanupAction = ( newAction : ICleanupAction ) : void => {
46- if ( _ . some ( actionsToExecute , currentAction => _ . isEqual ( currentAction , newAction ) ) ) {
47- fileLogService . logData ( { message : `cleanup-process will not add action for execution as it has been added already: ${ JSON . stringify ( newAction ) } ` } ) ;
45+ const addCleanupAction = ( commandInfo : ISpawnCommandInfo ) : void => {
46+ if ( _ . some ( commandsInfos , currentCommandInfo => _ . isEqual ( currentCommandInfo , commandInfo ) ) ) {
47+ fileLogService . logData ( { message : `cleanup-process will not add command for execution as it has been added already: ${ JSON . stringify ( commandInfo ) } ` } ) ;
4848 } else {
49- fileLogService . logData ( { message : `cleanup-process added action for execution: ${ JSON . stringify ( newAction ) } ` } ) ;
50- actionsToExecute . push ( newAction ) ;
49+ fileLogService . logData ( { message : `cleanup-process added command for execution: ${ JSON . stringify ( commandInfo ) } ` } ) ;
50+ commandsInfos . push ( commandInfo ) ;
5151 }
5252} ;
5353
54- const removeCleanupAction = ( actionToRemove : ICleanupAction ) : void => {
55- if ( _ . some ( actionsToExecute , currentAction => _ . isEqual ( currentAction , actionToRemove ) ) ) {
56- _ . remove ( actionsToExecute , currentAction => _ . isEqual ( currentAction , actionToRemove ) ) ;
57- fileLogService . logData ( { message : `cleanup-process removed action for execution: ${ JSON . stringify ( actionToRemove ) } ` } ) ;
54+ const removeCleanupAction = ( commandInfo : ISpawnCommandInfo ) : void => {
55+ if ( _ . some ( commandsInfos , currentCommandInfo => _ . isEqual ( currentCommandInfo , commandInfo ) ) ) {
56+ _ . remove ( commandsInfos , currentCommandInfo => _ . isEqual ( currentCommandInfo , commandInfo ) ) ;
57+ fileLogService . logData ( { message : `cleanup-process removed command for execution: ${ JSON . stringify ( commandInfo ) } ` } ) ;
5858 } else {
59- fileLogService . logData ( { message : `cleanup-process cannot remove action for execution as it has note been added before: ${ JSON . stringify ( actionToRemove ) } ` } ) ;
59+ fileLogService . logData ( { message : `cleanup-process cannot remove command for execution as it has note been added before: ${ JSON . stringify ( commandInfo ) } ` } ) ;
6060 }
6161} ;
6262
@@ -82,24 +82,24 @@ const removeDeleteAction = (filePath: string): void => {
8282 }
8383} ;
8484
85- process . on ( "message" , async ( cleanupProcessMessage : ICleanupProcessMessage ) => {
85+ process . on ( "message" , async ( cleanupProcessMessage : ICleanupMessageBase ) => {
8686 fileLogService . logData ( { message : `cleanup-process received message of type: ${ JSON . stringify ( cleanupProcessMessage ) } ` } ) ;
8787
88- switch ( cleanupProcessMessage . actionType ) {
89- case CleanupProcessMessageType . AddCleanAction :
90- addCleanupAction ( ( < ICleanupActionMessage > cleanupProcessMessage ) . action ) ;
88+ switch ( cleanupProcessMessage . messageType ) {
89+ case CleanupProcessMessage . AddCleanCommand :
90+ addCleanupAction ( ( < ISpawnCommandCleanupMessage > cleanupProcessMessage ) . commandInfo ) ;
9191 break ;
92- case CleanupProcessMessageType . RemoveCleanAction :
93- removeCleanupAction ( ( < ICleanupActionMessage > cleanupProcessMessage ) . action ) ;
92+ case CleanupProcessMessage . RemoveCleanCommand :
93+ removeCleanupAction ( ( < ISpawnCommandCleanupMessage > cleanupProcessMessage ) . commandInfo ) ;
9494 break ;
95- case CleanupProcessMessageType . AddDeleteAction :
96- addDeleteAction ( ( < ICleanupDeleteActionMessage > cleanupProcessMessage ) . filePath ) ;
95+ case CleanupProcessMessage . AddDeleteFileAction :
96+ addDeleteAction ( ( < IDeleteFileCleanupMessage > cleanupProcessMessage ) . filePath ) ;
9797 break ;
98- case CleanupProcessMessageType . RemoveDeleteAction :
99- removeDeleteAction ( ( < ICleanupDeleteActionMessage > cleanupProcessMessage ) . filePath ) ;
98+ case CleanupProcessMessage . RemoveDeleteFileAction :
99+ removeDeleteAction ( ( < IDeleteFileCleanupMessage > cleanupProcessMessage ) . filePath ) ;
100100 break ;
101101 default :
102- fileLogService . logData ( { message : `Unable to handle message of type ${ cleanupProcessMessage . actionType } . Full message is ${ JSON . stringify ( cleanupProcessMessage ) } ` , type : FileLogMessageType . Error } ) ;
102+ fileLogService . logData ( { message : `Unable to handle message of type ${ cleanupProcessMessage . messageType } . Full message is ${ JSON . stringify ( cleanupProcessMessage ) } ` , type : FileLogMessageType . Error } ) ;
103103 break ;
104104 }
105105
0 commit comments