diff --git a/packages/contentstack-bootstrap/src/bootstrap/index.ts b/packages/contentstack-bootstrap/src/bootstrap/index.ts index e0162e92f3..a6c44fbdbd 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/index.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/index.ts @@ -115,7 +115,7 @@ export default class Bootstrap { if (this.options.livePreviewEnabled) { cliux.print( - 'Important: set management token and app host in the environment file before running the application', + 'Important: set preview token, preview host and app host in the environment file before running the application', { color: 'yellow', }, diff --git a/packages/contentstack-bootstrap/src/bootstrap/interactive.ts b/packages/contentstack-bootstrap/src/bootstrap/interactive.ts index 88e605d35d..cf61b119b2 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/interactive.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/interactive.ts @@ -104,7 +104,7 @@ export async function continueBootstrapCommand() { const { shouldContinue } = await inquirer.prompt({ type: 'list', name: 'shouldContinue', - message: `Do you still want to complete the bootstrap command with Live Preview Disabled?`, + message: `Do you still want to complete the bootstrap command?`, choices: ['yes', 'no'], loop: false, }); diff --git a/packages/contentstack-bootstrap/src/bootstrap/utils.ts b/packages/contentstack-bootstrap/src/bootstrap/utils.ts index c83fe7809b..900535f953 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/utils.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/utils.ts @@ -64,7 +64,7 @@ export const setupEnvironments = async ( : {}; if (livePreviewEnabled && !tokenResult.preview_token && !managementToken) { cliux.print( - `warning: Live Preview using the Preview token is not available in your plan please contact the admin.`, + `info: For the Environment ${environment.name}.\nwarning: Live Preview using the Preview token is not available in your plan please contact the admin.`, { color: 'yellow', } @@ -140,11 +140,13 @@ const envFileHandler = async ( let fileName; let customHost; let previewHost: string; + let appHost: string; const regionName = region && region.name && region.name.toLowerCase(); - previewHost = region.cda?.substring(8).replace('cdn', 'rest-preview'); + previewHost = region?.cda?.substring(8)?.replace('cdn', 'rest-preview'); + appHost = region?.uiHost?.substring(8); const isUSRegion = regionName === 'us' || regionName === 'na'; if (regionName !== 'eu' && !isUSRegion) { - customHost = region.cda && region.cda.substring(8); + customHost = region?.cda.substring(8); customHost = customHost.replace('cdn', 'rest-preview'); } const production = environmentVariables.environment === 'production' ? true : false; @@ -159,9 +161,9 @@ const envFileHandler = async ( livePreviewEnabled ? `\nREACT_APP_CONTENTSTACK_PREVIEW_TOKEN=${ environmentVariables.preview_token || `''` - }\nREACT_APP_CONTENTSTACK_PREVIEW_HOST=${customHost ?? previewHost}\n` + }\nREACT_APP_CONTENTSTACK_PREVIEW_HOST=${customHost ?? previewHost}\nREACT_APP_CONTENTSTACK_APP_HOST=${appHost}\n` : '\n' - }REACT_APP_CONTENTSTACK_APP_HOST=''\nREACT_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${ + }\nREACT_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${ !isUSRegion && !customHost ? '\nREACT_APP_CONTENTSTACK_REGION=' + region.name : '' }\nSKIP_PREFLIGHT_CHECK=true\nREACT_APP_CONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`; result = await writeEnvFile(content, filePath); @@ -176,11 +178,11 @@ const envFileHandler = async ( livePreviewEnabled ? `\nCONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token || `''`}\nCONTENTSTACK_PREVIEW_HOST=${ customHost ?? previewHost - }\n` + }\nCONTENTSTACK_APP_HOST=${appHost}\n` : '\n' }CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\n${ !isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : '' - }\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_MANAGEMENT_TOKEN=''\nCONTENTSTACK_APP_HOST=''\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; + }\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_MANAGEMENT_TOKEN=''\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; result = await writeEnvFile(content, filePath); break; case 'gatsby': @@ -193,9 +195,9 @@ const envFileHandler = async ( livePreviewEnabled ? `\nCONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token || `''`}\nCONTENTSTACK_PREVIEW_HOST=${ customHost ?? previewHost - }\n` + }\nCONTENTSTACK_APP_HOST=${appHost}\n` : '\n' - }CONTENTSTACK_APP_HOST=''\nCONTENTSTACK_ENVIRONMENT=${ + }\nCONTENTSTACK_ENVIRONMENT=${ environmentVariables.environment }\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`; result = await writeEnvFile(content, filePath); @@ -207,9 +209,9 @@ const envFileHandler = async ( environmentVariables.deliveryToken }',\n${ livePreviewEnabled - ? `\npreivew_token=${environmentVariables.preview_token || `''`}\npreview_host=${customHost ?? previewHost}\n` + ? `\npreivew_token=${environmentVariables.preview_token || `''`}\npreview_host=${customHost ?? previewHost}\napp_host=${appHost}\n` : '\n' - },\tapp_host: '',\n\t\tenvironment: '${environmentVariables.environment}'${ + },\n\t\tenvironment: '${environmentVariables.environment}'${ !isUSRegion && !customHost ? `,\n\t\tregion: '${region.name}'` : '' } \n\t } \n };`; fileName = `environment${environmentVariables.environment === 'production' ? '.prod.' : '.'}ts`; @@ -221,11 +223,11 @@ const envFileHandler = async ( environmentVariables.api_key }', \n\tdelivery_token: '${environmentVariables.deliveryToken}',\n\t${ livePreviewEnabled - ? `\npreview_token=${environmentVariables.preview_token || `''`}\npreview_host=${customHost ?? previewHost}\n` + ? `\npreview_token=${environmentVariables.preview_token || `''`}\npreview_host=${customHost ?? previewHost}\napp_host=${appHost}` : '\n' },\n\tenvironment: '${environmentVariables.environment}'${ !isUSRegion && !customHost ? `,\n\tregion: '${region.name}'` : '' - },\n\t\n\tapp_host: '',\n\tmanagement_token: '',\n\tlive_preview: ${livePreviewEnabled}\n};`; + },\n\tmanagement_token: '',\n\tlive_preview: ${livePreviewEnabled}\n};`; fileName = `environment${environmentVariables.environment === 'production' ? '.prod.' : '.'}ts`; filePath = path.join(clonedDirectory, 'src', 'environments', fileName); result = await writeEnvFile(content, filePath); @@ -242,11 +244,11 @@ const envFileHandler = async ( livePreviewEnabled ? `\nCONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token || `''`}\nCONTENTSTACK_PREVIEW_HOST=${ customHost ?? previewHost - }\n` + }\nCONTENTSTACK_APP_HOST=${appHost}` : '\n' }\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${ !isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : '' - }\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\n\nCONTENTSTACK_APP_HOST=''\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; + }\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\n\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; result = await writeEnvFile(content, filePath); break; case 'vue-starter': @@ -258,9 +260,9 @@ const envFileHandler = async ( livePreviewEnabled ? `\nVUE_APP_CONTENTSTACK_PREVIEW_TOKEN=${ environmentVariables.preview_token || `''` - }\nVUE_APP_CONTENTSTACK_PREVIEW_HOST=${customHost ?? previewHost}\n` + }\nVUE_APP_CONTENTSTACK_PREVIEW_HOST=${customHost ?? previewHost}\nVUE_APP_CONTENTSTACK_APP_HOST=${appHost}\n` : '\n' - }VUE_APP_CONTENTSTACK_APP_HOST=''\nVUE_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${ + }\nVUE_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${ !isUSRegion && !customHost ? '\nVUE_APP_CONTENTSTACK_REGION=' + region.name : '' }\nVUE_APP_CONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`; result = await writeEnvFile(content, filePath);