Skip to content

Commit a76bd73

Browse files
fix: review comments
1 parent 995d628 commit a76bd73

File tree

3 files changed

+79
-10
lines changed

3 files changed

+79
-10
lines changed

messages/migrate.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@
187187
"creatingNPMConfigFile": "Creating npm configuration file",
188188
"npmConfigFileCreated": "Npm config file created",
189189
"authKeyEnvVarNotSet": "The OMA_AUTH_KEY environment variable isn’t set. LWCs won't be deployed.",
190+
"npmNotInstalled": "npm is not installed on this system. LWC auto-deployment requires npm.",
191+
"lwcDeployPrerequisitesMissing": "LWC auto-deployment prerequisites are not met: %s",
192+
"manualLwcDeploymentPrompt": "Manual LWC deployment will be required. Do you want to proceed with the migration? [y/n]",
193+
"manualLwcDeploymentProceeding": "Proceeding with migration. LWC components will need to be deployed manually.",
194+
"npmAndAuthKeyRequired": "Please install npm and set the OMA_AUTH_KEY environment variable, then re-run the migration.",
190195
"manualDeploymentSteps": "<a href='%s' target='_blank'>Please refer to this documentation for manual deployment process</a>",
191196
"deploymentConsentNotGiven": "Deployment consent not given, manual deployment is required",
192197
"experienceSiteException": "We’ve encountered an exception while processing Experience Cloud sites.",
@@ -330,4 +335,4 @@
330335
"processingNotRequired": "Migration is not required for orgs on standard data model with the Omnistudio Metadata setting turned on.",
331336
"skippingTruncation": "Skipping truncation as the org is on standard data model.",
332337
"loglevelFlagDeprecated": "loglevel is deprecated. Use --verbose instead."
333-
}
338+
}

src/migration/premigrate.ts

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { YES_SHORT, YES_LONG, NO_SHORT, NO_LONG } from '../utils/projectPathUtil
88
import { documentRegistry } from '../utils/constants/documentRegistry';
99
import { OmniStudioMetadataCleanupService } from '../utils/config/OmniStudioMetadataCleanupService';
1010
import { isStandardDataModelWithMetadataAPIEnabled } from '../utils/dataModelService';
11+
import { sfProject } from '../utils/sfcli/project/sfProject';
1112
import { BaseMigrationTool } from './base';
1213

1314
const authEnvKey = 'OMA_AUTH_KEY';
@@ -132,15 +133,9 @@ export class PreMigrate extends BaseMigrationTool {
132133
authKey: undefined,
133134
};
134135
if (consent && includeLwc) {
135-
deploymentConfig.authKey = process.env[authEnvKey];
136-
if (!deploymentConfig.authKey) {
137-
Logger.warn(this.messages.getMessage('authKeyEnvVarNotSet'));
138-
actionItems.push(
139-
`${this.messages.getMessage('authKeyEnvVarNotSet')}\n${this.messages.getMessage('manualDeploymentSteps', [
140-
documentRegistry.manualDeploymentSteps,
141-
])}`
142-
);
143-
}
136+
const lwcPrereqResult = await this.checkLwcDeployPrerequisites(actionItems);
137+
deploymentConfig.authKey = lwcPrereqResult.authKey;
138+
deploymentConfig.autoDeploy = lwcPrereqResult.autoDeploy;
144139
}
145140

146141
if (!consent) {
@@ -215,6 +210,70 @@ export class PreMigrate extends BaseMigrationTool {
215210
return await omniStudioMetadataCleanupService.cleanupOmniStudioMetadataTables();
216211
}
217212

213+
private async checkLwcDeployPrerequisites(
214+
actionItems: string[]
215+
): Promise<{ autoDeploy: boolean; authKey: string | undefined }> {
216+
const missingPrerequisites: string[] = [];
217+
218+
const isNpmAvailable = sfProject.isNpmInstalled();
219+
if (!isNpmAvailable) {
220+
missingPrerequisites.push(this.messages.getMessage('npmNotInstalled'));
221+
}
222+
223+
const authKey = process.env[authEnvKey];
224+
if (!authKey) {
225+
missingPrerequisites.push(this.messages.getMessage('authKeyEnvVarNotSet'));
226+
}
227+
228+
if (missingPrerequisites.length === 0) {
229+
return { autoDeploy: true, authKey };
230+
}
231+
232+
Logger.warn(this.messages.getMessage('lwcDeployPrerequisitesMissing', [missingPrerequisites.join(' ')]));
233+
234+
const proceedWithManual = await this.getManualLwcDeploymentConsent();
235+
236+
if (proceedWithManual) {
237+
Logger.log(this.messages.getMessage('manualLwcDeploymentProceeding'));
238+
actionItems.push(
239+
`${missingPrerequisites.join(' ')}\n${this.messages.getMessage('manualDeploymentSteps', [
240+
documentRegistry.manualDeploymentSteps,
241+
])}`
242+
);
243+
return { autoDeploy: true, authKey: undefined };
244+
}
245+
246+
Logger.error(this.messages.getMessage('npmAndAuthKeyRequired'));
247+
process.exit(1);
248+
}
249+
250+
private async getManualLwcDeploymentConsent(): Promise<boolean> {
251+
const askWithTimeOut = PromptUtil.askWithTimeOut(this.messages);
252+
const validResponse = false;
253+
254+
while (!validResponse) {
255+
try {
256+
const resp = await askWithTimeOut(
257+
Logger.prompt.bind(Logger),
258+
this.messages.getMessage('manualLwcDeploymentPrompt')
259+
);
260+
const response = typeof resp === 'string' ? resp.trim().toLowerCase() : '';
261+
262+
if (response === YES_SHORT || response === YES_LONG) {
263+
return true;
264+
} else if (response === NO_SHORT || response === NO_LONG) {
265+
return false;
266+
} else {
267+
Logger.error(this.messages.getMessage('invalidYesNoResponse'));
268+
}
269+
} catch (err) {
270+
Logger.error(this.messages.getMessage('requestTimedOut'));
271+
process.exit(1);
272+
}
273+
}
274+
return false;
275+
}
276+
218277
// This needs to be behind timeout
219278
private async getExpSiteMetadataEnableConsent(): Promise<boolean> {
220279
const question = this.messages.getMessage('consentForExperienceSites');

src/utils/sfcli/project/sfProject.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'fs';
2+
import * as shell from 'shelljs';
23
import { Messages } from '@salesforce/core';
34
import { Logger } from '../../logger';
45
import { cli } from '../../shell/cli';
@@ -103,6 +104,10 @@ export class sfProject {
103104
}
104105
}
105106

107+
public static isNpmInstalled(): boolean {
108+
return !!shell.which('npm');
109+
}
110+
106111
public static createNPMConfigFile(authKey: string): void {
107112
Logger.logVerbose(messages.getMessage('creatingNPMConfigFile'));
108113
fs.writeFileSync(

0 commit comments

Comments
 (0)