Skip to content

Commit 7def135

Browse files
committed
feat: adds partial deployment if authKeydoesn't exist
1 parent 1503e0f commit 7def135

File tree

7 files changed

+68
-95
lines changed

7 files changed

+68
-95
lines changed

messages/migrate.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,14 @@
199199
"errorCheckingGlobalAutoNumber": "We couldn’t check whether the Global Auto Number setting is enabled: %s. Try again later.",
200200
"errorMigrationMessage": "Error migrating object: %s",
201201
"nameMappingUndefined": "Name Mapping is undefined",
202-
"autoDeployConsentMessage": "Do you want to auto deploy the migrated components? [y/n]",
203-
"errorDeployingComponents": "Error deploying components post migration",
202+
"autoDeployConsentMessage": "Do you want to auto deploy the related objects? [y/n]",
203+
"errorDeployingComponents": "Error deploying related objects post migration",
204204
"installingDependency": "Installing node dependency %s",
205205
"dependencyInstalled": "Node dependency %s installed",
206206
"deployingFromManifest": "Deploying from metadata packages",
207207
"manifestDeployed": "Metadata packages are deployed",
208208
"installingRequiredDependencies": "Installing required node dependencies",
209209
"creatingNPMConfigFile": "Creating npm config file",
210-
"npmConfigFileCreated": "Npm config file created"
210+
"npmConfigFileCreated": "Npm config file created",
211+
"authKeyEnvVarNotSet": "OMA_AUTH_KEY environment variable is not set, LWCs will not be deployed"
211212
}

src/commands/omnistudio/migration/assess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export default class Assess extends OmniStudioBaseCommand {
177177
messages,
178178
this.ux,
179179
objectsToProcess,
180-
false,
180+
undefined,
181181
undefined
182182
);
183183

src/commands/omnistudio/migration/migrate.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import { GlobalAutoNumberMigrationTool } from '../../../migration/globalautonumb
3333
// Initialize Messages with the current plugin directory
3434
Messages.importMessagesDirectory(__dirname);
3535

