88 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
99 */
1010import * as os from 'os' ;
11+ import * as fs from 'fs' ;
1112import { flags } from '@salesforce/command' ;
1213import { Messages } from '@salesforce/core' ;
1314import '../../../utils/prototypes' ;
@@ -72,13 +73,12 @@ export default class Migrate extends OmniStudioBaseCommand {
7273
7374 // Let's time every step
7475 DebugTimer . getInstance ( ) . start ( ) ;
75- // const includeApex = this.flags.apex
76- // ? await this.ux.confirm('Do you want to include Apex migration? (yes/no)')
77- // : false;
78-
76+ let projectPath : string ;
77+ let objectsToProcess : string [ ] ;
78+ let targetApexNamespace : string ;
7979 if ( relatedObjects ) {
8080 const validOptions = [ 'apex' , 'lwc' ] ;
81- const objectsToProcess = relatedObjects . split ( ',' ) . map ( ( obj ) => obj . trim ( ) ) ;
81+ objectsToProcess = relatedObjects . split ( ',' ) . map ( ( obj ) => obj . trim ( ) ) ;
8282 // Validate input
8383 for ( const obj of objectsToProcess ) {
8484 if ( ! validOptions . includes ( obj ) ) {
@@ -87,72 +87,20 @@ export default class Migrate extends OmniStudioBaseCommand {
8787 }
8888 // Ask for user consent
8989 const consent = await this . ux . confirm (
90- 'By proceeding further, you hereby consent to the use, accept changes to your custom code, and the accompanying terms and conditions associated with the use of the OmniStudio Migration Tool. Do you want to proceed?'
90+ 'By proceeding further, you hereby consent to the use, accept changes to your custom code, and the accompanying terms and conditions associated with the use of the OmniStudio Migration Tool. Do you want to proceed? [y/n] '
9191 ) ;
9292 if ( ! consent ) {
93- this . ux . log ( ' User declined consent. Aborting the process.' ) ;
93+ this . ux . error ( ` User declined consent, will not process ${ relatedObjects } .` ) ;
9494 } else {
95- const projectPath = await this . ux . prompt ( 'Enter the project path for processing:' ) ;
96- this . ux . log ( `Using project path: ${ projectPath } ` ) ;
97- OmnistudioRelatedObjectMigrationFacade . intializeProject ( projectPath ) ;
95+ projectPath = await this . getProjectPath ( relatedObjects , projectPath ) ;
96+ targetApexNamespace = await this . getTargetApexNamespace ( objectsToProcess , targetApexNamespace ) ;
9897 }
9998 }
10099
101100 // const includeLwc = this.flags.lwc ? await this.ux.confirm('Do you want to include LWC migration? (yes/no)') : false;
102101 // Register the migration objects
103102 let migrationObjects : MigrationTool [ ] = [ ] ;
104- if ( ! migrateOnly ) {
105- migrationObjects = [
106- new DataRaptorMigrationTool ( namespace , conn , this . logger , messages , this . ux ) ,
107- new OmniScriptMigrationTool (
108- OmniScriptExportType . All ,
109- namespace ,
110- conn ,
111- this . logger ,
112- messages ,
113- this . ux ,
114- allVersions
115- ) ,
116- new CardMigrationTool ( namespace , conn , this . logger , messages , this . ux , allVersions ) ,
117- ] ;
118- } else {
119- switch ( migrateOnly ) {
120- case 'os' :
121- migrationObjects . push (
122- new OmniScriptMigrationTool (
123- OmniScriptExportType . OS ,
124- namespace ,
125- conn ,
126- this . logger ,
127- messages ,
128- this . ux ,
129- allVersions
130- )
131- ) ;
132- break ;
133- case 'ip' :
134- migrationObjects . push (
135- new OmniScriptMigrationTool (
136- OmniScriptExportType . IP ,
137- namespace ,
138- conn ,
139- this . logger ,
140- messages ,
141- this . ux ,
142- allVersions
143- )
144- ) ;
145- break ;
146- case 'fc' :
147- migrationObjects . push ( new CardMigrationTool ( namespace , conn , this . logger , messages , this . ux , allVersions ) ) ;
148- break ;
149- case 'dr' :
150- migrationObjects . push ( new DataRaptorMigrationTool ( namespace , conn , this . logger , messages , this . ux ) ) ;
151- break ;
152- default :
153- throw new Error ( messages . getMessage ( 'invalidOnlyFlag' ) ) ;
154- }
155- }
103+ migrationObjects = this . getMigrationObjects ( migrateOnly , migrationObjects , namespace , conn , allVersions ) ;
156104 // Migrate individual objects
157105 const debugTimer = DebugTimer . getInstance ( ) ;
158106 let objectMigrationResults : MigratedObject [ ] = [ ] ;
@@ -206,10 +154,12 @@ export default class Migrate extends OmniStudioBaseCommand {
206154 allVersions ,
207155 this . org
208156 ) ;
209- const relatedObjectMigrationResult = omnistudioRelatedObjectsMigration . migrateAll ( objectMigrationResults , [
210- 'lwc' ,
211- 'apex' ,
212- ] ) ;
157+ const relatedObjectMigrationResult = omnistudioRelatedObjectsMigration . migrateAll (
158+ objectMigrationResults ,
159+ objectsToProcess ,
160+ projectPath ,
161+ targetApexNamespace
162+ ) ;
213163 generatePackageXml . createChangeList (
214164 relatedObjectMigrationResult . apexAssessmentInfos ,
215165 relatedObjectMigrationResult . lwcAssessmentInfos
@@ -223,6 +173,93 @@ export default class Migrate extends OmniStudioBaseCommand {
223173 return { objectMigrationResults } ;
224174 }
225175
176+ private getMigrationObjects (
177+ migrateOnly : string ,
178+ migrationObjects : MigrationTool [ ] ,
179+ namespace : string ,
180+ conn ,
181+ allVersions : any
182+ ) : MigrationTool [ ] {
183+ if ( ! migrateOnly ) {
184+ migrationObjects = [
185+ new DataRaptorMigrationTool ( namespace , conn , this . logger , messages , this . ux ) ,
186+ new OmniScriptMigrationTool (
187+ OmniScriptExportType . All ,
188+ namespace ,
189+ conn ,
190+ this . logger ,
191+ messages ,
192+ this . ux ,
193+ allVersions
194+ ) ,
195+ new CardMigrationTool ( namespace , conn , this . logger , messages , this . ux , allVersions ) ,
196+ ] ;
197+ } else {
198+ switch ( migrateOnly ) {
199+ case 'os' :
200+ migrationObjects . push (
201+ new OmniScriptMigrationTool (
202+ OmniScriptExportType . OS ,
203+ namespace ,
204+ conn ,
205+ this . logger ,
206+ messages ,
207+ this . ux ,
208+ allVersions
209+ )
210+ ) ;
211+ break ;
212+ case 'ip' :
213+ migrationObjects . push (
214+ new OmniScriptMigrationTool (
215+ OmniScriptExportType . IP ,
216+ namespace ,
217+ conn ,
218+ this . logger ,
219+ messages ,
220+ this . ux ,
221+ allVersions
222+ )
223+ ) ;
224+ break ;
225+ case 'fc' :
226+ migrationObjects . push ( new CardMigrationTool ( namespace , conn , this . logger , messages , this . ux , allVersions ) ) ;
227+ break ;
228+ case 'dr' :
229+ migrationObjects . push ( new DataRaptorMigrationTool ( namespace , conn , this . logger , messages , this . ux ) ) ;
230+ break ;
231+ default :
232+ throw new Error ( messages . getMessage ( 'invalidOnlyFlag' ) ) ;
233+ }
234+ }
235+ return migrationObjects ;
236+ }
237+
238+ private async getProjectPath ( relatedObjects : string , projectPath : string ) : Promise < string > {
239+ const projectPathConfirmation = await this . ux
240+ . confirm ( `Do you have a sfdc project where ${ relatedObjects } files are already retrieved from org - y
241+ or you want tool to create a project omnistudio_migration in current directory for processing - n ? [y/n]` ) ;
242+ if ( projectPathConfirmation ) {
243+ projectPath = await this . ux . prompt ( `Enter the project path for processing ${ relatedObjects } :` ) ;
244+ const projectJsonFile = 'sfdx-project.json' ;
245+ if ( ! fs . existsSync ( projectPath + '/' + projectJsonFile ) ) {
246+ throw new Error ( `Could not find any ${ projectJsonFile } in ${ projectPath } .` ) ;
247+ }
248+ this . ux . log ( `Using project path: ${ projectPath } ` ) ;
249+ }
250+ return projectPath ;
251+ }
252+
253+ private async getTargetApexNamespace ( objectsToProcess : string [ ] , targetApexNamespace : string ) : Promise < string > {
254+ if ( objectsToProcess . includes ( 'apex' ) ) {
255+ targetApexNamespace = await this . ux . prompt (
256+ 'Enter the target namespace to be used for calling package Apex classes'
257+ ) ;
258+ this . ux . log ( `Using target namespace: ${ targetApexNamespace } for calling package Apex classes` ) ;
259+ }
260+ return targetApexNamespace ;
261+ }
262+
226263 private mergeRecordAndUploadResults (
227264 migrationResults : MigrationResult ,
228265 migrationTool : MigrationTool
0 commit comments