99 */
1010import * as os from 'os' ;
1111import { flags } from '@salesforce/command' ;
12- import { Messages } from '@salesforce/core' ;
12+ import { Connection , Messages } from '@salesforce/core' ;
1313import OmniStudioBaseCommand from '../../basecommand' ;
1414import { DataRaptorMigrationTool } from '../../../migration/dataraptor' ;
1515import { DebugTimer , MigratedObject , MigratedRecordInfo } from '../../../utils' ;
@@ -134,32 +134,19 @@ export default class Migrate extends OmniStudioBaseCommand {
134134 let targetApexNamespace : string ;
135135 const preMigrate : PreMigrate = new PreMigrate ( this . org , namespace , conn , this . logger , messages , this . ux ) ;
136136 const isExperienceBundleMetadataAPIProgramaticallyEnabled : { value : boolean } = { value : false } ;
137+
138+ let autoDeploy = false ;
137139 if ( relatedObjects ) {
138- // To-Do: Add LWC to valid options when GA is released
139- const validOptions = [ Constants . Apex , Constants . ExpSites , Constants . FlexiPage ] ;
140- objectsToProcess = relatedObjects . split ( ',' ) . map ( ( obj ) => obj . trim ( ) ) ;
141- // Validate input
142- for ( const obj of objectsToProcess ) {
143- if ( ! validOptions . includes ( obj ) ) {
144- Logger . error ( messages . getMessage ( 'invalidRelatedObjectsOption' , [ obj ] ) ) ;
145- process . exit ( 1 ) ;
146- }
147- }
148- // Check for general consent to make modifications with OMT
149- const generalConsent = await this . getGeneralConsent ( ) ;
150- if ( generalConsent ) {
151- // Use ProjectPathUtil for APEX project folder selection (matches assess.ts logic)
152- projectPath = await ProjectPathUtil . getProjectPath ( messages , true ) ;
153- targetApexNamespace = await this . getTargetApexNamespace ( objectsToProcess , targetApexNamespace ) ;
154- await preMigrate . handleExperienceSitePrerequisites (
155- objectsToProcess ,
156- conn ,
157- isExperienceBundleMetadataAPIProgramaticallyEnabled
158- ) ;
159- Logger . logVerbose (
160- 'The objects to process after handleExpSitePrerequisite are ' + JSON . stringify ( objectsToProcess )
161- ) ;
162- } // TODO - What if general consent is no
140+ const relatedObjectMigrationResult = await this . migrateRelatedObjects (
141+ relatedObjects ,
142+ preMigrate ,
143+ conn ,
144+ isExperienceBundleMetadataAPIProgramaticallyEnabled
145+ ) ;
146+ objectsToProcess = relatedObjectMigrationResult . objectsToProcess ;
147+ projectPath = relatedObjectMigrationResult . projectPath ;
148+ targetApexNamespace = relatedObjectMigrationResult . targetApexNamespace ;
149+ autoDeploy = relatedObjectMigrationResult . autoDeploy ;
163150 }
164151
165152 Logger . log ( messages . getMessage ( 'migrationInitialization' , [ String ( namespace ) ] ) ) ;
@@ -204,9 +191,17 @@ export default class Migrate extends OmniStudioBaseCommand {
204191 this . logger ,
205192 messages ,
206193 this . ux ,
207- objectsToProcess
194+ objectsToProcess ,
195+ autoDeploy ,
196+ projectPath
208197 ) ;
209198
199+ try {
200+ postMigrate . deploy ( ) ;
201+ } catch ( error ) {
202+ Logger . error ( messages . getMessage ( 'errorDeployingComponents' ) , error ) ;
203+ }
204+
210205 if ( ! migrateOnly ) {
211206 await postMigrate . setDesignersToUseStandardDataModel ( namespace , actionItems ) ;
212207 }
@@ -223,7 +218,8 @@ export default class Migrate extends OmniStudioBaseCommand {
223218 relatedObjectMigrationResult . apexAssessmentInfos ,
224219 relatedObjectMigrationResult . lwcAssessmentInfos ,
225220 relatedObjectMigrationResult . experienceSiteAssessmentInfos ,
226- relatedObjectMigrationResult . flexipageAssessmentInfos
221+ relatedObjectMigrationResult . flexipageAssessmentInfos ,
222+ this . org . getConnection ( ) . version
227223 ) ;
228224
229225 await ResultsBuilder . generateReport (
@@ -237,7 +233,73 @@ export default class Migrate extends OmniStudioBaseCommand {
237233 ) ;
238234
239235 // Return results needed for --json flag
240- return { objectMigrationResults } ;
236+ return { objectMigrationResults : [ ] } ;
237+ }
238+
239+ private async migrateRelatedObjects (
240+ relatedObjects : string ,
241+ preMigrate : PreMigrate ,
242+ conn : Connection ,
243+ isExperienceBundleMetadataAPIProgramaticallyEnabled : { value : boolean }
244+ ) : Promise < { objectsToProcess : string [ ] ; projectPath : string ; targetApexNamespace : string ; autoDeploy : boolean } > {
245+ const validOptions = [ Constants . Apex , Constants . ExpSites , Constants . FlexiPage ] ;
246+ const objectsToProcess = relatedObjects . split ( ',' ) . map ( ( obj ) => obj . trim ( ) ) ;
247+ // Validate input
248+ for ( const obj of objectsToProcess ) {
249+ if ( ! validOptions . includes ( obj ) ) {
250+ Logger . error ( messages . getMessage ( 'invalidRelatedObjectsOption' , [ obj ] ) ) ;
251+ process . exit ( 1 ) ;
252+ }
253+ }
254+
255+ const autoDeploy = await this . getAutoDeployConsent ( ) ;
256+ let projectPath : string ;
257+ let targetApexNamespace : string ;
258+ // Check for general consent to make modifications with OMT
259+ const generalConsent = await this . getGeneralConsent ( ) ;
260+ if ( generalConsent ) {
261+ // Use ProjectPathUtil for APEX project folder selection (matches assess.ts logic)
262+ projectPath = await ProjectPathUtil . getProjectPath ( messages , true ) ;
263+ targetApexNamespace = await this . getTargetApexNamespace ( objectsToProcess , targetApexNamespace ) ;
264+ await preMigrate . handleExperienceSitePrerequisites (
265+ objectsToProcess ,
266+ conn ,
267+ isExperienceBundleMetadataAPIProgramaticallyEnabled
268+ ) ;
269+ Logger . logVerbose (
270+ 'The objects to process after handleExpSitePrerequisite are ' + JSON . stringify ( objectsToProcess )
271+ ) ;
272+ }
273+
274+ return { objectsToProcess, projectPath, targetApexNamespace, autoDeploy } ;
275+ }
276+
277+ private async getAutoDeployConsent ( ) : Promise < boolean > {
278+ const askWithTimeOut = PromptUtil . askWithTimeOut ( messages ) ;
279+ let validResponse = false ;
280+ let consent = false ;
281+
282+ while ( ! validResponse ) {
283+ try {
284+ const resp = await askWithTimeOut ( Logger . prompt . bind ( Logger ) , messages . getMessage ( 'autoDeployConsentMessage' ) ) ;
285+ const response = typeof resp === 'string' ? resp . trim ( ) . toLowerCase ( ) : '' ;
286+
287+ if ( response === YES_SHORT || response === YES_LONG ) {
288+ consent = true ;
289+ validResponse = true ;
290+ } else if ( response === NO_SHORT || response === NO_LONG ) {
291+ consent = false ;
292+ validResponse = true ;
293+ } else {
294+ Logger . error ( messages . getMessage ( 'invalidYesNoResponse' ) ) ;
295+ }
296+ } catch ( err ) {
297+ Logger . error ( messages . getMessage ( 'requestTimedOut' ) ) ;
298+ process . exit ( 1 ) ;
299+ }
300+ }
301+
302+ return consent ;
241303 }
242304
243305 private async getMigrationConsent ( ) : Promise < boolean > {
0 commit comments