@@ -17,7 +17,10 @@ import { readFileSync } from 'node:fs';
1717import { join } from 'node:path' ;
1818import { SfCommand , Flags } from '@salesforce/sf-plugins-core' ;
1919import { Messages , SfError } from '@salesforce/core' ;
20+ import { MultiStageOutput } from '@oclif/multi-stage-output' ;
2021import { Agent , findAuthoringBundle } from '@salesforce/agents' ;
22+ import { Duration , sleep } from '@salesforce/kit' ;
23+ import { colorize } from '@oclif/core/ux' ;
2124import { FlaggablePrompt , promptForFlag } from '../../../flags.js' ;
2225
2326Messages . importMessagesDirectoryFromMetaUrl ( import . meta. url ) ;
@@ -73,25 +76,57 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat
7376 messages . getMessage ( 'error.agentNotFoundAction' ) ,
7477 ] ) ;
7578 }
79+ const mso = new MultiStageOutput < { status : string ; errors : string } > ( {
80+ jsonEnabled : this . jsonEnabled ( ) ,
81+ title : `Validating ${ apiName } Authoring Bundle` ,
82+ showTitle : true ,
83+ stages : [ 'Validating Authoring Bundle' ] ,
84+ stageSpecificBlock : [
85+ {
86+ stage : 'Validating Authoring Bundle' ,
87+ label : 'Status' ,
88+ type : 'dynamic-key-value' ,
89+ get : ( data ) : string => data ?. status ?? 'IN PROGRESS' ,
90+ } ,
91+ {
92+ stage : 'Validating Authoring Bundle' ,
93+ label : 'Errors' ,
94+ type : 'dynamic-key-value' ,
95+ get : ( data ) : string => data ?. errors ?? '0' ,
96+ } ,
97+ ] ,
98+ } ) ;
7699
77100 try {
101+ mso . skipTo ( 'Validating Authoring Bundle' ) ;
78102 const targetOrg = flags [ 'target-org' ] ;
79103 const conn = targetOrg . getConnection ( flags [ 'api-version' ] ) ;
80104 // Call Agent.compileAfScript() API
105+ await sleep ( Duration . seconds ( 2 ) ) ;
81106 await Agent . compileAfScript ( conn , readFileSync ( join ( authoringBundleDir , `${ ! apiName } .agent` ) , 'utf8' ) ) ;
82- this . logSuccess ( 'Successfully compiled' ) ;
107+ mso . updateData ( { status : 'COMPLETED' } ) ;
108+ mso . stop ( 'completed' ) ;
83109 return {
84110 success : true ,
85111 } ;
86112 } catch ( error ) {
87113 // Handle validation errors
88114 const err = SfError . wrap ( error ) ;
115+ let count = 0 ;
89116 const formattedError = err . message
90117 . split ( '\n' )
91- . map ( ( line ) => `- ${ line } ` )
118+ . map ( ( line ) => {
119+ count += 1 ;
120+ const type = line . split ( ':' ) [ 0 ] ;
121+ const rest = line . substring ( line . indexOf ( ':' ) ) . trim ( ) ;
122+ return `- ${ colorize ( 'red' , type ) } ${ rest } ` ;
123+ } )
92124 . join ( '\n' ) ;
93- this . error ( messages . getMessage ( 'error.compilationFailed' , [ formattedError ] ) ) ;
94125
126+ mso . updateData ( { errors : count . toString ( ) , status : 'ERROR' } ) ;
127+ mso . error ( ) ;
128+
129+ this . log ( messages . getMessage ( 'error.compilationFailed' , [ formattedError ] ) ) ;
95130 return {
96131 success : false ,
97132 errors : err . message . split ( '\n' ) ,
0 commit comments