11import path from 'path' ;
22import * as os from 'os' ;
3- import { flags } from '@salesforce/command' ;
4- import { Messages , Connection } from '@salesforce/core' ;
5- import OmniStudioBaseCommand from '../../basecommand' ;
3+ import { Messages , Connection , Org , Logger as CoreLogger } from '@salesforce/core' ;
4+ import { SfCommand , Ux , Flags as flags } from '@salesforce/sf-plugins-core' ;
65import { AssessmentInfo } from '../../../utils/interfaces' ;
76import { AssessmentReporter } from '../../../utils/resultsbuilder/assessmentReporter' ;
87import { OmniScriptExportType , OmniScriptMigrationTool } from '../../../migration/omniscript' ;
@@ -26,54 +25,75 @@ import { ValidatorService } from '../../../utils/validatorService';
2625Messages . importMessagesDirectory ( __dirname ) ;
2726const messages = Messages . loadMessages ( '@salesforce/plugin-omnistudio-migration-tool' , 'assess' ) ;
2827
29- export default class Assess extends OmniStudioBaseCommand {
28+ interface AssessFlags {
29+ 'target-org' ?: Org ;
30+ only ?: string ;
31+ allversions ?: boolean ;
32+ relatedobjects ?: string ;
33+ verbose ?: boolean ;
34+ }
35+
36+ export default class Assess extends SfCommand < AssessmentInfo > {
3037 public static description = messages . getMessage ( 'commandDescription' ) ;
3138
3239 public static examples = messages . getMessage ( 'examples' ) . split ( os . EOL ) ;
3340
34- public static args = [ { name : 'file' } ] ;
41+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
42+ public static args : any = [ ] ;
3543
36- protected static flagsConfig = {
44+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45+ public static readonly flags : any = {
46+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
47+ 'target-org' : flags . optionalOrg ( {
48+ summary : 'Target org username or alias' ,
49+ required : true ,
50+ } ) ,
51+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
3752 only : flags . string ( {
3853 char : 'o' ,
3954 description : messages . getMessage ( 'onlyFlagDescription' ) ,
4055 } ) ,
56+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
4157 allversions : flags . boolean ( {
4258 char : 'a' ,
4359 description : messages . getMessage ( 'allVersionsDescription' ) ,
4460 required : false ,
4561 } ) ,
62+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
4663 relatedobjects : flags . string ( {
4764 char : 'r' ,
4865 description : messages . getMessage ( 'relatedObjectGA' ) ,
4966 } ) ,
50- verbose : flags . builtin ( {
51- type : 'builtin' ,
67+ verbose : flags . boolean ( {
5268 description : messages . getMessage ( 'enableVerboseOutput' ) ,
5369 } ) ,
5470 } ;
5571
56- // eslint-disable-next-line @typescript-eslint/no-explicit-any
57- public async run ( ) : Promise < any > {
58- Logger . initialiseLogger ( this . ux , this . logger , 'assess' , this . flags . verbose ) ;
72+ public async run ( ) : Promise < AssessmentInfo > {
73+ const { flags : parsedFlags } = await this . parse ( Assess ) ;
74+ const ux = new Ux ( { jsonEnabled : this . jsonEnabled ( ) } ) ;
75+ const logger = await CoreLogger . child ( this . constructor . name ) ;
76+ Logger . initialiseLogger ( ux , logger , 'assess' , parsedFlags . verbose ) ;
5977 try {
60- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
61- return await this . runAssess ( ) ;
78+ return await this . runAssess ( parsedFlags as AssessFlags , ux , logger ) ;
6279 } catch ( e ) {
6380 const error = e as Error ;
6481 Logger . error ( messages . getMessage ( 'errorRunningAssess' , [ error . message ] ) , error ) ;
6582 process . exit ( 1 ) ;
6683 }
6784 }
6885
69- // eslint-disable-next-line @typescript-eslint/no-explicit-any
70- public async runAssess ( ) : Promise < any > {
86+ public async runAssess ( parsedFlags : AssessFlags , ux : Ux , logger : CoreLogger ) : Promise < AssessmentInfo > {
7187 DebugTimer . getInstance ( ) . start ( ) ;
72- const allVersions = ( this . flags . allversions || false ) as boolean ;
73- const assessOnly = ( this . flags . only || '' ) as string ;
74- const relatedObjects = ( this . flags . relatedobjects || '' ) as string ;
88+ const allVersions = parsedFlags . allversions || false ;
89+ const assessOnly = parsedFlags . only || '' ;
90+ const relatedObjects = parsedFlags . relatedobjects || '' ;
7591 const isExperienceBundleMetadataAPIProgramaticallyEnabled : { value : boolean } = { value : false } ;
76- const conn = this . org . getConnection ( ) ;
92+
93+ // target-org is required by flag definition, so it will always be present
94+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
95+ const org = parsedFlags [ 'target-org' ] ! ;
96+ const conn = org . getConnection ( ) ;
7797 let objectsToProcess : string [ ] ;
7898 // To-Do: Add LWC to valid options when GA is released
7999 const validOptions = [ Constants . Apex , Constants . ExpSites , Constants . FlexiPage , Constants . LWC ] ;
@@ -93,7 +113,7 @@ export default class Assess extends OmniStudioBaseCommand {
93113
94114 const namespace = orgs . packageDetails . namespace ;
95115 let projectPath = '' ;
96- const preMigrate : PreMigrate = new PreMigrate ( namespace , conn , this . logger , messages , this . ux ) ;
116+ const preMigrate : PreMigrate = new PreMigrate ( namespace , conn , logger , messages , ux ) ;
97117 if ( relatedObjects ) {
98118 objectsToProcess = relatedObjects . split ( ',' ) . map ( ( obj ) => obj . trim ( ) ) ;
99119 projectPath = await ProjectPathUtil . getProjectPath ( messages , true ) ;
@@ -129,13 +149,13 @@ export default class Assess extends OmniStudioBaseCommand {
129149
130150 Logger . log ( messages . getMessage ( 'assessmentInitialization' , [ String ( namespace ) ] ) ) ;
131151 Logger . log ( messages . getMessage ( 'apiVersionInfo' , [ String ( apiVersion ) ] ) ) ;
132- Logger . logVerbose ( messages . getMessage ( 'assessmentTargets' , [ String ( this . flags . only || 'all' ) ] ) ) ;
152+ Logger . logVerbose ( messages . getMessage ( 'assessmentTargets' , [ String ( parsedFlags . only || 'all' ) ] ) ) ;
133153 Logger . logVerbose ( messages . getMessage ( 'relatedObjectsInfo' , [ relatedObjects || 'none' ] ) ) ;
134154 Logger . logVerbose ( messages . getMessage ( 'allVersionsFlagInfo' , [ String ( allVersions ) ] ) ) ;
135155
136156 try {
137157 // Assess OmniStudio components
138- await this . assessOmniStudioComponents ( assesmentInfo , assessOnly , namespace , conn , allVersions ) ;
158+ await this . assessOmniStudioComponents ( assesmentInfo , assessOnly , namespace , conn , allVersions , ux ) ;
139159 // eslint-disable-next-line @typescript-eslint/no-explicit-any
140160 } catch ( ex : any ) {
141161 if ( ex instanceof InvalidEntityTypeError ) {
@@ -165,7 +185,7 @@ export default class Assess extends OmniStudioBaseCommand {
165185 namespace ,
166186 assessOnly ,
167187 allVersions ,
168- this . org ,
188+ org ,
169189 projectPath
170190 ) ;
171191 const relatedObjectAssessmentResult = omnistudioRelatedObjectsMigration . assessAll ( objectsToProcess ) ;
@@ -182,15 +202,7 @@ export default class Assess extends OmniStudioBaseCommand {
182202 }
183203
184204 // Post Assessment tasks
185- const postMigrate : PostMigrate = new PostMigrate (
186- this . org ,
187- namespace ,
188- conn ,
189- this . logger ,
190- messages ,
191- this . ux ,
192- objectsToProcess
193- ) ;
205+ const postMigrate : PostMigrate = new PostMigrate ( org , namespace , conn , logger , messages , ux , objectsToProcess ) ;
194206
195207 const userActionMessages : string [ ] = [ ] ;
196208 await postMigrate . restoreExperienceAPIMetadataSettings (
@@ -222,34 +234,35 @@ export default class Assess extends OmniStudioBaseCommand {
222234 assessOnly : string ,
223235 namespace : string ,
224236 conn : Connection ,
225- allVersions : boolean
237+ allVersions : boolean ,
238+ ux : Ux
226239 ) : Promise < void > {
227240 if ( ! assessOnly ) {
228241 // If no specific component is specified, assess all components
229- await this . assessDataRaptors ( assesmentInfo , namespace , conn ) ;
230- await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions ) ;
231- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS ) ;
232- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP ) ;
233- await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn ) ;
242+ await this . assessDataRaptors ( assesmentInfo , namespace , conn , ux ) ;
243+ await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions , ux ) ;
244+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS , ux ) ;
245+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP , ux ) ;
246+ await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn , ux ) ;
234247 await this . assessCustomLabels ( assesmentInfo , namespace , conn ) ;
235248 return ;
236249 }
237250
238251 switch ( assessOnly ) {
239252 case Constants . DataMapper :
240- await this . assessDataRaptors ( assesmentInfo , namespace , conn ) ;
253+ await this . assessDataRaptors ( assesmentInfo , namespace , conn , ux ) ;
241254 break ;
242255 case Constants . Flexcard :
243- await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions ) ;
256+ await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions , ux ) ;
244257 break ;
245258 case Constants . Omniscript :
246- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS ) ;
259+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS , ux ) ;
247260 break ;
248261 case Constants . IntegrationProcedure :
249- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP ) ;
262+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP , ux ) ;
250263 break ;
251264 case Constants . GlobalAutoNumber :
252- await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn ) ;
265+ await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn , ux ) ;
253266 break ;
254267 case Constants . CustomLabel :
255268 await this . assessCustomLabels ( assesmentInfo , namespace , conn ) ;
@@ -259,8 +272,13 @@ export default class Assess extends OmniStudioBaseCommand {
259272 }
260273 }
261274
262- private async assessDataRaptors ( assesmentInfo : AssessmentInfo , namespace : string , conn : Connection ) : Promise < void > {
263- const drMigrator = new DataRaptorMigrationTool ( namespace , conn , Logger , messages , this . ux ) ;
275+ private async assessDataRaptors (
276+ assesmentInfo : AssessmentInfo ,
277+ namespace : string ,
278+ conn : Connection ,
279+ ux : Ux
280+ ) : Promise < void > {
281+ const drMigrator = new DataRaptorMigrationTool ( namespace , conn , Logger , messages , ux ) ;
264282 assesmentInfo . dataRaptorAssessmentInfos = await drMigrator . assess ( ) ;
265283 Logger . logVerbose (
266284 messages . getMessage ( 'assessedDataRaptorsCount' , [ assesmentInfo . dataRaptorAssessmentInfos . length ] )
@@ -272,9 +290,10 @@ export default class Assess extends OmniStudioBaseCommand {
272290 assesmentInfo : AssessmentInfo ,
273291 namespace : string ,
274292 conn : Connection ,
275- allVersions : boolean
293+ allVersions : boolean ,
294+ ux : Ux
276295 ) : Promise < void > {
277- const flexMigrator = new CardMigrationTool ( namespace , conn , Logger , messages , this . ux , allVersions ) ;
296+ const flexMigrator = new CardMigrationTool ( namespace , conn , Logger , messages , ux , allVersions ) ;
278297 Logger . logVerbose ( messages . getMessage ( 'flexCardAssessment' ) ) ;
279298 assesmentInfo . flexCardAssessmentInfos = await flexMigrator . assess ( ) ;
280299 Logger . logVerbose ( messages . getMessage ( 'assessedFlexCardsCount' , [ assesmentInfo . flexCardAssessmentInfos . length ] ) ) ;
@@ -286,11 +305,12 @@ export default class Assess extends OmniStudioBaseCommand {
286305 namespace : string ,
287306 conn : Connection ,
288307 allVersions : boolean ,
289- exportType : OmniScriptExportType
308+ exportType : OmniScriptExportType ,
309+ ux : Ux
290310 ) : Promise < void > {
291311 const exportComponentType = exportType === OmniScriptExportType . IP ? 'Integration Procedures' : 'Omniscripts' ;
292312 Logger . logVerbose ( messages . getMessage ( 'omniScriptAssessment' , [ exportComponentType ] ) ) ;
293- const osMigrator = new OmniScriptMigrationTool ( exportType , namespace , conn , Logger , messages , this . ux , allVersions ) ;
313+ const osMigrator = new OmniScriptMigrationTool ( exportType , namespace , conn , Logger , messages , ux , allVersions ) ;
294314 const newOmniAssessmentInfo = await osMigrator . assess (
295315 assesmentInfo . dataRaptorAssessmentInfos ,
296316 assesmentInfo . flexCardAssessmentInfos
@@ -326,10 +346,11 @@ export default class Assess extends OmniStudioBaseCommand {
326346 private async assessGlobalAutoNumbers (
327347 assesmentInfo : AssessmentInfo ,
328348 namespace : string ,
329- conn : Connection
349+ conn : Connection ,
350+ ux : Ux
330351 ) : Promise < void > {
331352 Logger . logVerbose ( messages . getMessage ( 'startingGlobalAutoNumberAssessment' ) ) ;
332- const globalAutoNumberMigrationTool = new GlobalAutoNumberMigrationTool ( namespace , conn , Logger , messages , this . ux ) ;
353+ const globalAutoNumberMigrationTool = new GlobalAutoNumberMigrationTool ( namespace , conn , Logger , messages , ux ) ;
333354 assesmentInfo . globalAutoNumberAssessmentInfos = await globalAutoNumberMigrationTool . assess ( ) ;
334355 Logger . logVerbose (
335356 messages . getMessage ( 'assessedGlobalAutoNumbersCount' , [ assesmentInfo . globalAutoNumberAssessmentInfos . length ] )
0 commit comments