@@ -24,15 +24,22 @@ const enum POSTPROCESSING_STEP {
2424 ENCRYPTION = 'ENCRYPTION' ,
2525}
2626
27- type Step = {
28- success : boolean ;
27+ type StepPassed = {
28+ success : true ;
2929 step : POSTPROCESSING_STEP ;
3030 outputPath ?: string ;
3131} ;
3232
33+ type StepFailed = {
34+ success : false ;
35+ step : POSTPROCESSING_STEP ;
36+ error : string ;
37+ } ;
38+
39+
3340export interface PostprocessFileResult {
3441 success : boolean ;
35- steps : Step [ ] ;
42+ steps : ( StepPassed | StepFailed ) [ ] ;
3643 outputPath ?: string ;
3744}
3845
@@ -75,7 +82,7 @@ export async function postprocessFile({ config, inputPath, outputPath, options }
7582
7683 if ( ! encryptResult . success ) {
7784 log ( `[ERROR] Encryption failed: ${ encryptResult . error } (code: ${ encryptResult . code } )` ) ;
78- result . steps . push ( { success : false , step : POSTPROCESSING_STEP . ENCRYPTION } ) ;
85+ result . steps . push ( { success : false , step : POSTPROCESSING_STEP . ENCRYPTION , error : encryptResult . error } ) ;
7986 }
8087 else result . steps . push ( { success : true , step : POSTPROCESSING_STEP . ENCRYPTION , outputPath : encryptResult . outputPath } ) ;
8188 }
@@ -84,6 +91,11 @@ export async function postprocessFile({ config, inputPath, outputPath, options }
8491
8592 log ( "[INFO] Postprocessing complete." ) ;
8693 if ( result . steps . some ( s => ! s . success ) ) result . success = false ;
87- else if ( result . steps . length > 0 ) result . outputPath = result . steps [ result . steps . length - 1 ] . outputPath ; // set outputPath to last successful step outputPath
94+ else {
95+ const lastStepWithOutput = [ ...result . steps ] . reverse ( ) . find ( s => s . success && 'outputPath' in s && s . outputPath ) ;
96+ if ( lastStepWithOutput && 'outputPath' in lastStepWithOutput ) {
97+ result . outputPath = lastStepWithOutput . outputPath ;
98+ }
99+ }
88100 return result ;
89101}
0 commit comments