@@ -9,10 +9,10 @@ import { ProgressState, ProgressStatus } from '../components/progress/progress-d
99import { DisplayPlanStateTransition , RenderEvent , RenderState , Reporter } from './reporter.js' ;
1010
1111const ProgressLabelMapping = {
12- [ ProcessName . APPLY ] : 'Applying plan... ' ,
13- [ ProcessName . PLAN ] : 'Generating plan... ' ,
12+ [ ProcessName . APPLY ] : 'Codify plan' ,
13+ [ ProcessName . PLAN ] : 'Codify plan' ,
1414 [ SubProcessName . APPLY_RESOURCE ] : 'Applying resource' ,
15- [ SubProcessName . GENERATE_PLAN ] : 'Generating plan' ,
15+ [ SubProcessName . GENERATE_PLAN ] : 'Refresh states and generating plan' ,
1616 [ SubProcessName . INITIALIZE_PLUGINS ] : 'Initializing plugins' ,
1717 [ SubProcessName . PARSE ] : 'Parsing configs' ,
1818 [ SubProcessName . VALIDATE ] : 'Validating configs' ,
@@ -21,56 +21,64 @@ const ProgressLabelMapping = {
2121export class DefaultReporter implements Reporter {
2222
2323 private renderEmitter = new EventEmitter ( ) ;
24- private staticOutput = new Array < string > ( )
2524 private progressState : ProgressState | null = null
2625
2726 constructor ( ) {
28- ctx . on ( Event . OUTPUT , ( ...args ) => this . renderLog ( ...args ) ) ;
27+ render ( < DefaultComponent emitter = { this . renderEmitter } /> )
28+
29+ ctx . on ( Event . OUTPUT , ( args ) => this . log ( args ) ) ;
2930 ctx . on ( Event . PROCESS_START , ( name ) => this . onProcessStartEvent ( name ) )
3031 ctx . on ( Event . PROCESS_FINISH , ( name ) => this . onProcessFinishEvent ( name ) )
3132 ctx . on ( Event . SUB_PROCESS_START , ( name ) => this . onSubprocessStartEvent ( name ) ) ;
3233 ctx . on ( Event . SUB_PROCESS_FINISH , ( name ) => this . onSubprocessFinishEvent ( name ) )
34+ }
3335
34- render ( < DefaultComponent emitter = { this . renderEmitter } /> )
36+ displayPlan ( plan : PlanResponseData [ ] ) : void {
37+ this . progressState = null ;
38+
39+ this . renderEmitter . emit ( RenderEvent . STATE_TRANSITION , {
40+ nextState : RenderState . DISPLAY_PLAN ,
41+ plan,
42+ } as DisplayPlanStateTransition ) ;
3543 }
3644
37- async promptConfirmation ( ) : Promise < boolean > {
45+ async promptApplyConfirmation ( ) : Promise < boolean > {
3846 const result = await Promise . all ( [
3947 new Promise < boolean > ( ( resolve ) => {
4048 this . renderEmitter . once ( RenderEvent . PROMPT_RESULT , ( isConfirmed ) => resolve ( isConfirmed as boolean ) ) ;
4149 } ) ,
4250 this . renderEmitter . emit ( RenderEvent . STATE_TRANSITION , {
43- nextState : RenderState . ASK_CONFIRMATION ,
51+ nextState : RenderState . PROMPT_APPLY_CONFIRMATION ,
4452 } ) ,
4553 ] )
4654
55+ const continueApply = result [ 0 ] ;
4756
48- return result [ 0 ] ;
49- }
57+ if ( continueApply ) {
58+ this . renderEmitter . emit ( RenderEvent . STATE_TRANSITION , {
59+ nextState : RenderState . APPLYING ,
60+ } ) ;
61+ }
5062
51- displayPlan ( plan : PlanResponseData [ ] ) : void {
52- this . renderEmitter . emit ( RenderEvent . STATE_TRANSITION , {
53- nextState : RenderState . DISPLAY_PLAN ,
54- plan,
55- } as DisplayPlanStateTransition ) ;
63+ this . log ( `Do you want to apply the above changes? -> ${ continueApply ? '"Yes"' : '"No"' } ` )
64+ return continueApply ;
5665 }
5766
58- private renderLog ( ...args : string [ ] ) {
59- this . staticOutput . push ( ...args ) ;
60- this . renderEmitter . emit ( RenderEvent . LOG , this . staticOutput ) ;
67+ private log ( args : string ) : void {
68+ this . renderEmitter . emit ( RenderEvent . LOG , args ) ;
6169 }
6270
6371 private onProcessStartEvent ( name : ProcessName ) : void {
6472 const label = ProgressLabelMapping [ name ] ;
6573
6674 this . progressState = {
75+ label : label + '...' ,
6776 name,
68- label,
6977 status : ProgressStatus . IN_PROGRESS ,
7078 subProgresses : [ ] ,
7179 } ;
7280
73- this . renderLog ( `${ label } started` )
81+ this . log ( `${ label } started` )
7482 this . renderEmitter . emit ( RenderEvent . PROGRESS_UPDATE , this . progressState ) ;
7583 }
7684
@@ -79,7 +87,7 @@ export class DefaultReporter implements Reporter {
7987
8088 this . progressState ! . status = ProgressStatus . FINISHED ;
8189
82- this . renderLog ( `${ label } finished successfully` )
90+ this . log ( `${ label } finished successfully` )
8391 this . renderEmitter . emit ( RenderEvent . PROGRESS_UPDATE , this . progressState ) ;
8492
8593 }
@@ -88,12 +96,12 @@ export class DefaultReporter implements Reporter {
8896 const label = ProgressLabelMapping [ name ] ;
8997
9098 this . progressState ?. subProgresses ?. push ( {
91- name,
9299 label,
100+ name,
93101 status : ProgressStatus . IN_PROGRESS ,
94102 } ) ;
95103
96- this . renderLog ( `${ label } started` )
104+ this . log ( `${ label } started` )
97105 this . renderEmitter . emit ( RenderEvent . PROGRESS_UPDATE , this . progressState ) ;
98106 }
99107
@@ -110,7 +118,7 @@ export class DefaultReporter implements Reporter {
110118
111119 subProgress . status = ProgressStatus . FINISHED ;
112120
113- this . renderLog ( `${ label } finished successfully` )
121+ this . log ( `${ label } finished successfully` )
114122 this . renderEmitter . emit ( RenderEvent . PROGRESS_UPDATE , this . progressState ) ;
115123 }
116124
0 commit comments