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' ;
@@ -20,61 +19,84 @@ import { ProjectPathUtil } from '../../../utils/projectPathUtil';
2019import { PreMigrate } from '../../../migration/premigrate' ;
2120import { PostMigrate } from '../../../migration/postMigrate' ;
2221import { CustomLabelsUtil } from '../../../utils/customLabels' ;
23- import { initializeDataModelService , isFoundationPackage , isStandardDataModel } from '../../../utils/dataModelService' ;
24-
22+ import { initializeDataModelService } from '../../../utils/dataModelService' ;
2523import { ValidatorService } from '../../../utils/validatorService' ;
2624
2725Messages . importMessagesDirectory ( __dirname ) ;
2826const messages = Messages . loadMessages ( '@salesforce/plugin-omnistudio-migration-tool' , 'assess' ) ;
2927
30- 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 > {
3137 public static description = messages . getMessage ( 'commandDescription' ) ;
3238
3339 public static examples = messages . getMessage ( 'examples' ) . split ( os . EOL ) ;
3440
35- public static args = [ { name : 'file' } ] ;
41+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
42+ public static args : any = [ ] ;
3643
37- 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+ aliases : [ 'targetusername' , 'u' ] ,
51+ deprecateAliases : true ,
52+ makeDefault : false , // Prevent auto-resolution during command-reference generation
53+ } ) ,
54+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
3855 only : flags . string ( {
3956 char : 'o' ,
4057 description : messages . getMessage ( 'onlyFlagDescription' ) ,
4158 } ) ,
59+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
4260 allversions : flags . boolean ( {
4361 char : 'a' ,
4462 description : messages . getMessage ( 'allVersionsDescription' ) ,
4563 required : false ,
4664 } ) ,
65+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
4766 relatedobjects : flags . string ( {
4867 char : 'r' ,
4968 description : messages . getMessage ( 'relatedObjectGA' ) ,
5069 } ) ,
51- verbose : flags . builtin ( {
52- type : 'builtin' ,
70+ verbose : flags . boolean ( {
5371 description : messages . getMessage ( 'enableVerboseOutput' ) ,
5472 } ) ,
5573 } ;
5674
57- // eslint-disable-next-line @typescript-eslint/no-explicit-any
58- public async run ( ) : Promise < any > {
59- Logger . initialiseLogger ( this . ux , this . logger , 'assess' , this . flags . verbose ) ;
75+ public async run ( ) : Promise < AssessmentInfo > {
76+ const { flags : parsedFlags } = await this . parse ( Assess ) ;
77+ const ux = new Ux ( { jsonEnabled : this . jsonEnabled ( ) } ) ;
78+ const logger = await CoreLogger . child ( this . constructor . name ) ;
79+ Logger . initialiseLogger ( ux , logger , 'assess' , parsedFlags . verbose ) ;
6080 try {
61- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
62- return await this . runAssess ( ) ;
81+ return await this . runAssess ( parsedFlags as AssessFlags , ux , logger ) ;
6382 } catch ( e ) {
6483 const error = e as Error ;
6584 Logger . error ( messages . getMessage ( 'errorRunningAssess' , [ error . message ] ) , error ) ;
6685 process . exit ( 1 ) ;
6786 }
6887 }
6988
70- // eslint-disable-next-line @typescript-eslint/no-explicit-any
71- public async runAssess ( ) : Promise < any > {
89+ public async runAssess ( parsedFlags : AssessFlags , ux : Ux , logger : CoreLogger ) : Promise < AssessmentInfo > {
7290 DebugTimer . getInstance ( ) . start ( ) ;
73- let allVersions = ( this . flags . allversions || false ) as boolean ;
74- const assessOnly = ( this . flags . only || '' ) as string ;
75- const relatedObjects = ( this . flags . relatedobjects || '' ) as string ;
91+ const allVersions = parsedFlags . allversions || false ;
92+ const assessOnly = parsedFlags . only || '' ;
93+ const relatedObjects = parsedFlags . relatedobjects || '' ;
7694 const isExperienceBundleMetadataAPIProgramaticallyEnabled : { value : boolean } = { value : false } ;
77- const conn = this . org . getConnection ( ) ;
95+
96+ // target-org is required by flag definition, so it will always be present
97+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
98+ const org = parsedFlags [ 'target-org' ] ! ;
99+ const conn = org . getConnection ( ) ;
78100 let objectsToProcess : string [ ] ;
79101 // To-Do: Add LWC to valid options when GA is released
80102 const validOptions = [ Constants . Apex , Constants . ExpSites , Constants . FlexiPage , Constants . LWC ] ;
@@ -94,12 +116,7 @@ export default class Assess extends OmniStudioBaseCommand {
94116
95117 const namespace = orgs . packageDetails . namespace ;
96118 let projectPath = '' ;
97- const preMigrate : PreMigrate = new PreMigrate ( namespace , conn , this . logger , messages , this . ux ) ;
98-
99- // Handle all versions prerequisite for standard data model
100- if ( isStandardDataModel ( ) ) {
101- allVersions = await preMigrate . handleAllVersionsPrerequisites ( allVersions ) ;
102- }
119+ const preMigrate : PreMigrate = new PreMigrate ( namespace , conn , logger , messages , ux ) ;
103120 if ( relatedObjects ) {
104121 objectsToProcess = relatedObjects . split ( ',' ) . map ( ( obj ) => obj . trim ( ) ) ;
105122 projectPath = await ProjectPathUtil . getProjectPath ( messages , true ) ;
@@ -135,13 +152,13 @@ export default class Assess extends OmniStudioBaseCommand {
135152
136153 Logger . log ( messages . getMessage ( 'assessmentInitialization' , [ String ( namespace ) ] ) ) ;
137154 Logger . log ( messages . getMessage ( 'apiVersionInfo' , [ String ( apiVersion ) ] ) ) ;
138- Logger . logVerbose ( messages . getMessage ( 'assessmentTargets' , [ String ( this . flags . only || 'all' ) ] ) ) ;
155+ Logger . logVerbose ( messages . getMessage ( 'assessmentTargets' , [ String ( parsedFlags . only || 'all' ) ] ) ) ;
139156 Logger . logVerbose ( messages . getMessage ( 'relatedObjectsInfo' , [ relatedObjects || 'none' ] ) ) ;
140157 Logger . logVerbose ( messages . getMessage ( 'allVersionsFlagInfo' , [ String ( allVersions ) ] ) ) ;
141158
142159 try {
143160 // Assess OmniStudio components
144- await this . assessOmniStudioComponents ( assesmentInfo , assessOnly , namespace , conn , allVersions ) ;
161+ await this . assessOmniStudioComponents ( assesmentInfo , assessOnly , namespace , conn , allVersions , ux ) ;
145162 // eslint-disable-next-line @typescript-eslint/no-explicit-any
146163 } catch ( ex : any ) {
147164 if ( ex instanceof InvalidEntityTypeError ) {
@@ -171,7 +188,7 @@ export default class Assess extends OmniStudioBaseCommand {
171188 namespace ,
172189 assessOnly ,
173190 allVersions ,
174- this . org ,
191+ org ,
175192 projectPath
176193 ) ;
177194 const relatedObjectAssessmentResult = omnistudioRelatedObjectsMigration . assessAll ( objectsToProcess ) ;
@@ -188,15 +205,7 @@ export default class Assess extends OmniStudioBaseCommand {
188205 }
189206
190207 // Post Assessment tasks
191- const postMigrate : PostMigrate = new PostMigrate (
192- this . org ,
193- namespace ,
194- conn ,
195- this . logger ,
196- messages ,
197- this . ux ,
198- objectsToProcess
199- ) ;
208+ const postMigrate : PostMigrate = new PostMigrate ( org , namespace , conn , logger , messages , ux , objectsToProcess ) ;
200209
201210 const userActionMessages : string [ ] = [ ] ;
202211 await postMigrate . restoreExperienceAPIMetadataSettings (
@@ -228,40 +237,35 @@ export default class Assess extends OmniStudioBaseCommand {
228237 assessOnly : string ,
229238 namespace : string ,
230239 conn : Connection ,
231- allVersions : boolean
240+ allVersions : boolean ,
241+ ux : Ux
232242 ) : Promise < void > {
233243 if ( ! assessOnly ) {
234244 // If no specific component is specified, assess all components
235- await this . assessDataRaptors ( assesmentInfo , namespace , conn ) ;
236- await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions ) ;
237- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS ) ;
238- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP ) ;
239- if ( ! isFoundationPackage ( ) ) {
240- await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn ) ;
241- }
245+ await this . assessDataRaptors ( assesmentInfo , namespace , conn , ux ) ;
246+ await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions , ux ) ;
247+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS , ux ) ;
248+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP , ux ) ;
249+ await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn , ux ) ;
242250 await this . assessCustomLabels ( assesmentInfo , namespace , conn ) ;
243251 return ;
244252 }
245253
246254 switch ( assessOnly ) {
247255 case Constants . DataMapper :
248- await this . assessDataRaptors ( assesmentInfo , namespace , conn ) ;
256+ await this . assessDataRaptors ( assesmentInfo , namespace , conn , ux ) ;
249257 break ;
250258 case Constants . Flexcard :
251- await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions ) ;
259+ await this . assessFlexCards ( assesmentInfo , namespace , conn , allVersions , ux ) ;
252260 break ;
253261 case Constants . Omniscript :
254- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS ) ;
262+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . OS , ux ) ;
255263 break ;
256264 case Constants . IntegrationProcedure :
257- await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP ) ;
265+ await this . assessOmniScripts ( assesmentInfo , namespace , conn , allVersions , OmniScriptExportType . IP , ux ) ;
258266 break ;
259267 case Constants . GlobalAutoNumber :
260- if ( ! isFoundationPackage ( ) ) {
261- await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn ) ;
262- } else {
263- Logger . warn ( messages . getMessage ( 'globalAutoNumberUnSupportedInOmnistudioPackage' ) ) ;
264- }
268+ await this . assessGlobalAutoNumbers ( assesmentInfo , namespace , conn , ux ) ;
265269 break ;
266270 case Constants . CustomLabel :
267271 await this . assessCustomLabels ( assesmentInfo , namespace , conn ) ;
@@ -271,8 +275,13 @@ export default class Assess extends OmniStudioBaseCommand {
271275 }
272276 }
273277
274- private async assessDataRaptors ( assesmentInfo : AssessmentInfo , namespace : string , conn : Connection ) : Promise < void > {
275- const drMigrator = new DataRaptorMigrationTool ( namespace , conn , Logger , messages , this . ux ) ;
278+ private async assessDataRaptors (
279+ assesmentInfo : AssessmentInfo ,
280+ namespace : string ,
281+ conn : Connection ,
282+ ux : Ux
283+ ) : Promise < void > {
284+ const drMigrator = new DataRaptorMigrationTool ( namespace , conn , Logger , messages , ux ) ;
276285 assesmentInfo . dataRaptorAssessmentInfos = await drMigrator . assess ( ) ;
277286 Logger . logVerbose (
278287 messages . getMessage ( 'assessedDataRaptorsCount' , [ assesmentInfo . dataRaptorAssessmentInfos . length ] )
@@ -284,9 +293,10 @@ export default class Assess extends OmniStudioBaseCommand {
284293 assesmentInfo : AssessmentInfo ,
285294 namespace : string ,
286295 conn : Connection ,
287- allVersions : boolean
296+ allVersions : boolean ,
297+ ux : Ux
288298 ) : Promise < void > {
289- const flexMigrator = new CardMigrationTool ( namespace , conn , Logger , messages , this . ux , allVersions ) ;
299+ const flexMigrator = new CardMigrationTool ( namespace , conn , Logger , messages , ux , allVersions ) ;
290300 Logger . logVerbose ( messages . getMessage ( 'flexCardAssessment' ) ) ;
291301 assesmentInfo . flexCardAssessmentInfos = await flexMigrator . assess ( ) ;
292302 Logger . logVerbose ( messages . getMessage ( 'assessedFlexCardsCount' , [ assesmentInfo . flexCardAssessmentInfos . length ] ) ) ;
@@ -298,11 +308,12 @@ export default class Assess extends OmniStudioBaseCommand {
298308 namespace : string ,
299309 conn : Connection ,
300310 allVersions : boolean ,
301- exportType : OmniScriptExportType
311+ exportType : OmniScriptExportType ,
312+ ux : Ux
302313 ) : Promise < void > {
303314 const exportComponentType = exportType === OmniScriptExportType . IP ? 'Integration Procedures' : 'Omniscripts' ;
304315 Logger . logVerbose ( messages . getMessage ( 'omniScriptAssessment' , [ exportComponentType ] ) ) ;
305- const osMigrator = new OmniScriptMigrationTool ( exportType , namespace , conn , Logger , messages , this . ux , allVersions ) ;
316+ const osMigrator = new OmniScriptMigrationTool ( exportType , namespace , conn , Logger , messages , ux , allVersions ) ;
306317 const newOmniAssessmentInfo = await osMigrator . assess (
307318 assesmentInfo . dataRaptorAssessmentInfos ,
308319 assesmentInfo . flexCardAssessmentInfos
@@ -338,13 +349,11 @@ export default class Assess extends OmniStudioBaseCommand {
338349 private async assessGlobalAutoNumbers (
339350 assesmentInfo : AssessmentInfo ,
340351 namespace : string ,
341- conn : Connection
352+ conn : Connection ,
353+ ux : Ux
342354 ) : Promise < void > {
343- if ( isFoundationPackage ( ) ) {
344- return ;
345- }
346355 Logger . logVerbose ( messages . getMessage ( 'startingGlobalAutoNumberAssessment' ) ) ;
347- const globalAutoNumberMigrationTool = new GlobalAutoNumberMigrationTool ( namespace , conn , Logger , messages , this . ux ) ;
356+ const globalAutoNumberMigrationTool = new GlobalAutoNumberMigrationTool ( namespace , conn , Logger , messages , ux ) ;
348357 assesmentInfo . globalAutoNumberAssessmentInfos = await globalAutoNumberMigrationTool . assess ( ) ;
349358 Logger . logVerbose (
350359 messages . getMessage ( 'assessedGlobalAutoNumbersCount' , [ assesmentInfo . globalAutoNumberAssessmentInfos . length ] )
0 commit comments