@@ -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' ;
2124
2225Messages . importMessagesDirectoryFromMetaUrl ( import . meta. url ) ;
2326const messages = Messages . loadMessages ( '@salesforce/plugin-agent' , 'agent.validate.authoring-bundle' ) ;
@@ -45,33 +48,66 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat
4548
4649 public async run ( ) : Promise < AgentValidateAuthoringBundleResult > {
4750 const { flags } = await this . parse ( AgentValidateAuthoringBundle ) ;
48- // todo: this eslint warning can be removed once published
49- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
5051 const authoringBundleDir = findAuthoringBundle ( this . project ! . getPath ( ) , flags [ 'api-name' ] ) ;
5152 if ( ! authoringBundleDir ) {
5253 throw new SfError ( messages . getMessage ( 'error.afscriptNotFound' , [ flags [ 'api-name' ] ] ) , 'AfScriptNotFoundError' , [
5354 messages . getMessage ( 'error.afscriptNotFoundAction' ) ,
5455 ] ) ;
5556 }
57+ const mso = new MultiStageOutput < { status : string ; errors : string } > ( {
58+ jsonEnabled : this . jsonEnabled ( ) ,
59+ title : `Validating ${ flags [ 'api-name' ] } Authoring Bundle` ,
60+ showTitle : true ,
61+ stages : [ 'Validating Authoring Bundle' ] ,
62+ stageSpecificBlock : [
63+ {
64+ stage : 'Validating Authoring Bundle' ,
65+ label : 'Status' ,
66+ type : 'dynamic-key-value' ,
67+ get : ( data ) : string | undefined => data ?. status ?? 'In Progress' ,
68+ } ,
69+ {
70+ stage : 'Validating Authoring Bundle' ,
71+ label : 'Errors' ,
72+ type : 'dynamic-key-value' ,
73+ get : ( data ) : string | undefined => data ?. errors ?? '0' ,
74+ } ,
75+ ] ,
76+ } ) ;
5677
5778 try {
79+ mso . skipTo ( 'Validating Authoring Bundle' ) ;
5880 const targetOrg = flags [ 'target-org' ] ;
5981 const conn = targetOrg . getConnection ( flags [ 'api-version' ] ) ;
6082 // Call Agent.compileAfScript() API
61- await Agent . compileAfScript ( conn , readFileSync ( join ( authoringBundleDir , `${ flags [ 'api-name' ] } .agent` ) , 'utf8' ) ) ;
62- this . logSuccess ( 'Successfully compiled' ) ;
83+ await sleep ( Duration . seconds ( 2 ) ) ;
84+ const result = await Agent . compileAfScript (
85+ conn ,
86+ readFileSync ( join ( authoringBundleDir , `${ flags [ 'api-name' ] } .agent` ) , 'utf8' )
87+ ) ;
88+ mso . updateData ( { status : result !== undefined ? 'Success' : 'Failure' } ) ;
89+ mso . stop ( 'completed' ) ;
6390 return {
6491 success : true ,
6592 } ;
6693 } catch ( error ) {
6794 // Handle validation errors
6895 const err = SfError . wrap ( error ) ;
96+ let count = 0 ;
6997 const formattedError = err . message
7098 . split ( '\n' )
71- . map ( ( line ) => `- ${ line } ` )
99+ . map ( ( line ) => {
100+ count += 1 ;
101+ const type = line . split ( ':' ) [ 0 ] ;
102+ const rest = line . substring ( line . indexOf ( ':' ) ) . trim ( ) ;
103+ return `- ${ colorize ( 'red' , type ) } ${ rest } ` ;
104+ } )
72105 . join ( '\n' ) ;
73- this . error ( messages . getMessage ( 'error.compilationFailed' , [ formattedError ] ) ) ;
74106
107+ mso . updateData ( { errors : count . toString ( ) , status : 'Failure' } ) ;
108+ mso . stop ( ) ;
109+
110+ this . log ( messages . getMessage ( 'error.compilationFailed' , [ formattedError ] ) ) ;
75111 return {
76112 success : false ,
77113 errors : err . message . split ( '\n' ) ,
0 commit comments