Skip to content

Commit

Permalink
added the env name for which we want to keep the env file creation op…
Browse files Browse the repository at this point in the history
…tional and added the app host
  • Loading branch information
cs-raj committed Jan 11, 2024
1 parent f44b4d5 commit b306d3a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/src/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
36 changes: 19 additions & 17 deletions packages/contentstack-bootstrap/src/bootstrap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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':
Expand All @@ -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);
Expand All @@ -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`;
Expand All @@ -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);
Expand All @@ -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':
Expand All @@ -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);
Expand Down

0 comments on commit b306d3a

Please sign in to comment.