36+
const authEnvKey = 'OMA_AUTH_KEY';
37+
3638
// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
3739
// or any library that is using the messages framework can also be loaded this way.
3840
const messages = Messages.loadMessages('@salesforce/plugin-omnistudio-migration-tool', 'migrate');
@@ -135,7 +137,7 @@ export default class Migrate extends OmniStudioBaseCommand {
135137
const preMigrate: PreMigrate = new PreMigrate(this.org, namespace, conn, this.logger, messages, this.ux);
136138
const isExperienceBundleMetadataAPIProgramaticallyEnabled: { value: boolean } = { value: false };
137139

138-
let autoDeploy = false;
140+
let deploymentConfig = { autoDeploy: false, authKey: undefined };
139141
if (relatedObjects) {
140142
const relatedObjectMigrationResult = await this.migrateRelatedObjects(
141143
relatedObjects,
@@ -146,7 +148,7 @@ export default class Migrate extends OmniStudioBaseCommand {
146148
objectsToProcess = relatedObjectMigrationResult.objectsToProcess;
147149
projectPath = relatedObjectMigrationResult.projectPath;
148150
targetApexNamespace = relatedObjectMigrationResult.targetApexNamespace;
149-
autoDeploy = relatedObjectMigrationResult.autoDeploy;
151+
deploymentConfig = relatedObjectMigrationResult.deploymentConfig;
150152
}
151153

152154
Logger.log(messages.getMessage('migrationInitialization', [String(namespace)]));
@@ -192,16 +194,10 @@ export default class Migrate extends OmniStudioBaseCommand {
192194
messages,
193195
this.ux,
194196
objectsToProcess,
195-
autoDeploy,
197+
deploymentConfig,
196198
projectPath
197199
);
198200

199-
try {
200-
postMigrate.deploy();
201-
} catch (error) {
202-
Logger.error(messages.getMessage('errorDeployingComponents'), error);
203-
}
204-
205201
if (!migrateOnly) {
206202
await postMigrate.setDesignersToUseStandardDataModel(namespace, actionItems);
207203
}
@@ -216,12 +212,18 @@ export default class Migrate extends OmniStudioBaseCommand {
216212

217213
generatePackageXml.createChangeList(
218214
relatedObjectMigrationResult.apexAssessmentInfos,
219-
relatedObjectMigrationResult.lwcAssessmentInfos,
215+
deploymentConfig.autoDeploy && deploymentConfig.authKey ? relatedObjectMigrationResult.lwcAssessmentInfos : [],
220216
relatedObjectMigrationResult.experienceSiteAssessmentInfos,
221217
relatedObjectMigrationResult.flexipageAssessmentInfos,
222218
this.org.getConnection().version
223219
);
224220

221+
try {
222+
postMigrate.deploy();
223+
} catch (error) {
224+
Logger.error(messages.getMessage('errorDeployingComponents'), error);
225+
}
226+
225227
await ResultsBuilder.generateReport(
226228
objectMigrationResults,
227229
relatedObjectMigrationResult,
@@ -241,7 +243,12 @@ export default class Migrate extends OmniStudioBaseCommand {
241243
preMigrate: PreMigrate,
242244
conn: Connection,
243245
isExperienceBundleMetadataAPIProgramaticallyEnabled: { value: boolean }
244-
): Promise<{ objectsToProcess: string[]; projectPath: string; targetApexNamespace: string; autoDeploy: boolean }> {
246+
): Promise<{
247+
objectsToProcess: string[];
248+
projectPath: string;
249+
targetApexNamespace: string;
250+
deploymentConfig: { autoDeploy: boolean; authKey: string | undefined };
251+
}> {
245252
const validOptions = [Constants.Apex, Constants.ExpSites, Constants.FlexiPage];
246253
const objectsToProcess = relatedObjects.split(',').map((obj) => obj.trim());
247254
// Validate input
@@ -252,7 +259,7 @@ export default class Migrate extends OmniStudioBaseCommand {
252259
}
253260
}
254261

255-
const autoDeploy = await this.getAutoDeployConsent();
262+
const deploymentConfig = await this.getAutoDeployConsent();
256263
let projectPath: string;
257264
let targetApexNamespace: string;
258265
// Check for general consent to make modifications with OMT
@@ -271,10 +278,10 @@ export default class Migrate extends OmniStudioBaseCommand {
271278
);
272279
}
273280

274-
return { objectsToProcess, projectPath, targetApexNamespace, autoDeploy };
281+
return { objectsToProcess, projectPath, targetApexNamespace, deploymentConfig };
275282
}
276283

277-
private async getAutoDeployConsent(): Promise<boolean> {
284+
private async getAutoDeployConsent(): Promise<{ autoDeploy: boolean; authKey: string | undefined }> {
278285
const askWithTimeOut = PromptUtil.askWithTimeOut(messages);
279286
let validResponse = false;
280287
let consent = false;
@@ -299,7 +306,18 @@ export default class Migrate extends OmniStudioBaseCommand {
299306
}
300307
}
301308

302-
return consent;
309+
const deploymentConfig = {
310+
autoDeploy: consent,
311+
authKey: undefined,
312+
};
313+
if (consent) {
314+
deploymentConfig.authKey = process.env[authEnvKey];
315+
if (!deploymentConfig.authKey) {
316+
Logger.error(messages.getMessage('authKeyEnvVarNotSet'));
317+
}
318+
}
319+
320+
return deploymentConfig;
303321
}
304322

305323
private async getMigrationConsent(): Promise<boolean> {

src/migration/deployer.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,26 @@ import { Logger } from '../utils/logger';
66

77
export class Deployer {
88
private readonly projectPath: string;
9-
private readonly authEnvKey = 'OMA_AUTH_KEY';
109
private readonly authKey: string;
1110
private readonly requiredNodeDependency = '@omnistudio/[email protected]';
1211
private readonly username: string;
1312
private readonly messages: Messages;
1413

15-
public constructor(projectPath: string, messages: Messages, username: string) {
14+
public constructor(projectPath: string, messages: Messages, username: string, authKey: string) {
1615
this.projectPath = projectPath;
1716
this.username = username;
18-
this.authKey = process.env[this.authEnvKey];
1917
this.messages = messages;
20-
21-
if (!this.authKey) {
22-
throw new Error(`${this.authEnvKey} environment variable is not set`);
23-
}
18+
this.authKey = authKey;
2419
}
2520

2621
public deploy(): void {
2722
shell.cd(this.projectPath);
28-
sfProject.createNPMConfigFile(this.authKey);
29-
Logger.logVerbose(this.messages.getMessage('installingRequiredDependencies'));
30-
sfProject.installDependency();
31-
sfProject.installDependency(this.requiredNodeDependency);
23+
if (this.authKey) {
24+
sfProject.createNPMConfigFile(this.authKey);
25+
Logger.logVerbose(this.messages.getMessage('installingRequiredDependencies'));
26+
sfProject.installDependency();
27+
sfProject.installDependency(this.requiredNodeDependency);
28+
}
3229
sfProject.deployFromManifest(path.join(process.cwd(), 'package.xml'), this.username);
3330
}
3431
}

src/migration/postMigrate.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class PostMigrate extends BaseMigrationTool {
1414
private readonly org: Org;
1515
private readonly relatedObjectsToProcess: string[];
1616
private readonly projectPath: string;
17-
private readonly autoDeploy: boolean;
17+
private readonly deploymentConfig: { autoDeploy: boolean; authKey: string | undefined };
1818

1919
// Source Custom Object Names
2020
constructor(
@@ -25,13 +25,13 @@ export class PostMigrate extends BaseMigrationTool {
2525
messages: Messages,
2626
ux: UX,
2727
relatedObjectsToProcess: string[],
28-
autoDeploy: boolean,
28+
deploymentConfig: { autoDeploy: boolean; authKey: string | undefined },
2929
projectPath: string
3030
) {
3131
super(namespace, connection, logger, messages, ux);
3232
this.org = org;
3333
this.relatedObjectsToProcess = relatedObjectsToProcess;
34-
this.autoDeploy = autoDeploy;
34+
this.deploymentConfig = deploymentConfig;
3535
this.projectPath = projectPath;
3636
}
3737

@@ -86,11 +86,16 @@ export class PostMigrate extends BaseMigrationTool {
8686
}
8787

8888
public deploy(): void {
89-
if (!this.autoDeploy) {
89+
if (!this.deploymentConfig.autoDeploy) {
9090
return;
9191
}
9292
try {
93-
const deployer = new Deployer(this.projectPath, this.messages, this.org.getUsername());
93+
const deployer = new Deployer(
94+
this.projectPath,
95+
this.messages,
96+
this.org.getUsername(),
97+
this.deploymentConfig.authKey
98+
);
9499
deployer.deploy();
95100
} catch (error) {
96101
Logger.error(this.messages.getMessage('errorDeployingComponents'), error);

test/migration/deployer.test.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Deployer', () => {
4444
sandbox.stub(sfProject, 'installDependency');
4545
sandbox.stub(sfProject, 'deployFromManifest');
4646

47-
deployer = new Deployer(testProjectPath, messages, testUsername);
47+
deployer = new Deployer(testProjectPath, messages, testUsername, testAuthKey);
4848
});
4949

5050
afterEach(() => {
@@ -62,24 +62,6 @@ describe('Deployer', () => {
6262
expect((deployer as any).messages).to.equal(messages);
6363
expect((deployer as any).requiredNodeDependency).to.equal('@omnistudio/[email protected]');
6464
});
65-
66-
it('should throw error when OMA_AUTH_KEY environment variable is not set', () => {
67-
// Remove the environment variable
68-
delete process.env.OMA_AUTH_KEY;
69-
70-
expect(() => {
71-
new Deployer(testProjectPath, messages, testUsername);
72-
}).to.throw('OMA_AUTH_KEY environment variable is not set');
73-
});
74-
75-
it('should throw error when OMA_AUTH_KEY environment variable is empty', () => {
76-
// Set empty environment variable
77-
Object.assign(process.env, { OMA_AUTH_KEY: '' });
78-
79-
expect(() => {
80-
new Deployer(testProjectPath, messages, testUsername);
81-
}).to.throw('OMA_AUTH_KEY environment variable is not set');
82-
});
8365
});
8466

8567
describe('deploy', () => {
@@ -152,10 +134,6 @@ describe('Deployer', () => {
152134
});
153135

154136
describe('private properties', () => {
155-
it('should have correct authEnvKey', () => {
156-
expect((deployer as any).authEnvKey).to.equal('OMA_AUTH_KEY');
157-
});
158-
159137
it('should have correct requiredNodeDependency', () => {
160138
expect((deployer as any).requiredNodeDependency).to.equal('@omnistudio/[email protected]');
161139
});

test/migration/postMigrate.test.ts

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ describe('PostMigrate', () => {
2929
const testRelatedObjectsToProcess = ['Flexipage', 'expsites'];
3030
const testProjectPath = '/test/project/path';
3131
const testUsername = '[email protected]';
32+
const testAuthKey = 'test-auth-key';
3233

3334
beforeEach(() => {
3435
sandbox = sinon.createSandbox();
3536

3637
// Set up environment variable for Deployer
37-
process.env.OMA_AUTH_KEY = 'test-auth-key';
38+
process.env.OMA_AUTH_KEY = testAuthKey;
3839

3940
// Mock org
4041
org = {
@@ -103,7 +104,7 @@ describe('PostMigrate', () => {
103104
messages,
104105
ux,
105106
testRelatedObjectsToProcess,
106-
true,
107+
{ autoDeploy: true, authKey: testAuthKey },
107108
testProjectPath
108109
);
109110
});
@@ -119,7 +120,8 @@ describe('PostMigrate', () => {
119120
expect((postMigrate as any).org).to.equal(org);
120121
expect((postMigrate as any).relatedObjectsToProcess).to.deep.equal(testRelatedObjectsToProcess);
121122
expect((postMigrate as any).projectPath).to.equal(testProjectPath);
122-
expect((postMigrate as any).autoDeploy).to.be.true;
123+
expect((postMigrate as any).deploymentConfig.autoDeploy).to.be.true;
124+
expect((postMigrate as any).deploymentConfig.authKey).to.equal(testAuthKey);
123125
expect((postMigrate as any).namespace).to.equal(testNamespace);
124126
expect((postMigrate as any).connection).to.equal(connection);
125127
expect((postMigrate as any).logger).to.equal(logger);
@@ -128,35 +130,6 @@ describe('PostMigrate', () => {
128130
});
129131

130132
it('should initialize with autoDeploy set to false', () => {
131-
const postMigrateNoDeploy = new PostMigrate(
132-
org,
133-
testNamespace,
134-
connection,
135-
logger,
136-
messages,
137-
ux,
138-
testRelatedObjectsToProcess,
139-
false,
140-
testProjectPath
141-
);
142-
143-
expect((postMigrateNoDeploy as any).autoDeploy).to.be.false;
144-
});
145-
});
146-
147-
describe('deploy', () => {
148-
it('should deploy when autoDeploy is true', () => {
149-
// Arrange
150-
const deployerStub = sandbox.stub(Deployer.prototype, 'deploy');
151-
152-
// Act
153-
postMigrate.deploy();
154-
155-
// Assert
156-
expect(deployerStub.called).to.be.true;
157-
});
158-
159-
it('should not deploy when autoDeploy is false', () => {
160133
// Arrange
161134
const postMigrateNoDeploy = new PostMigrate(
162135
org,
@@ -166,7 +139,7 @@ describe('PostMigrate', () => {
166139
messages,
167140
ux,
168141
testRelatedObjectsToProcess,
169-
false,
142+
{ autoDeploy: false, authKey: testAuthKey },
170143
testProjectPath
171144
);
172145
const deployerStub = sandbox.stub(Deployer.prototype, 'deploy');
@@ -175,6 +148,7 @@ describe('PostMigrate', () => {
175148
postMigrateNoDeploy.deploy();
176149

177150
// Assert
151+
expect((postMigrateNoDeploy as any).deploymentConfig.autoDeploy).to.be.false;
178152
expect(deployerStub.called).to.be.false;
179153
});
180154

@@ -308,7 +282,7 @@ describe('PostMigrate', () => {
308282
messages,
309283
ux,
310284
undefined as any,
311-
true,
285+
{ autoDeploy: true, authKey: testAuthKey },
312286
testProjectPath
313287
);
314288
const userActionMessage: string[] = [];
@@ -339,7 +313,7 @@ describe('PostMigrate', () => {
339313
messages,
340314
ux,
341315
null as any,
342-
true,
316+
{ autoDeploy: true, authKey: testAuthKey },
343317
testProjectPath
344318
);
345319
const userActionMessage: string[] = [];
@@ -370,7 +344,7 @@ describe('PostMigrate', () => {
370344
messages,
371345
ux,
372346
['Flexipage'], // No expsites
373-
true,
347+
{ autoDeploy: true, authKey: testAuthKey },
374348
testProjectPath
375349
);
376350
const userActionMessage: string[] = [];
@@ -466,7 +440,7 @@ describe('PostMigrate', () => {
466440
messages,
467441
ux,
468442
testRelatedObjectsToProcess,
469-
false,
443+
{ autoDeploy: false, authKey: testAuthKey },
470444
testProjectPath
471445
);
472446
const deployerStub = sandbox.stub(Deployer.prototype, 'deploy');

0 commit comments

Comments
 (0)