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' ;
@@ -32,54 +31,78 @@ import { ValidatorService } from '../../../utils/validatorService';
3231Messages . importMessagesDirectory ( __dirname ) ;
3332const messages = Messages . loadMessages ( '@salesforce/plugin-omnistudio-migration-tool' , 'assess' ) ;
3433
35- export default class Assess extends OmniStudioBaseCommand {
34+ interface AssessFlags {
35+ 'target-org' ?: Org ;
36+ only ?: string ;
37+ allversions ?: boolean ;
38+ relatedobjects ?: string ;
39+ verbose ?: boolean ;
40+ }
41+
42+ export default class Assess extends SfCommand < AssessmentInfo > {
3643 public static description = messages . getMessage ( 'commandDescription' ) ;
3744
3845 public static examples = messages . getMessage ( 'examples' ) . split ( os . EOL ) ;
3946
40- public static args = [ { name : 'file' } ] ;
47+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48+ public static args : any = [ ] ;
4149
42- protected static flagsConfig = {
50+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51+ public static readonly flags : any = {
52+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
53+ 'target-org' : flags . optionalOrg ( {
54+ summary : 'Target org username or alias' ,
55+ required : true ,
56+ aliases : [ 'targetusername' , 'u' ] ,
57+ deprecateAliases : true ,
58+ makeDefault : false , // Prevent auto-resolution during command-reference generation
59+ } ) ,
60+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
4361 only : flags . string ( {
4462 char : 'o' ,
4563 description : messages . getMessage ( 'onlyFlagDescription' ) ,
4664 } ) ,
65+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
4766 allversions : flags . boolean ( {
4867 char : 'a' ,
4968 description : messages . getMessage ( 'allVersionsDescription' ) ,
5069 required : false ,
5170 } ) ,
71+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
5272 relatedobjects : flags . string ( {
5373 char : 'r' ,
5474 description : messages . getMessage ( 'relatedObjectGA' ) ,
5575 } ) ,
56- verbose : flags . builtin ( {
57- type : 'builtin' ,
76+ verbose : flags . boolean ( {
5877 description : messages . getMessage ( 'enableVerboseOutput' ) ,
5978 } ) ,
6079 } ;
6180
62- // eslint-disable-next-line @typescript-eslint/no-explicit-any
63- public async run ( ) : Promise < any > {
64- Logger . initialiseLogger ( this . ux , this . logger , 'assess' , this . flags . verbose ) ;
81+ public async run ( ) : Promise < AssessmentInfo > {
82+ const { flags : parsedFlags } = await this . parse ( Assess ) ;
83+ const ux = new Ux ( { jsonEnabled : this . jsonEnabled ( ) } ) ;
84+ const logger = await CoreLogger . child ( this . constructor . name ) ;
85+ Logger . initialiseLogger ( ux , logger , 'assess' , parsedFlags . verbose ) ;
6586 try {
66- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
67- return await this . runAssess ( ) ;
87+ return await this . runAssess ( parsedFlags as AssessFlags , ux , logger ) ;
6888 } catch ( e ) {
6989 const error = e as Error ;
7090 Logger . error ( messages . getMessage ( 'errorRunningAssess' , [ error . message ] ) , error ) ;
7191 process . exit ( 1 ) ;
7292 }
7393 }
7494
75- // eslint-disable-next-line @typescript-eslint/no-explicit-any
76- public async runAssess ( ) : Promise < any > {
95+ public async runAssess ( parsedFlags : AssessFlags , ux : Ux , logger : CoreLogger ) : Promise < AssessmentInfo > {
7796 DebugTimer . getInstance ( ) . start ( ) ;
78- let allVersions = ( this . flags . allversions || false ) as boolean ;
79- const assessOnly = ( this . flags . only || '' ) as string ;
80- const relatedObjects = ( this . flags . relatedobjects || '' ) as string ;
97+ const allVersions = parsedFlags . allversions || false ;
98+ const assessOnly = parsedFlags . only || '' ;
99+ const relatedObjects = parsedFlags . relatedobjects || '' ;
81100 const isExperienceBundleMetadataAPIProgramaticallyEnabled : { value : boolean } = { value : false } ;
82- const conn = this . org . getConnection ( ) ;
101+
102+ // target-org is required by flag definition, so it will always be present
103+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
104+ const org = parsedFlags [ 'target-org' ] ! ;
105+ const conn = org . getConnection ( ) ;
83106 let objectsToProcess : string [ ] ;
84107 // To-Do: Add LWC to valid options when GA is released
85108 const validOptions = [ Constants . Apex , Constants . ExpSites , Constants . FlexiPage , Constants . LWC ] ;
@@ -99,7 +122,7 @@ export default class Assess extends OmniStudioBaseCommand {
99122
100123 const namespace = orgs . packageDetails . namespace ;
101124 let projectPath = '' ;
102- const preMigrate : PreMigrate = new PreMigrate ( namespace , conn , this . logger , messages , this . ux ) ;
125+ const preMigrate : PreMigrate = new PreMigrate ( namespace , conn , logger , messages , ux ) ;
103126
104127 // Handle all versions prerequisite for standard data model
105128 if ( isStandardDataModel ( ) ) {
@@ -142,13 +165,13 @@ export default class Assess extends OmniStudioBaseCommand {
142165
143166 Logger . log ( messages . getMessage ( 'assessmentInitialization' , [ String ( namespace ) ] ) ) ;
144167 Logger . log ( messages . getMessage ( 'apiVersionInfo' , [ String ( apiVersion ) ] ) ) ;
145- Logger . logVerbose ( messages . getMessage ( 'assessmentTargets' , [ String ( this . flags . only || 'all' ) ] ) ) ;
168+ Logger . logVerbose ( messages . getMessage ( 'assessmentTargets' , [ String ( parsedFlags . only || 'all' ) ] ) ) ;
146169 Logger . logVerbose ( messages . getMessage ( 'relatedObjectsInfo' , [ relatedObjects || 'none' ] ) ) ;
147170 Logger . logVerbose ( messages . getMessage ( 'allVersionsFlagInfo' , [ String ( allVersions ) ] ) ) ;
148171
149172 try {
150173 // Assess OmniStudio components
151- await this . assessOmniStudioComponents ( assesmentInfo , assessOnly , namespace , conn , allVersions ) ;
174+ await this . assessOmniStudioComponents ( assesmentInfo , assessOnly , namespace , conn , allVersions , ux ) ;
152175 // eslint-disable-next-line @typescript-eslint/no-explicit-any
153176 } catch ( ex : any ) {
154177 if ( ex instanceof InvalidEntityTypeError ) {
@@ -178,7 +201,7 @@ export default class Assess extends OmniStudioBaseCommand {
178201 namespace ,
179202 assessOnly ,
180203 allVersions ,
181- this . org ,
204+ org ,
182205 projectPath
183206 ) ;
184207 const relatedObjectAssessmentResult = omnistudioRelatedObjectsMigration . assessAll ( objectsToProcess ) ;
@@ -195,15 +218,7 @@ export default class Assess extends OmniStudioBaseCommand {
195218 }
196219
197220 // Post Assessment tasks
198- const postMigrate : PostMigrate = new PostMigrate (
199- this . org ,
200- namespace ,
201- conn ,
202- this . logger ,
203- messages ,
204- this . ux ,
205- objectsToProcess
206- ) ;
221+ const postMigrate : PostMigrate = new PostMigrate ( org , namespace , conn , logger , messages , ux , objectsToProcess ) ;
207222
208223 const userActionMessages : string [ ] = [ ] ;
209224 await postMigrate . restoreExperienceAPIMetadataSettings (
@@ -235,40 +250,35 @@ export default class Assess extends OmniStudioBaseCommand {
235250 assessOnly : string ,
236251 namespace : string ,
237252 conn : Connection ,
238- allVersions : boolean
253+ allVersions : boolean ,
254+ ux : Ux
239255 ) : Promise < void > {
240256 if ( ! assessOnly ) {
241257 // If no specific component is specified, assess all components
242- await this . assessDataRaptors ( assesmentInfo , namespace , conn ) ;
243- await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions ) ;
244- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS ) ;
245- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP ) ;
246- if ( ! isFoundationPackage ( ) ) {
247- await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn ) ;
248- }
258+ await this . assessDataRaptors ( assesmentInfo , namespace , conn , ux ) ;
259+ await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions , ux ) ;
260+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS , ux ) ;
261+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP , ux ) ;
262+ await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn , ux ) ;
249263 await this . assessCustomLabels ( assesmentInfo , namespace , conn ) ;
250264 return ;
251265 }
252266
253267 switch ( assessOnly ) {
254268 case Constants . DataMapper :
255- await this . assessDataRaptors ( assesmentInfo , namespace , conn ) ;
269+ await this . assessDataRaptors ( assesmentInfo , namespace , conn , ux ) ;
256270 break ;
257271 case Constants . Flexcard :
258- await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions ) ;
272+ await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions , ux ) ;
259273 break ;
260274 case Constants . Omniscript :
261- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS ) ;
275+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS , ux ) ;
262276 break ;
263277 case Constants . IntegrationProcedure :
264- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP ) ;
278+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP , ux ) ;
265279 break ;
266280 case Constants . GlobalAutoNumber :
267- if ( ! isFoundationPackage ( ) ) {
268- await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn ) ;
269- } else {
270- Logger . warn ( messages . getMessage ( 'globalAutoNumberUnSupportedInOmnistudioPackage' ) ) ;
271- }
281+ await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn , ux ) ;
272282 break ;
273283 case Constants . CustomLabel :
274284 await this . assessCustomLabels ( assesmentInfo , namespace , conn ) ;
@@ -278,8 +288,13 @@ export default class Assess extends OmniStudioBaseCommand {
278288 }
279289 }
280290
281- private async assessDataRaptors ( assesmentInfo : AssessmentInfo , namespace : string , conn : Connection ) : Promise < void > {
282- const drMigrator = new DataRaptorMigrationTool ( namespace , conn , Logger , messages , this . ux ) ;
291+ private async assessDataRaptors (
292+ assesmentInfo : AssessmentInfo ,
293+ namespace : string ,
294+ conn : Connection ,
295+ ux : Ux
296+ ) : Promise < void > {
297+ const drMigrator = new DataRaptorMigrationTool ( namespace , conn , Logger , messages , ux ) ;
283298 assesmentInfo . dataRaptorAssessmentInfos = await drMigrator . assess ( ) ;
284299 this . logAssessmentCompletionIfNeeded (
285300 'assessedDataRaptorsCount' ,
@@ -292,9 +307,10 @@ export default class Assess extends OmniStudioBaseCommand {
292307 assesmentInfo : AssessmentInfo ,
293308 namespace : string ,
294309 conn : Connection ,
295- allVersions : boolean
310+ allVersions : boolean ,
311+ ux : Ux
296312 ) : Promise < void > {
297- const flexMigrator = new CardMigrationTool ( namespace , conn , Logger , messages , this . ux , allVersions ) ;
313+ const flexMigrator = new CardMigrationTool ( namespace , conn , Logger , messages , ux , allVersions ) ;
298314 assesmentInfo . flexCardAssessmentInfos = await flexMigrator . assess ( ) ;
299315 this . logAssessmentCompletionIfNeeded (
300316 'assessedFlexCardsCount' ,
@@ -308,10 +324,11 @@ export default class Assess extends OmniStudioBaseCommand {
308324 namespace : string ,
309325 conn : Connection ,
310326 allVersions : boolean ,
311- exportType : OmniScriptExportType
327+ exportType : OmniScriptExportType ,
328+ ux : Ux
312329 ) : Promise < void > {
313330 const exportComponentType = exportType === OmniScriptExportType . IP ? 'Integration Procedures' : 'Omniscripts' ;
314- const osMigrator = new OmniScriptMigrationTool ( exportType , namespace , conn , Logger , messages , this . ux , allVersions ) ;
331+ const osMigrator = new OmniScriptMigrationTool ( exportType , namespace , conn , Logger , messages , ux , allVersions ) ;
315332 const newOmniAssessmentInfo = await osMigrator . assess (
316333 assesmentInfo . dataRaptorAssessmentInfos ,
317334 assesmentInfo . flexCardAssessmentInfos
@@ -354,13 +371,11 @@ export default class Assess extends OmniStudioBaseCommand {
354371 private async assessGlobalAutoNumbers (
355372 assesmentInfo : AssessmentInfo ,
356373 namespace : string ,
357- conn : Connection
374+ conn : Connection ,
375+ ux : Ux
358376 ) : Promise < void > {
359- if ( isFoundationPackage ( ) ) {
360- return ;
361- }
362377 Logger . logVerbose ( messages . getMessage ( 'startingGlobalAutoNumberAssessment' ) ) ;
363- const globalAutoNumberMigrationTool = new GlobalAutoNumberMigrationTool ( namespace , conn , Logger , messages , this . ux ) ;
378+ const globalAutoNumberMigrationTool = new GlobalAutoNumberMigrationTool ( namespace , conn , Logger , messages , ux ) ;
364379 assesmentInfo . globalAutoNumberAssessmentInfos = await globalAutoNumberMigrationTool . assess ( ) ;
365380 Logger . logVerbose (
366381 messages . getMessage ( 'assessedGlobalAutoNumbersCount' , [ assesmentInfo . globalAutoNumberAssessmentInfos . length ] )
0 commit comments