@@ -8,6 +8,7 @@ import { YES_SHORT, YES_LONG, NO_SHORT, NO_LONG } from '../utils/projectPathUtil
88import { documentRegistry } from '../utils/constants/documentRegistry' ;
99import { OmniStudioMetadataCleanupService } from '../utils/config/OmniStudioMetadataCleanupService' ;
1010import { isStandardDataModelWithMetadataAPIEnabled } from '../utils/dataModelService' ;
11+ import { sfProject } from '../utils/sfcli/project/sfProject' ;
1112import { BaseMigrationTool } from './base' ;
1213
1314const 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' ) ;
0 commit comments