From d479efb0a0f26f85611a689bf5ad4d97cbff45b3 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 24 Jan 2024 13:16:38 +0530 Subject: [PATCH 1/3] modified the env for angular and next --- packages/contentstack-bootstrap/src/bootstrap/utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/contentstack-bootstrap/src/bootstrap/utils.ts b/packages/contentstack-bootstrap/src/bootstrap/utils.ts index ef94b7ec7f..99fdddac49 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/utils.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/utils.ts @@ -226,8 +226,8 @@ const envFileHandler = async ( environmentVariables.api_key }', \n\tdelivery_token: '${environmentVariables.deliveryToken}',\n\t${ livePreviewEnabled - ? `\npreview_token=${environmentVariables.preview_token || `''`}\npreview_host=${previewHost - }\napp_host=${appHost}` + ? `\npreview_token:'${environmentVariables.preview_token}' || ''},\npreview_host:'${previewHost + }',\napp_host:'${appHost}'` : '\n' },\n\tenvironment: '${environmentVariables.environment}'${ !isUSRegion && !customHost ? `,\n\tregion: '${region.name}'` : '' @@ -256,7 +256,7 @@ const envFileHandler = async ( !isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : '' }\nCONTENTSTACK_API_HOST='${ customHost ? customHost : managementAPIHost - }'CONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\n\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; + }\n'CONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\n\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; result = await writeEnvFile(content, filePath); break; case 'vue-starter': From 602d9ea8051d633edc55a0fd8379170d1e27770d Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 24 Jan 2024 15:49:54 +0530 Subject: [PATCH 2/3] removed management token from nextjs --- .../contentstack-bootstrap/src/bootstrap/utils.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/contentstack-bootstrap/src/bootstrap/utils.ts b/packages/contentstack-bootstrap/src/bootstrap/utils.ts index 99fdddac49..954e464846 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/utils.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/utils.ts @@ -186,7 +186,7 @@ const envFileHandler = async ( customHost ? customHost : managementAPIHost }${ !isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : '' - }\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_MANAGEMENT_TOKEN=''\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; + }\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; result = await writeEnvFile(content, filePath); break; case 'gatsby': @@ -210,9 +210,9 @@ const envFileHandler = async ( environmentVariables.deliveryToken }',\n${ livePreviewEnabled - ? `\npreivew_token=${ + ? `\n\tpreivew_token=${ environmentVariables.preview_token || `''` - }\npreview_host=${previewHost}\napp_host=${appHost}\n` + }\n\tpreview_host=${previewHost}\n\tapp_host=${appHost}\n` : '\n' },\n\t\tenvironment: '${environmentVariables.environment}'${ !isUSRegion && !customHost ? `,\n\t\tregion: '${region.name}'` : '' @@ -226,14 +226,14 @@ const envFileHandler = async ( environmentVariables.api_key }', \n\tdelivery_token: '${environmentVariables.deliveryToken}',\n\t${ livePreviewEnabled - ? `\npreview_token:'${environmentVariables.preview_token}' || ''},\npreview_host:'${previewHost + ? `\npreview_token:'${environmentVariables.preview_token || ''}',\npreview_host:'${previewHost }',\napp_host:'${appHost}'` : '\n' },\n\tenvironment: '${environmentVariables.environment}'${ !isUSRegion && !customHost ? `,\n\tregion: '${region.name}'` : '' },\n\tapi_host: '${ customHost ? customHost : managementAPIHost - }'\n\tmanagement_token: '',\n\tlive_preview: ${livePreviewEnabled}\n};`; + }',\n\tlive_preview: ${livePreviewEnabled}\n};`; fileName = `environment${environmentVariables.environment === 'production' ? '.prod.' : '.'}ts`; filePath = path.join(clonedDirectory, 'src', 'environments', fileName); result = await writeEnvFile(content, filePath); @@ -254,9 +254,9 @@ const envFileHandler = async ( : '\n' }\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${ !isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : '' - }\nCONTENTSTACK_API_HOST='${ + }\nCONTENTSTACK_API_HOST=${ customHost ? customHost : managementAPIHost - }\n'CONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\n\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; + }\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\n\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; result = await writeEnvFile(content, filePath); break; case 'vue-starter': From c82ad810a0ae930f3a37ab8a16f6b5df4b81fea3 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 25 Jan 2024 10:45:34 +0530 Subject: [PATCH 3/3] modifed the test cases --- packages/contentstack-bootstrap/test/utils.test.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/contentstack-bootstrap/test/utils.test.js b/packages/contentstack-bootstrap/test/utils.test.js index 13f08b81fe..b2deb439fb 100644 --- a/packages/contentstack-bootstrap/test/utils.test.js +++ b/packages/contentstack-bootstrap/test/utils.test.js @@ -45,7 +45,8 @@ describe('Utils', () => { const region = { name: 'NA', cda: 'https://cdn.contentstack.com', - cma: 'https://app.contentstack.com', + cma: 'https://api.contentstack.com', + uiHost: 'https://app.contentstack.com' }; const managementAPIClient = { stack: () => { @@ -73,12 +74,12 @@ describe('Utils', () => { let devEnvFile = await getFileContent(path.join(clonedDirectory, '.env.development.local')); devEnvFile = devEnvFile.replace(/\n/g, ','); expect(devEnvFile).equal( - 'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_PREVIEW_TOKEN=mock_preview_token,REACT_APP_CONTENTSTACK_PREVIEW_HOST=https://rest-preview.contentstack.com,REACT_APP_CONTENTSTACK_ENVIRONMENT=development,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=true', + 'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_PREVIEW_TOKEN=mock_preview_token,REACT_APP_CONTENTSTACK_PREVIEW_HOST=rest-preview.contentstack.com,REACT_APP_CONTENTSTACK_APP_HOST=app.contentstack.com,,REACT_APP_CONTENTSTACK_ENVIRONMENT=development,,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=true', ); let prodEnvFile = await getFileContent(path.join(clonedDirectory, '.env.production.local')); prodEnvFile = prodEnvFile.replace(/\n/g, ','); expect(prodEnvFile).equal( - 'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_PREVIEW_TOKEN=mock_preview_token,REACT_APP_CONTENTSTACK_PREVIEW_HOST=https://rest-preview.contentstack.com,REACT_APP_CONTENTSTACK_ENVIRONMENT=production,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=true', + 'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_PREVIEW_TOKEN=mock_preview_token,REACT_APP_CONTENTSTACK_PREVIEW_HOST=rest-preview.contentstack.com,REACT_APP_CONTENTSTACK_APP_HOST=app.contentstack.com,,REACT_APP_CONTENTSTACK_ENVIRONMENT=production,,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=true', ); }); it('Create env file for a stack with live preview disabled', async () => { @@ -94,6 +95,7 @@ describe('Utils', () => { name: 'NA', cda: 'https://cdn.contentstack.com', cma: 'https://app.contentstack.com', + uiHost: 'https://app.contentstack.com' }; const managementAPIClient = { stack: () => { @@ -121,12 +123,12 @@ describe('Utils', () => { let devEnvFile = await getFileContent(path.join(clonedDirectory, '.env.development.local')); devEnvFile = devEnvFile.replace(/\n/g, ','); expect(devEnvFile).equal( - 'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_ENVIRONMENT=development,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=false' + 'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,,REACT_APP_CONTENTSTACK_ENVIRONMENT=development,,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=false' ); let prodEnvFile = await getFileContent(path.join(clonedDirectory, '.env.production.local')); prodEnvFile = prodEnvFile.replace(/\n/g, ','); expect(prodEnvFile).equal( - 'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_ENVIRONMENT=production,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=false' + 'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,,REACT_APP_CONTENTSTACK_ENVIRONMENT=production,,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=false' ); }); it('Create env with invalid environments, should throw an error', async () => { @@ -140,7 +142,7 @@ describe('Utils', () => { const region = { name: 'NA', cda: 'https://app.contentstack.com', - cma: 'https://app.contentstack.com', + cma: 'https://api.contentstack.com', }; const managementAPIClient = { stack: () => ({