Skip to content

Commit cb5ae1d

Browse files
fix: review comments
1 parent ec30239 commit cb5ae1d

File tree

3 files changed

+29
-62
lines changed

3 files changed

+29
-62
lines changed

messages/assess.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
"allVersionsDescription": "Migrate all versions of a component",
3030
"changeMessage": " %s will be changed from %s to %s",
3131
"angularOSWarning": " Angular OmniScript will not be migrated, please convert this to LWC based Omniscript",
32-
"apexLwc": "Please select the type of components to migrate: 'apex' for Apex classes, 'lwc' for Lightning Web Components, or 'apex,lwc' if you want to include both types."
32+
"apexLwc": "Please select the type of components to assess: 'apex' for Apex classes, 'lwc' for Lightning Web Components, or 'apex,lwc' if you want to include both types."
3333
}

src/commands/omnistudio/migration/migrate.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,11 @@ export default class Migrate extends OmniStudioBaseCommand {
165165
namespace,
166166
migrateOnly,
167167
allVersions,
168-
this.org
168+
this.org,
169+
projectPath
169170
);
170171
const relatedObjectMigrationResult = omnistudioRelatedObjectsMigration.migrateAll(
171-
objectMigrationResults,
172172
objectsToProcess,
173-
projectPath,
174173
targetApexNamespace
175174
);
176175
generatePackageXml.createChangeList(

src/migration/related/OmnistudioRelatedObjectMigrationFacade.ts

Lines changed: 26 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
/* eslint-disable @typescript-eslint/no-explicit-any */
55
import { Org } from '@salesforce/core';
66
import * as shell from 'shelljs';
7-
import {
8-
ApexAssessmentInfo,
9-
DebugTimer,
10-
LWCAssessmentInfo,
11-
MigratedObject,
12-
RelatedObjectAssesmentInfo,
13-
} from '../../utils';
7+
import { ApexAssessmentInfo, DebugTimer, LWCAssessmentInfo, RelatedObjectAssesmentInfo } from '../../utils';
148
import { sfProject } from '../../utils/sfcli/project/sfProject';
159
import { Logger } from '../../utils/logger';
1610
import { ApexMigration } from './ApexMigration';
@@ -35,58 +29,45 @@ export default class OmnistudioRelatedObjectMigrationFacade {
3529
protected readonly only: string;
3630
protected readonly allversions: boolean;
3731
protected readonly org: Org;
32+
protected readonly projectPath: string;
3833

39-
public constructor(namespace: string, only: string, allversions: boolean, org: Org) {
34+
public constructor(namespace: string, only: string, allversions: boolean, org: Org, projectPath?: string) {
4035
this.namespace = namespace;
4136
this.only = only;
4237
this.allversions = allversions;
4338
this.org = org;
39+
this.projectPath = projectPath || this.createProject();
4440
}
45-
public static intializeProject(projectPath?: string): string {
46-
if (projectPath) {
47-
// sfProject.create(defaultProjectName, projectPath);
48-
return projectPath;
49-
} else {
50-
sfProject.create(defaultProjectName);
51-
return process.cwd() + '/' + defaultProjectName;
52-
}
41+
42+
private createProject(): string {
43+
sfProject.create(defaultProjectName);
44+
return process.cwd() + '/' + defaultProjectName;
5345
}
54-
public intializeProjectWithRetrieve(relatedObjects: string[], projectPath?: string): string {
55-
if (projectPath) {
56-
// sfProject.create(defaultProjectName, projectPath);
57-
return projectPath;
58-
} else {
59-
sfProject.create(defaultProjectName);
60-
projectPath = process.cwd() + '/' + defaultProjectName;
61-
const pwd = shell.pwd();
62-
shell.cd(projectPath);
63-
if (relatedObjects.includes('lwc')) {
64-
sfProject.retrieve(LWCTYPE, this.org.getUsername());
65-
}
66-
if (relatedObjects.includes('apex')) {
67-
sfProject.retrieve(APEXCLASS, this.org.getUsername());
68-
}
69-
shell.cd(pwd);
46+
47+
private retrieveMetadata(relatedObjects: string[]): void {
48+
const pwd = shell.pwd();
49+
shell.cd(this.projectPath);
50+
if (relatedObjects.includes('lwc')) {
51+
sfProject.retrieve(LWCTYPE, this.org.getUsername());
7052
}
71-
return projectPath;
53+
if (relatedObjects.includes('apex')) {
54+
sfProject.retrieve(APEXCLASS, this.org.getUsername());
55+
}
56+
shell.cd(pwd);
7257
}
7358

74-
public migrateAll(
75-
migrationResult: MigratedObject[],
76-
relatedObjects: string[],
77-
projectPath?: string,
78-
targetApexNamespace?: string
79-
): RelatedObjectAssesmentInfo {
59+
public migrateAll(relatedObjects: string[], targetApexNamespace?: string): RelatedObjectAssesmentInfo {
8060
// Start the debug timer
8161
DebugTimer.getInstance().start();
8262

83-
// Declare an array of MigrationTool
84-
const projectDirectory: string = this.intializeProjectWithRetrieve(relatedObjects, projectPath);
63+
// Retrieve metadata if needed
64+
this.retrieveMetadata(relatedObjects);
65+
8566
const debugTimer = DebugTimer.getInstance();
8667
debugTimer.start();
8768
// Initialize migration tools based on the relatedObjects parameter
88-
const apexMigrator = this.createApexClassMigrationTool(projectDirectory, targetApexNamespace);
89-
const lwcMigrator = this.createLWCComponentMigrationTool(this.namespace, projectDirectory);
69+
const apexMigrator = new ApexMigration(this.projectPath, this.namespace, this.org, targetApexNamespace);
70+
const lwcMigrator = new LwcMigration(this.projectPath, this.namespace, this.org);
9071
let apexAssessmentInfos: ApexAssessmentInfo[] = [];
9172
let lwcAssessmentInfos: LWCAssessmentInfo[] = [];
9273
// Proceed with migration logic
@@ -121,8 +102,6 @@ export default class OmnistudioRelatedObjectMigrationFacade {
121102
// Start the debug timer
122103
DebugTimer.getInstance().start();
123104

124-
// Declare an array of MigrationTool
125-
const projectDirectory: string = OmnistudioRelatedObjectMigrationFacade.intializeProject();
126105
const debugTimer = DebugTimer.getInstance();
127106
debugTimer.start();
128107

@@ -132,7 +111,7 @@ export default class OmnistudioRelatedObjectMigrationFacade {
132111
// Proceed with assessment logic
133112
try {
134113
if (relatedObjects.includes('apex')) {
135-
const apexMigrator = new ApexMigration(projectDirectory, this.namespace, this.org);
114+
const apexMigrator = new ApexMigration(this.projectPath, this.namespace, this.org);
136115
apexAssessmentInfos = apexMigrator.assess();
137116
}
138117
} catch (Error) {
@@ -141,7 +120,7 @@ export default class OmnistudioRelatedObjectMigrationFacade {
141120
}
142121
try {
143122
if (relatedObjects.includes('lwc')) {
144-
const lwcparser = new LwcMigration(projectDirectory, this.namespace, this.org);
123+
const lwcparser = new LwcMigration(this.projectPath, this.namespace, this.org);
145124
lwcAssessmentInfos = lwcparser.assessment();
146125
}
147126
} catch (Error) {
@@ -158,15 +137,4 @@ export default class OmnistudioRelatedObjectMigrationFacade {
158137
// Return results needed for --json flag
159138
return { apexAssessmentInfos, lwcAssessmentInfos };
160139
}
161-
162-
// Factory methods to create instances of specific tools
163-
private createLWCComponentMigrationTool(namespace: string, projectPath: string): LwcMigration {
164-
// Return an instance of LWCComponentMigrationTool when implemented
165-
return new LwcMigration(projectPath, this.namespace, this.org);
166-
}
167-
168-
private createApexClassMigrationTool(projectPath: string, targetApexNamespace?: string): ApexMigration {
169-
// Return an instance of ApexClassMigrationTool when implemented
170-
return new ApexMigration(projectPath, this.namespace, this.org, targetApexNamespace);
171-
}
172140
}

0 commit comments

Comments
 (0)