Skip to content

Commit a3b6211

Browse files
committed
feat: addressed comments
1 parent cf19ea6 commit a3b6211

File tree

2 files changed

+49
-45
lines changed

2 files changed

+49
-45
lines changed

src/commands/omnistudio/migration/migrate.ts

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ 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-
3836
// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
3937
// or any library that is using the messages framework can also be loaded this way.
4038
const messages = Messages.loadMessages('@salesforce/plugin-omnistudio-migration-tool', 'migrate');
@@ -260,7 +258,7 @@ export default class Migrate extends OmniStudioBaseCommand {
260258
}
261259
}
262260

263-
const deploymentConfig = await this.getAutoDeployConsent(objectsToProcess.includes(Constants.LWC));
261+
let deploymentConfig = { autoDeploy: false, authKey: undefined };
264262
let projectPath: string;
265263
let targetApexNamespace: string;
266264
// Check for general consent to make modifications with OMT
@@ -274,6 +272,7 @@ export default class Migrate extends OmniStudioBaseCommand {
274272
conn,
275273
isExperienceBundleMetadataAPIProgramaticallyEnabled
276274
);
275+
deploymentConfig = await preMigrate.getAutoDeployConsent(objectsToProcess.includes(Constants.LWC));
277276
Logger.logVerbose(
278277
'The objects to process after handleExpSitePrerequisite are ' + JSON.stringify(objectsToProcess)
279278
);
@@ -282,47 +281,6 @@ export default class Migrate extends OmniStudioBaseCommand {
282281
return { objectsToProcess, projectPath, targetApexNamespace, deploymentConfig };
283282
}
284283

285-
private async getAutoDeployConsent(
286-
includeLwc: boolean
287-
): Promise<{ autoDeploy: boolean; authKey: string | undefined }> {
288-
const askWithTimeOut = PromptUtil.askWithTimeOut(messages);
289-
let validResponse = false;
290-
let consent = false;
291-
292-
while (!validResponse) {
293-
try {
294-
const resp = await askWithTimeOut(Logger.prompt.bind(Logger), messages.getMessage('autoDeployConsentMessage'));
295-
const response = typeof resp === 'string' ? resp.trim().toLowerCase() : '';
296-
297-
if (response === YES_SHORT || response === YES_LONG) {
298-
consent = true;
299-
validResponse = true;
300-
} else if (response === NO_SHORT || response === NO_LONG) {
301-
consent = false;
302-
validResponse = true;
303-
} else {
304-
Logger.error(messages.getMessage('invalidYesNoResponse'));
305-
}
306-
} catch (err) {
307-
Logger.error(messages.getMessage('requestTimedOut'));
308-
process.exit(1);
309-
}
310-
}
311-
312-
const deploymentConfig = {
313-
autoDeploy: consent,
314-
authKey: undefined,
315-
};
316-
if (consent && includeLwc) {
317-
deploymentConfig.authKey = process.env[authEnvKey];
318-
if (!deploymentConfig.authKey) {
319-
Logger.warn(messages.getMessage('authKeyEnvVarNotSet'));
320-
}
321-
}
322-
323-
return deploymentConfig;
324-
}
325-
326284
private async getMigrationConsent(): Promise<boolean> {
327285
const askWithTimeOut = PromptUtil.askWithTimeOut(messages);
328286
let validResponse = false;

src/migration/premigrate.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { UX } from '@salesforce/command';
33
import { Logger } from '../utils/logger';
44
import { Constants } from '../utils/constants/stringContants';
55
import { OrgPreferences } from '../utils/orgPreferences';
6-
import { askStringWithTimeout } from '../utils/promptUtil';
6+
import { askStringWithTimeout, PromptUtil } from '../utils/promptUtil';
77
import { YES_SHORT, YES_LONG, NO_SHORT, NO_LONG } from '../utils/projectPathUtil';
88
import { BaseMigrationTool } from './base';
99

10+
const authEnvKey = 'OMA_AUTH_KEY';
11+
1012
export class PreMigrate extends BaseMigrationTool {
1113
// Source Custom Object Names
1214
public constructor(namespace: string, connection: Connection, logger: Logger, messages: Messages, ux: UX) {
@@ -51,6 +53,50 @@ export class PreMigrate extends BaseMigrationTool {
5153
}
5254
}
5355

56+
public async getAutoDeployConsent(
57+
includeLwc: boolean
58+
): Promise<{ autoDeploy: boolean; authKey: string | undefined }> {
59+
const askWithTimeOut = PromptUtil.askWithTimeOut(this.messages);
60+
let validResponse = false;
61+
let consent = false;
62+
63+
while (!validResponse) {
64+
try {
65+
const resp = await askWithTimeOut(
66+
Logger.prompt.bind(Logger),
67+
this.messages.getMessage('autoDeployConsentMessage')
68+
);
69+
const response = typeof resp === 'string' ? resp.trim().toLowerCase() : '';
70+
71+
if (response === YES_SHORT || response === YES_LONG) {
72+
consent = true;
73+
validResponse = true;
74+
} else if (response === NO_SHORT || response === NO_LONG) {
75+
consent = false;
76+
validResponse = true;
77+
} else {
78+
Logger.error(this.messages.getMessage('invalidYesNoResponse'));
79+
}
80+
} catch (err) {
81+
Logger.error(this.messages.getMessage('requestTimedOut'));
82+
process.exit(1);
83+
}
84+
}
85+
86+
const deploymentConfig = {
87+
autoDeploy: consent,
88+
authKey: undefined,
89+
};
90+
if (consent && includeLwc) {
91+
deploymentConfig.authKey = process.env[authEnvKey];
92+
if (!deploymentConfig.authKey) {
93+
Logger.warn(this.messages.getMessage('authKeyEnvVarNotSet'));
94+
}
95+
}
96+
97+
return deploymentConfig;
98+
}
99+
54100
// This needs to be behind timeout
55101
private async getExpSiteMetadataEnableConsent(): Promise<boolean> {
56102
const question = this.messages.getMessage('consentForExperienceSites');

0 commit comments

Comments
 (0)