From 610f7b4937973e1f1aa1723fe018683b99d6ac2d Mon Sep 17 00:00:00 2001 From: yavorsk Date: Mon, 30 Oct 2023 17:32:39 +0200 Subject: [PATCH 01/12] Rename jssAppName to siteName variables in react template --- .../create-sitecore-jss/src/templates/react/.env | 5 +++-- .../react/scripts/config/plugins/fallback.js | 2 +- .../react/scripts/config/plugins/package-json.js | 2 +- .../react/scripts/disconnected-mode-proxy.js | 4 ++-- .../src/templates/react/scripts/generate-config.js | 13 +++++++------ .../src/templates/react/server/server.js | 8 ++++---- .../react/src/lib/dictionary-service-factory.js | 4 ++-- .../react/src/lib/layout-service-factory.js | 4 ++-- 8 files changed, 22 insertions(+), 20 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/react/.env b/packages/create-sitecore-jss/src/templates/react/.env index 37c9868a42..c43b7f8135 100644 --- a/packages/create-sitecore-jss/src/templates/react/.env +++ b/packages/create-sitecore-jss/src/templates/react/.env @@ -20,8 +20,9 @@ REACT_APP_SITECORE_API_HOST= # the resolved Sitecore API hostname + the `graphQLEndpointPath` defined in your `package.json`. REACT_APP_GRAPH_QL_ENDPOINT= -# Your JSS app name (also used as the default site name). Overrides 'config.appName' defined in a package.json -REACT_APP_JSS_APP_NAME= +# Your Sitecore site name. +# Uses your `package.json` config `appName` if empty. +SITE_NAME= # Your default app language. REACT_APP_DEFAULT_LANGUAGE= diff --git a/packages/create-sitecore-jss/src/templates/react/scripts/config/plugins/fallback.js b/packages/create-sitecore-jss/src/templates/react/scripts/config/plugins/fallback.js index 7caee94ebe..df3c16c354 100644 --- a/packages/create-sitecore-jss/src/templates/react/scripts/config/plugins/fallback.js +++ b/packages/create-sitecore-jss/src/templates/react/scripts/config/plugins/fallback.js @@ -10,7 +10,7 @@ class FallbackPlugin { return Object.assign({}, config, { defaultLanguage: config.defaultLanguage || 'en', sitecoreApiKey: config.sitecoreApiKey || 'no-api-key-set', - jssAppName: config.jssAppName || 'Unknown', + siteName: config.siteName || 'Unknown', layoutServiceConfigurationName: config.layoutServiceConfigurationName || 'default', }); } diff --git a/packages/create-sitecore-jss/src/templates/react/scripts/config/plugins/package-json.js b/packages/create-sitecore-jss/src/templates/react/scripts/config/plugins/package-json.js index a741a79d78..bf958ca421 100644 --- a/packages/create-sitecore-jss/src/templates/react/scripts/config/plugins/package-json.js +++ b/packages/create-sitecore-jss/src/templates/react/scripts/config/plugins/package-json.js @@ -10,7 +10,7 @@ class PackageJsonPlugin { if (!packageConfig.config) return config; return Object.assign({}, config, { - jssAppName: config.jssAppName || packageConfig.config.appName, + siteName: config.siteName || packageConfig.config.appName, defaultLanguage: config.defaultLanguage || packageConfig.config.language, graphQLEndpointPath: config.graphQLEndpointPath || packageConfig.config.graphQLEndpointPath, }); diff --git a/packages/create-sitecore-jss/src/templates/react/scripts/disconnected-mode-proxy.js b/packages/create-sitecore-jss/src/templates/react/scripts/disconnected-mode-proxy.js index b53c374635..15e035e0d1 100644 --- a/packages/create-sitecore-jss/src/templates/react/scripts/disconnected-mode-proxy.js +++ b/packages/create-sitecore-jss/src/templates/react/scripts/disconnected-mode-proxy.js @@ -18,11 +18,11 @@ const touchToReloadFilePath = 'src/temp/config.js'; const proxyOptions = { appRoot: path.join(__dirname, '..'), - appName: config.jssAppName, + appName: config.siteName, watchPaths: ['./data'], language: config.defaultLanguage, port: process.env.PROXY_PORT || 3042, - onManifestUpdated: (manifest) => { + onManifestUpdated: manifest => { // if we can resolve the config file, we can alter it to force reloading the app automatically // instead of waiting for a manual reload. We must materially alter the _contents_ of the file to trigger // an actual reload, so we append "// reloadnow" to the file each time. This will not cause a problem, diff --git a/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js b/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js index 554687dd72..3a344f6de1 100644 --- a/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js +++ b/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js @@ -12,14 +12,15 @@ const { jssConfigFactory } = require('./config'); const defaultConfig = { sitecoreApiKey: process.env[`${constantCase('reactAppSitecoreApiKey')}`], sitecoreApiHost: process.env[`${constantCase('reactAppSitecoreApiHost')}`], - jssAppName: process.env[`${constantCase('reactAppJssAppName')}`], + siteName: process.env[`${constantCase('siteName')}`], graphQLEndpointPath: process.env[`${constantCase('reactAppGraphQLEndpointPath')}`], defaultLanguage: process.env[`${constantCase('reactAppDefaultLanguage')}`], graphQLEndpoint: process.env[`${constantCase('reactAppGraphQLEndpoint')}`], - layoutServiceConfigurationName: process.env[`${constantCase('reactAppLayoutServiceConfigurationName')}`], + layoutServiceConfigurationName: + process.env[`${constantCase('reactAppLayoutServiceConfigurationName')}`], }; -generateConfig() +generateConfig(); /** * Generate config @@ -30,7 +31,7 @@ generateConfig() */ function generateConfig() { try { - config = jssConfigFactory.create(defaultConfig) + config = jssConfigFactory.create(defaultConfig); } catch (error) { console.error('Error generating config'); console.error(error); @@ -38,7 +39,7 @@ function generateConfig() { } writeConfig(config); -}; +} function writeConfig(config) { let configText = `/* eslint-disable */ @@ -47,7 +48,7 @@ function writeConfig(config) { const config = {};\n`; // Set base configuration values, allowing override with environment variables - Object.keys(config).forEach((prop) => { + Object.keys(config).forEach(prop => { configText += `config.${prop} = process.env.REACT_APP_${constantCase(prop)} || "${ config[prop] }",\n`; diff --git a/packages/create-sitecore-jss/src/templates/react/server/server.js b/packages/create-sitecore-jss/src/templates/react/server/server.js index f8d558836b..88317ec75c 100644 --- a/packages/create-sitecore-jss/src/templates/react/server/server.js +++ b/packages/create-sitecore-jss/src/templates/react/server/server.js @@ -40,7 +40,7 @@ export const setUpDefaultAgents = (httpAgent, httpsAgent) => { // Export app configuration; this will be used when this app runs in Headless mode (ie node-headless-ssr-experience-edge or node-headless-ssr-proxy) export const apiKey = config.sitecoreApiKey; -export const appName = config.jssAppName; +export const appName = config.siteName; export const defaultLanguage = config.defaultLanguage; /** @@ -81,12 +81,12 @@ export function renderView(callback, path, data, viewBag) { /> ) ) - .then((renderedAppHtml) => + .then(renderedAppHtml => // getHtmlTemplate() should return the "shell" HTML template that the rendered app // will be injected into. In many cases, the HTML template will be the same for client-side // rendering and for server-sider rendering. However, in some instances (e.g. JSS render host) // the HTML template needs to be modified or replaced when rendering. - getHtmlTemplate(state).then((htmlTemplate) => ({ + getHtmlTemplate(state).then(htmlTemplate => ({ htmlTemplate, renderedAppHtml, })) @@ -139,7 +139,7 @@ export function renderView(callback, path, data, viewBag) { callback(null, { html }); }) - .catch((error) => callback(error, null)); + .catch(error => callback(error, null)); } catch (err) { // need to ensure the callback is always invoked no matter what // or else SSR will hang diff --git a/packages/create-sitecore-jss/src/templates/react/src/lib/dictionary-service-factory.js b/packages/create-sitecore-jss/src/templates/react/src/lib/dictionary-service-factory.js index 907df4b3f4..ac880a0e7f 100644 --- a/packages/create-sitecore-jss/src/templates/react/src/lib/dictionary-service-factory.js +++ b/packages/create-sitecore-jss/src/templates/react/src/lib/dictionary-service-factory.js @@ -11,7 +11,7 @@ export class DictionaryServiceFactory { ? new GraphQLDictionaryService({ endpoint: config.graphQLEndpoint, apiKey: config.sitecoreApiKey, - siteName: config.jssAppName, + siteName: config.siteName, /* The Dictionary Service needs a root item ID in order to fetch dictionary phrases for the current app. If your Sitecore instance only has 1 JSS App, you can specify the root item ID here; @@ -22,7 +22,7 @@ export class DictionaryServiceFactory { : new RestDictionaryService({ apiHost: config.sitecoreApiHost, apiKey: config.sitecoreApiKey, - siteName: config.jssAppName, + siteName: config.siteName, }); } } diff --git a/packages/create-sitecore-jss/src/templates/react/src/lib/layout-service-factory.js b/packages/create-sitecore-jss/src/templates/react/src/lib/layout-service-factory.js index fb4fcdd59e..43d3a5d018 100644 --- a/packages/create-sitecore-jss/src/templates/react/src/lib/layout-service-factory.js +++ b/packages/create-sitecore-jss/src/templates/react/src/lib/layout-service-factory.js @@ -11,12 +11,12 @@ export class LayoutServiceFactory { ? new GraphQLLayoutService({ endpoint: config.graphQLEndpoint, apiKey: config.sitecoreApiKey, - siteName: config.jssAppName, + siteName: config.siteName, }) : new RestLayoutService({ apiHost: config.sitecoreApiHost, apiKey: config.sitecoreApiKey, - siteName: config.jssAppName, + siteName: config.siteName, configurationName: config.layoutServiceConfigurationName, }); } From 0f0db8e1f68df711ff40375dd8ce757dc4534c68 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Mon, 30 Oct 2023 18:11:55 +0200 Subject: [PATCH 02/12] Rename jssAppName to siteName variables in angular template --- .../src/templates/angular/.env | 5 +++-- .../angular/scripts/disconnected-mode-proxy.ts | 15 +++++++++------ .../templates/angular/scripts/generate-config.ts | 12 ++++++++---- .../src/templates/angular/server.bundle.ts | 15 ++++++--------- .../src/app/lib/dictionary-service-factory.ts | 4 ++-- .../angular/src/app/lib/layout-service-factory.ts | 4 ++-- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/angular/.env b/packages/create-sitecore-jss/src/templates/angular/.env index ac3a727160..1f569cbf3d 100644 --- a/packages/create-sitecore-jss/src/templates/angular/.env +++ b/packages/create-sitecore-jss/src/templates/angular/.env @@ -17,8 +17,9 @@ SITECORE_API_HOST= # the resolved Sitecore API hostname + the `graphQLEndpointPath` defined in your `package.json`. GRAPH_QL_ENDPOINT= -# Your JSS app name (also used as the default site name). Overrides 'config.appName' defined in a package.json -JSS_APP_NAME= +# Your Sitecore site name. +# Uses your `package.json` config `appName` if empty. +SITE_NAME= # Your default app language. DEFAULT_LANGUAGE= diff --git a/packages/create-sitecore-jss/src/templates/angular/scripts/disconnected-mode-proxy.ts b/packages/create-sitecore-jss/src/templates/angular/scripts/disconnected-mode-proxy.ts index 28652c18ba..096be36ad0 100644 --- a/packages/create-sitecore-jss/src/templates/angular/scripts/disconnected-mode-proxy.ts +++ b/packages/create-sitecore-jss/src/templates/angular/scripts/disconnected-mode-proxy.ts @@ -9,21 +9,24 @@ import * as fs from 'fs'; import { join } from 'path'; -import { createDefaultDisconnectedServer, DisconnectedServerOptions } from '@sitecore-jss/sitecore-jss-dev-tools'; +import { + createDefaultDisconnectedServer, + DisconnectedServerOptions, +} from '@sitecore-jss/sitecore-jss-dev-tools'; import { ManifestInstance } from '@sitecore-jss/sitecore-jss-dev-tools'; import { environment } from '../src/environments/environment'; -const config = (environment as { +const config = environment as { [key: string]: unknown; - jssAppName: string; - defaultLanguage: string -}); + siteName: string; + defaultLanguage: string; +}; const touchToReloadFilePath = 'src/environments/environment.js'; const proxyOptions: DisconnectedServerOptions = { appRoot: join(__dirname, '..'), - appName: config.jssAppName, + appName: config.siteName, watchPaths: ['./data'], language: config.defaultLanguage, // Additional transpilation is not needed diff --git a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts index c5823883ca..70f39765b2 100644 --- a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts +++ b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts @@ -15,7 +15,7 @@ export function generateConfig(configOverrides?: { [key: string]: unknown }, out production: false, sitecoreApiHost: '', sitecoreApiKey: 'no-api-key-set', - jssAppName: 'Unknown', + siteName: 'Unknown', sitecoreLayoutServiceConfig: 'jss', defaultLanguage: 'en', defaultServerRoute: '/', @@ -75,7 +75,9 @@ function transformScJssConfig() { return {}; } - if (!config) { return {}; } + if (!config) { + return {}; + } return { sitecoreApiKey: config.sitecore.apiKey, @@ -86,10 +88,12 @@ function transformScJssConfig() { function transformPackageConfig() { const packageAny = packageConfig; - if (!packageAny.config) { return {}; } + if (!packageAny.config) { + return {}; + } return { - jssAppName: packageAny.config.appName, + siteName: packageAny.config.appName, defaultLanguage: packageAny.config.language || 'en', graphQLEndpointPath: packageAny.config.graphQLEndpointPath || null, }; diff --git a/packages/create-sitecore-jss/src/templates/angular/server.bundle.ts b/packages/create-sitecore-jss/src/templates/angular/server.bundle.ts index 32189c2e00..43473295bc 100644 --- a/packages/create-sitecore-jss/src/templates/angular/server.bundle.ts +++ b/packages/create-sitecore-jss/src/templates/angular/server.bundle.ts @@ -87,7 +87,10 @@ function renderView( function parseRouteUrl(url: string) { const routeParser = new JssRouteBuilderService(); - const jssRoute = routeParser.parseRouteUrl(url.split('/').filter((segment) => segment), true); + const jssRoute = routeParser.parseRouteUrl( + url.split('/').filter((segment) => segment), + true + ); return { lang: jssRoute.language, sitecoreRoute: jssRoute.serverRoute, @@ -95,12 +98,6 @@ function parseRouteUrl(url: string) { } const apiKey = environment.sitecoreApiKey; -const appName = environment.jssAppName; +const siteName = environment.siteName; -export { - renderView, - parseRouteUrl, - setUpDefaultAgents, - apiKey, - appName, -}; +export { renderView, parseRouteUrl, setUpDefaultAgents, apiKey, siteName }; diff --git a/packages/create-sitecore-jss/src/templates/angular/src/app/lib/dictionary-service-factory.ts b/packages/create-sitecore-jss/src/templates/angular/src/app/lib/dictionary-service-factory.ts index 428cc36382..ba67ec29f4 100644 --- a/packages/create-sitecore-jss/src/templates/angular/src/app/lib/dictionary-service-factory.ts +++ b/packages/create-sitecore-jss/src/templates/angular/src/app/lib/dictionary-service-factory.ts @@ -12,7 +12,7 @@ export class DictionaryServiceFactory { ? new GraphQLDictionaryService({ endpoint: env.graphQLEndpoint, apiKey: env.sitecoreApiKey, - siteName: env.jssAppName, + siteName: env.siteName, /* The Dictionary Service needs a root item ID in order to fetch dictionary phrases for the current app. If your Sitecore instance only has 1 JSS App, you can specify the root item ID here; @@ -23,7 +23,7 @@ export class DictionaryServiceFactory { : new RestDictionaryService({ apiHost: env.sitecoreApiHost, apiKey: env.sitecoreApiKey, - siteName: env.jssAppName, + siteName: env.siteName, }); } } diff --git a/packages/create-sitecore-jss/src/templates/angular/src/app/lib/layout-service-factory.ts b/packages/create-sitecore-jss/src/templates/angular/src/app/lib/layout-service-factory.ts index cef90a28c6..2e420c80f0 100644 --- a/packages/create-sitecore-jss/src/templates/angular/src/app/lib/layout-service-factory.ts +++ b/packages/create-sitecore-jss/src/templates/angular/src/app/lib/layout-service-factory.ts @@ -12,12 +12,12 @@ export class LayoutServiceFactory { ? new GraphQLLayoutService({ endpoint: environment.graphQLEndpoint, apiKey: environment.sitecoreApiKey, - siteName: environment.jssAppName, + siteName: environment.siteName, }) : new RestLayoutService({ apiHost: environment.sitecoreApiHost, apiKey: environment.sitecoreApiKey, - siteName: environment.jssAppName, + siteName: environment.siteName, configurationName: environment.layoutServiceConfigurationName, }); } From 84243b67dd91fc6123416d3533420669a8a7a62b Mon Sep 17 00:00:00 2001 From: yavorsk Date: Mon, 30 Oct 2023 18:26:41 +0200 Subject: [PATCH 03/12] renamed siteName variable to be consistent with the other env vars for react template --- packages/create-sitecore-jss/src/templates/react/.env | 2 +- .../src/templates/react/scripts/generate-config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/react/.env b/packages/create-sitecore-jss/src/templates/react/.env index c43b7f8135..43664dfacc 100644 --- a/packages/create-sitecore-jss/src/templates/react/.env +++ b/packages/create-sitecore-jss/src/templates/react/.env @@ -22,7 +22,7 @@ REACT_APP_GRAPH_QL_ENDPOINT= # Your Sitecore site name. # Uses your `package.json` config `appName` if empty. -SITE_NAME= +REACT_APP_SITE_NAME= # Your default app language. REACT_APP_DEFAULT_LANGUAGE= diff --git a/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js b/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js index 3a344f6de1..bb92ce667c 100644 --- a/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js +++ b/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js @@ -12,7 +12,7 @@ const { jssConfigFactory } = require('./config'); const defaultConfig = { sitecoreApiKey: process.env[`${constantCase('reactAppSitecoreApiKey')}`], sitecoreApiHost: process.env[`${constantCase('reactAppSitecoreApiHost')}`], - siteName: process.env[`${constantCase('siteName')}`], + siteName: process.env[`${constantCase('reactAppSiteName')}`], graphQLEndpointPath: process.env[`${constantCase('reactAppGraphQLEndpointPath')}`], defaultLanguage: process.env[`${constantCase('reactAppDefaultLanguage')}`], graphQLEndpoint: process.env[`${constantCase('reactAppGraphQLEndpoint')}`], From 7f8893791d6f0b2714def344bef848b3e51fa579 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Mon, 30 Oct 2023 18:35:33 +0200 Subject: [PATCH 04/12] Rename jssAppName to siteName variables in vue template --- packages/create-sitecore-jss/src/templates/vue/.env | 5 +++-- .../templates/vue/scripts/disconnected-mode-proxy.js | 2 +- .../src/templates/vue/scripts/generate-config.js | 8 +++++--- .../src/templates/vue/server/server.js | 2 +- .../vue/src/lib/dictionary-service-factory.js | 10 +++++++--- .../templates/vue/src/lib/layout-service-factory.js | 4 ++-- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/vue/.env b/packages/create-sitecore-jss/src/templates/vue/.env index 758944e93d..fd829b14d3 100644 --- a/packages/create-sitecore-jss/src/templates/vue/.env +++ b/packages/create-sitecore-jss/src/templates/vue/.env @@ -19,8 +19,9 @@ VUE_APP_SITECORE_API_HOST= # the resolved Sitecore API hostname + the `graphQLEndpointPath` defined in your `package.json`. VUE_APP_GRAPH_QL_ENDPOINT= -# Your JSS app name (also used as the default site name). Overrides 'config.appName' defined in a package.json -VUE_APP_JSS_APP_NAME= +# Your Sitecore site name. +# Uses your `package.json` config `appName` if empty. +VUE_APP_SITE_NAME= # Your default app language. VUE_APP_DEFAULT_LANGUAGE= diff --git a/packages/create-sitecore-jss/src/templates/vue/scripts/disconnected-mode-proxy.js b/packages/create-sitecore-jss/src/templates/vue/scripts/disconnected-mode-proxy.js index d765f81704..384975521a 100644 --- a/packages/create-sitecore-jss/src/templates/vue/scripts/disconnected-mode-proxy.js +++ b/packages/create-sitecore-jss/src/templates/vue/scripts/disconnected-mode-proxy.js @@ -21,7 +21,7 @@ const touchToReloadFilePath = 'src/temp/config.js'; const proxyOptions = { appRoot: path.join(__dirname, '..'), - appName: config.jssAppName, + appName: config.siteName, watchPaths: ['./data'], language: config.defaultLanguage, port: process.env.PROXY_PORT || 3042, diff --git a/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js b/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js index f6aa3b4b09..608a8219e5 100644 --- a/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js +++ b/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js @@ -17,7 +17,7 @@ module.exports = function generateConfig(configOverrides) { const defaultConfig = { sitecoreApiKey: 'no-api-key-set', sitecoreApiHost: '', - jssAppName: 'Unknown', + siteName: 'Unknown', layoutServiceConfigurationName: 'default', }; @@ -45,7 +45,9 @@ const config = {};\n`; // Set base configuration values, allowing override with environment variables Object.keys(config).forEach((prop) => { - configText += `config.${prop} = process.env.VUE_APP_${constantCase(prop)} || "${config[prop]}",\n`; + configText += `config.${prop} = process.env.VUE_APP_${constantCase(prop)} || "${ + config[prop] + }",\n`; }); // Set computed values, allowing override with environment variables Object.keys(computedConfig).forEach((prop) => { @@ -83,7 +85,7 @@ function transformPackageConfig() { if (!packageConfig.config) return {}; return { - jssAppName: packageConfig.config.appName, + siteName: packageConfig.config.appName, defaultLanguage: packageConfig.config.language || 'en', graphQLEndpointPath: packageConfig.config.graphQLEndpointPath || null, }; diff --git a/packages/create-sitecore-jss/src/templates/vue/server/server.js b/packages/create-sitecore-jss/src/templates/vue/server/server.js index 0f383384a5..64b90d1cc3 100644 --- a/packages/create-sitecore-jss/src/templates/vue/server/server.js +++ b/packages/create-sitecore-jss/src/templates/vue/server/server.js @@ -40,7 +40,7 @@ export const setUpDefaultAgents = (httpAgent, httpsAgent) => { export const apiKey = config.sitecoreApiKey; /** Export the app name. This will be used by default in Headless mode, removing the need to manually configure the app name on the proxy. */ -export const appName = config.jssAppName; +export const appName = config.siteName; /** * Main entry point to the application when run via Server-Side Rendering, diff --git a/packages/create-sitecore-jss/src/templates/vue/src/lib/dictionary-service-factory.js b/packages/create-sitecore-jss/src/templates/vue/src/lib/dictionary-service-factory.js index 71dd6106b1..75f4c65d94 100644 --- a/packages/create-sitecore-jss/src/templates/vue/src/lib/dictionary-service-factory.js +++ b/packages/create-sitecore-jss/src/templates/vue/src/lib/dictionary-service-factory.js @@ -1,4 +1,8 @@ -import { GraphQLDictionaryService, RestDictionaryService, constants } from '@sitecore-jss/sitecore-jss-vue'; +import { + GraphQLDictionaryService, + RestDictionaryService, + constants, +} from '@sitecore-jss/sitecore-jss-vue'; import config from '../temp/config'; export class DictionaryServiceFactory { @@ -7,7 +11,7 @@ export class DictionaryServiceFactory { ? new GraphQLDictionaryService({ endpoint: config.graphQLEndpoint, apiKey: config.sitecoreApiKey, - siteName: config.jssAppName, + siteName: config.siteName, /* The Dictionary Service needs a root item ID in order to fetch dictionary phrases for the current app. If your Sitecore instance only has 1 JSS App, you can specify the root item ID here; @@ -18,7 +22,7 @@ export class DictionaryServiceFactory { : new RestDictionaryService({ apiHost: config.sitecoreApiHost, apiKey: config.sitecoreApiKey, - siteName: config.jssAppName, + siteName: config.siteName, }); } } diff --git a/packages/create-sitecore-jss/src/templates/vue/src/lib/layout-service-factory.js b/packages/create-sitecore-jss/src/templates/vue/src/lib/layout-service-factory.js index a591ff8526..47153c479b 100644 --- a/packages/create-sitecore-jss/src/templates/vue/src/lib/layout-service-factory.js +++ b/packages/create-sitecore-jss/src/templates/vue/src/lib/layout-service-factory.js @@ -7,12 +7,12 @@ export class LayoutServiceFactory { ? new GraphQLLayoutService({ endpoint: config.graphQLEndpoint, apiKey: config.sitecoreApiKey, - siteName: config.jssAppName, + siteName: config.siteName, }) : new RestLayoutService({ apiHost: config.sitecoreApiHost, apiKey: config.sitecoreApiKey, - siteName: config.jssAppName, + siteName: config.siteName, configurationName: config.layoutServiceConfigurationName, }); } From 33422027ced8f90611cf12051d3e8b60c9ce1af3 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Tue, 31 Oct 2023 14:53:50 +0200 Subject: [PATCH 05/12] Rename jssAppName to siteName variables in proxy apps templates --- .../node-headless-ssr-experience-edge/.env | 2 +- .../node-headless-ssr-experience-edge/README.md | 16 ++++++++-------- .../src/config.ts | 6 +++--- .../src/index.ts | 4 ++-- .../src/types.ts | 4 ++-- .../src/templates/node-headless-ssr-proxy/.env | 2 +- .../node-headless-ssr-proxy/src/config.ts | 10 +++++----- .../src/templates/react/server/server.js | 2 +- .../src/templates/vue/server/server.js | 2 +- packages/sitecore-jss-proxy/src/ProxyConfig.ts | 2 +- .../sitecore-jss-proxy/src/test/config.test.ts | 2 +- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/.env b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/.env index 41686b6728..05c713d085 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/.env +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/.env @@ -1,4 +1,4 @@ -SITECORE_JSS_APP_NAME= +SITECORE_SITE_NAME= SITECORE_JSS_SERVER_BUNDLE= SITECORE_EXPERIENCE_EDGE_ENDPOINT= SITECORE_API_KEY= diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/README.md b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/README.md index 4a4c242084..6f8c90db72 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/README.md +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/README.md @@ -36,14 +36,14 @@ Open `config.js` and specify your application bundle and connection settings. The following environment variables can be set to configure the SSR sample instead of modifying `config.js`. You can use the `.env` file located in the root of the app or set these directly in the environment (for example, in containers). -| Parameter | Description | -| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `SITECORE_JSS_APP_NAME` | The JSS app's name. Used when request layout data and dictionary using graphql query and the default value of `SITECORE_JSS_SERVER_BUNDLE` if it's not set. | -| `SITECORE_API_KEY` | The API key provisioned on Sitecore Experience Edge. | -| `SITECORE_JSS_SERVER_BUNDLE` | Path to the JSS app's `server.bundle.js` file. | -| `SITECORE_EXPERIENCE_EDGE_ENDPOINT` | Sitecore Experience Edge endpoint. | -| `DEFAULT_LANGUAGE` | The JSS app's default language. Used to determine language context in case language is not specified in request URL. | -| `PORT` | Optional. Port which will be used when start sample. Default can be seen in [config.js](./config.js). | +| Parameter | Description | +| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `SITECORE_SITE_NAME` | The sitecore site's name. Used when request layout data and dictionary using graphql query and the default value of `SITECORE_JSS_SERVER_BUNDLE` if it's not set. | +| `SITECORE_API_KEY` | The API key provisioned on Sitecore Experience Edge. | +| `SITECORE_JSS_SERVER_BUNDLE` | Path to the JSS app's `server.bundle.js` file. | +| `SITECORE_EXPERIENCE_EDGE_ENDPOINT` | Sitecore Experience Edge endpoint. | +| `DEFAULT_LANGUAGE` | The JSS app's default language. Used to determine language context in case language is not specified in request URL. | +| `PORT` | Optional. Port which will be used when start sample. Default can be seen in [config.js](./config.js). | ## Build & run diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts index fb5896d8c4..8f17d3a522 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts @@ -1,11 +1,11 @@ import { Config, ServerBundle } from './types'; -const appName = process.env.SITECORE_JSS_APP_NAME; +const siteName = process.env.SITECORE_SITE_NAME; /** * The server.bundle.js file from your pre-built JSS app */ -const bundlePath = process.env.SITECORE_JSS_SERVER_BUNDLE || `../dist/${appName}/server.bundle`; +const bundlePath = process.env.SITECORE_JSS_SERVER_BUNDLE || `../dist/${siteName}/server.bundle`; const serverBundle: ServerBundle = require(bundlePath); @@ -29,7 +29,7 @@ export const config: Config = { * The JSS application name defaults to providing part of the bundle path. * If not passed as an environment variable or set here, any application name exported from the bundle will be used instead. */ - appName: appName || serverBundle.appName, + siteName: siteName || serverBundle.siteName, /** * Port which will be used when start sample */ diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/index.ts b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/index.ts index 0083857b3a..9b82e12485 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/index.ts +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/index.ts @@ -10,13 +10,13 @@ const server = express(); const layoutService = new GraphQLLayoutService({ endpoint: config.endpoint, apiKey: config.apiKey, - siteName: config.appName, + siteName: config.siteName, }); const dictionaryService = new GraphQLDictionaryService({ endpoint: config.endpoint, apiKey: config.apiKey, - siteName: config.appName, + siteName: config.siteName, /* The Dictionary Service needs a root item ID in order to fetch dictionary phrases for the current app. If your Sitecore instance only has 1 JSS App, you can specify the root item ID here; diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/types.ts b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/types.ts index 739de89aaa..84732c52a8 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/types.ts +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/types.ts @@ -40,7 +40,7 @@ declare type RouteUrlParser = ( export interface ServerBundle { renderView: AppRenderer; parseRouteUrl: RouteUrlParser; - appName: string; + siteName: string; apiKey?: string; } @@ -48,7 +48,7 @@ export interface Config { [key: string]: unknown; endpoint: string; apiKey: string; - appName: string; + siteName: string; port: string | number; defaultLanguage: string; serverBundle: ServerBundle; diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/.env b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/.env index b3ed3be246..263a28af6b 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/.env +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/.env @@ -1,4 +1,4 @@ -SITECORE_JSS_APP_NAME= +SITECORE_SITE_NAME= SITECORE_JSS_SERVER_BUNDLE= SITECORE_API_HOST= SITECORE_API_KEY= diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts index d2606bf1e1..f7cec3f697 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts @@ -4,16 +4,16 @@ import { RestDictionaryService } from '@sitecore-jss/sitecore-jss/i18n'; import { httpAgentsConfig } from './httpAgents'; /** - * The JSS application name defaults to providing part of the bundle path as well as the dictionary service endpoint. + * The sitecore site name defaults to providing part of the bundle path as well as the dictionary service endpoint. * If not passed as an environment variable or set here, any application name exported from the bundle will be used instead. */ -let appName = process.env.SITECORE_JSS_APP_NAME || 'YOUR APP NAME'; +let siteName = process.env.SITECORE_SITE_NAME || 'YOUR SITE NAME'; /** * The server.bundle.js file from your pre-built JSS app */ -const bundlePath = process.env.SITECORE_JSS_SERVER_BUNDLE || `../dist/${appName}/server.bundle`; +const bundlePath = process.env.SITECORE_JSS_SERVER_BUNDLE || `../dist/${siteName}/server.bundle`; const serverBundle = require(bundlePath) as ServerBundle; @@ -21,13 +21,13 @@ httpAgentsConfig.setUpDefaultAgents(serverBundle); const apiHost = process.env.SITECORE_API_HOST || 'http://my.sitecore.host'; -appName = appName || serverBundle.appName; +siteName = siteName || serverBundle.siteName; const apiKey = process.env.SITECORE_API_KEY || serverBundle.apiKey || '{YOUR API KEY HERE}'; const dictionaryService = new RestDictionaryService({ apiHost, - siteName: appName, + siteName: siteName, apiKey, cacheTimeout: 60, }); diff --git a/packages/create-sitecore-jss/src/templates/react/server/server.js b/packages/create-sitecore-jss/src/templates/react/server/server.js index 88317ec75c..8a4c9c0c8e 100644 --- a/packages/create-sitecore-jss/src/templates/react/server/server.js +++ b/packages/create-sitecore-jss/src/templates/react/server/server.js @@ -40,7 +40,7 @@ export const setUpDefaultAgents = (httpAgent, httpsAgent) => { // Export app configuration; this will be used when this app runs in Headless mode (ie node-headless-ssr-experience-edge or node-headless-ssr-proxy) export const apiKey = config.sitecoreApiKey; -export const appName = config.siteName; +export const siteName = config.siteName; export const defaultLanguage = config.defaultLanguage; /** diff --git a/packages/create-sitecore-jss/src/templates/vue/server/server.js b/packages/create-sitecore-jss/src/templates/vue/server/server.js index 64b90d1cc3..ee031d42c5 100644 --- a/packages/create-sitecore-jss/src/templates/vue/server/server.js +++ b/packages/create-sitecore-jss/src/templates/vue/server/server.js @@ -40,7 +40,7 @@ export const setUpDefaultAgents = (httpAgent, httpsAgent) => { export const apiKey = config.sitecoreApiKey; /** Export the app name. This will be used by default in Headless mode, removing the need to manually configure the app name on the proxy. */ -export const appName = config.siteName; +export const siteName = config.siteName; /** * Main entry point to the application when run via Server-Side Rendering, diff --git a/packages/sitecore-jss-proxy/src/ProxyConfig.ts b/packages/sitecore-jss-proxy/src/ProxyConfig.ts index 053bd044a5..845810f8d9 100644 --- a/packages/sitecore-jss-proxy/src/ProxyConfig.ts +++ b/packages/sitecore-jss-proxy/src/ProxyConfig.ts @@ -19,7 +19,7 @@ export interface LayoutServiceData { /** Interface for the server.bundle.js file */ export interface ServerBundle { [key: string]: unknown; - appName: string; + siteName: string; apiKey: string; renderView: AppRenderer; parseRouteUrl: RouteUrlParser; diff --git a/packages/sitecore-jss-proxy/src/test/config.test.ts b/packages/sitecore-jss-proxy/src/test/config.test.ts index 0e936f34c0..fdabbcc183 100644 --- a/packages/sitecore-jss-proxy/src/test/config.test.ts +++ b/packages/sitecore-jss-proxy/src/test/config.test.ts @@ -17,7 +17,7 @@ const config: ProxyConfig = { lang: 'en', }; }, - appName: 'APP_NAME', + siteName: 'APP_NAME', apiKey: '{GUID}', }, }; From 8abba3032c3a3680ed5baba4f5d4f1aacafe0084 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Tue, 31 Oct 2023 15:32:50 +0200 Subject: [PATCH 06/12] additional jssAppName renamings --- .../src/templates/node-headless-ssr-experience-edge/README.md | 2 +- .../src/templates/node-headless-ssr-proxy/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/README.md b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/README.md index 6f8c90db72..67a9067f65 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/README.md +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/README.md @@ -24,7 +24,7 @@ This is a sample setup showing one of how you can configure rendering server on > You can use JSS sample apps which support server side rendering (JSS integrated mode) to operate with this project. -1. Deploy the build artifacts from your app (`/dist` or `/build` within the app) to the `sitecoreDistPath` set in your app's `package.json` under the SSR sample root path. Most apps use `/dist/${jssAppName}`, for example `$ssrSampleRoot/dist/${jssAppName}`. +1. Deploy the build artifacts from your app (`/dist` or `/build` within the app) to the `sitecoreDistPath` set in your app's `package.json` under the SSR sample root path. Most apps use `/dist/${siteName}`, for example `$ssrSampleRoot/dist/${siteName}`. > Another way to deploy the artifacts to the SSR sample is to change the `instancePath` in your app's `scjssconfig.json` to the SSR sample root path, and then use `jss deploy files` within the app to complete the deployment to the SSR sample. diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/README.md b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/README.md index ef6b0f0cf2..390d0cb888 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/README.md +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/README.md @@ -24,7 +24,7 @@ You can use this as a starting point to unlock deployment of your JSS apps to an > You can use any of the JSS sample apps. Other apps must support server side rendering (JSS integrated mode) to operate with this project. -1. Deploy the build artifacts from your app (`/dist` or `/build` within the app) to the `sitecoreDistPath` set in your app's `package.json` under the proxy root path. Most apps use `/dist/${jssAppName}`, for example `$proxyRoot/dist/${jssAppName}`. +1. Deploy the build artifacts from your app (`/dist` or `/build` within the app) to the `sitecoreDistPath` set in your app's `package.json` under the proxy root path. Most apps use `/dist/${siteName}`, for example `$proxyRoot/dist/${siteName}`. > Another way to deploy the artifacts to the proxy is to change the `instancePath` in your app's `scjssconfig.json` to the proxy root path, and then use `jss deploy files` within the app to complete the deployment to the proxy. From 363181cbc6bd37bfea07f925c0fe81105e264ca8 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Tue, 31 Oct 2023 16:23:04 +0200 Subject: [PATCH 07/12] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2037947bf2..a868f9d4a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Our versioning strategy is as follows: ### 🎉 New Features & Improvements +* `[templates/react]` `[templates/angular]` `[templates/vue]` `[templates/node-headless-ssr-proxy]` `[templates/node-headless-ssr-experience-edge]` ([#1647](https://github.com/Sitecore/jss/pull/1647)) Switch from using JSS_APP_NAME to SITE_NAME - environment and config variables in React, Vue, Angular templates as well as ssr node proxy apps templates have been renamed. * `[templates/nextjs]` `[sitecore-jss-nextjs]` `[sitecore-jss]` ([#1640](https://github.com/Sitecore/jss/pull/1640)) Sitecore Edge Platform and Context support: * Introducing the _clientFactory_ property. This property can be utilized by GraphQL-based services, the previously used _endpoint_ and _apiKey_ properties are deprecated. The _clientFactory_ serves as the central hub for executing GraphQL requests within the application. * New SITECORE_EDGE_CONTEXT_ID environment variable has been added. From 866740d55554dd2e11b4a6a0b97fe4a5bee6b684 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Thu, 2 Nov 2023 10:10:49 +0200 Subject: [PATCH 08/12] ensure backwards compatibility of jssAppName to siteName renamings --- .../angular/scripts/generate-config.ts | 15 +++++++++++++-- .../src/config.ts | 2 +- .../node-headless-ssr-proxy/src/config.ts | 3 ++- .../react/scripts/generate-config.js | 4 +++- .../templates/vue/scripts/generate-config.js | 19 +++++++++++++++---- .../sitecore-jss-proxy/src/ProxyConfig.ts | 1 + 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts index 70f39765b2..5a1c66b720 100644 --- a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts +++ b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts @@ -15,7 +15,8 @@ export function generateConfig(configOverrides?: { [key: string]: unknown }, out production: false, sitecoreApiHost: '', sitecoreApiKey: 'no-api-key-set', - siteName: 'Unknown', + jssAppName: 'Unknown', + siteName: '', sitecoreLayoutServiceConfig: 'jss', defaultLanguage: 'en', defaultServerRoute: '/', @@ -38,6 +39,9 @@ export function generateConfig(configOverrides?: { [key: string]: unknown }, out // and finally config passed in the configOverrides param wins. const config = Object.assign(defaultConfig, scjssConfig, packageJson, configOverrides); + // for the sake of backwards compatibility - make sure to initialize siteName + config.siteName = config.siteName || config.jssAppName; + // The GraphQL endpoint is an example of making a _computed_ config setting // based on other config settings. const computedConfig: { [key: string]: string } = {}; @@ -50,7 +54,14 @@ const config = {};\n`; // Set base configuration values, allowing override with environment variables Object.keys(config).forEach((prop) => { - configText += `config.${prop} = process.env.${constantCase(prop)} || "${config[prop]}",\n`; + if (prop === 'siteName') { + // for the sake of backwards compatibility - make sure to initialize siteName from jssAppName if necessary + configText += `config.${prop} = process.env.${constantCase(prop)} || "${ + config[prop] + } || process.env.${constantCase('jssAppName')} || "${config.jssAppName}",\n`; + } else { + configText += `config.${prop} = process.env.${constantCase(prop)} || "${config[prop]}",\n`; + } }); // Set computed values, allowing override with environment variables Object.keys(computedConfig).forEach((prop) => { diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts index 8f17d3a522..c0f99fd447 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts @@ -1,5 +1,5 @@ import { Config, ServerBundle } from './types'; -const siteName = process.env.SITECORE_SITE_NAME; +const siteName = process.env.SITECORE_SITE_NAME || process.env.SITECORE_JSS_APP_NAME; /** * The server.bundle.js file from your pre-built JSS app diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts index f7cec3f697..f1df4dbaff 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts @@ -7,7 +7,8 @@ import { httpAgentsConfig } from './httpAgents'; * The sitecore site name defaults to providing part of the bundle path as well as the dictionary service endpoint. * If not passed as an environment variable or set here, any application name exported from the bundle will be used instead. */ -let siteName = process.env.SITECORE_SITE_NAME || 'YOUR SITE NAME'; +let siteName = + process.env.SITECORE_SITE_NAME || process.env.SITECORE_JSS_APP_NAME || 'YOUR SITE NAME'; /** * The server.bundle.js file from your pre-built JSS app diff --git a/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js b/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js index bb92ce667c..3f87a7fed9 100644 --- a/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js +++ b/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js @@ -12,7 +12,9 @@ const { jssConfigFactory } = require('./config'); const defaultConfig = { sitecoreApiKey: process.env[`${constantCase('reactAppSitecoreApiKey')}`], sitecoreApiHost: process.env[`${constantCase('reactAppSitecoreApiHost')}`], - siteName: process.env[`${constantCase('reactAppSiteName')}`], + siteName: + process.env[`${constantCase('reactAppSiteName')}`] || + process.env[`${constantCase('reactAppJssAppName')}`], graphQLEndpointPath: process.env[`${constantCase('reactAppGraphQLEndpointPath')}`], defaultLanguage: process.env[`${constantCase('reactAppDefaultLanguage')}`], graphQLEndpoint: process.env[`${constantCase('reactAppGraphQLEndpoint')}`], diff --git a/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js b/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js index 608a8219e5..b6fa35cc23 100644 --- a/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js +++ b/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js @@ -17,7 +17,8 @@ module.exports = function generateConfig(configOverrides) { const defaultConfig = { sitecoreApiKey: 'no-api-key-set', sitecoreApiHost: '', - siteName: 'Unknown', + jssAppName: 'Unknown', + siteName: '', layoutServiceConfigurationName: 'default', }; @@ -33,6 +34,9 @@ module.exports = function generateConfig(configOverrides) { // and finally config passed in the configOverrides param wins. const config = Object.assign(defaultConfig, scjssConfig, packageJson, configOverrides); + // for the sake of backwards compatibility - make sure to initialize siteName + config.siteName = config.siteName || config.jssAppName; + // The GraphQL endpoint is an example of making a _computed_ config setting // based on other config settings. const computedConfig = {}; @@ -45,9 +49,16 @@ const config = {};\n`; // Set base configuration values, allowing override with environment variables Object.keys(config).forEach((prop) => { - configText += `config.${prop} = process.env.VUE_APP_${constantCase(prop)} || "${ - config[prop] - }",\n`; + if (prop === 'siteName') { + // for the sake of backwards compatibility - make sure to initialize siteName from jssAppName if necessary + configText += `config.${prop} = process.env.VUE_APP_${constantCase(prop)} || "${ + config[prop] + } || process.env.VUE_APP_JSS_APP_NAME || ${config.jssAppName}",\n`; + } else { + configText += `config.${prop} = process.env.VUE_APP_${constantCase('jssAppName')} || "${ + config[prop] + }",\n`; + } }); // Set computed values, allowing override with environment variables Object.keys(computedConfig).forEach((prop) => { diff --git a/packages/sitecore-jss-proxy/src/ProxyConfig.ts b/packages/sitecore-jss-proxy/src/ProxyConfig.ts index 845810f8d9..9c468d3af8 100644 --- a/packages/sitecore-jss-proxy/src/ProxyConfig.ts +++ b/packages/sitecore-jss-proxy/src/ProxyConfig.ts @@ -19,6 +19,7 @@ export interface LayoutServiceData { /** Interface for the server.bundle.js file */ export interface ServerBundle { [key: string]: unknown; + appName: string; siteName: string; apiKey: string; renderView: AppRenderer; From 241f56a5877dfe7e630c43cc0aad95716922f435 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Fri, 3 Nov 2023 10:10:27 +0200 Subject: [PATCH 09/12] fix small bug, simplify code by initializing siteName and jssAppName in defaultConfig --- .../angular/scripts/generate-config.ts | 13 +++---------- .../templates/vue/scripts/generate-config.js | 17 +++++------------ 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts index 5a1c66b720..05ef1b6cf0 100644 --- a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts +++ b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts @@ -15,8 +15,8 @@ export function generateConfig(configOverrides?: { [key: string]: unknown }, out production: false, sitecoreApiHost: '', sitecoreApiKey: 'no-api-key-set', - jssAppName: 'Unknown', - siteName: '', + jssAppName: process.env.JSS_APP_NAME, + siteName: process.env.SITE_NAME, sitecoreLayoutServiceConfig: 'jss', defaultLanguage: 'en', defaultServerRoute: '/', @@ -54,14 +54,7 @@ const config = {};\n`; // Set base configuration values, allowing override with environment variables Object.keys(config).forEach((prop) => { - if (prop === 'siteName') { - // for the sake of backwards compatibility - make sure to initialize siteName from jssAppName if necessary - configText += `config.${prop} = process.env.${constantCase(prop)} || "${ - config[prop] - } || process.env.${constantCase('jssAppName')} || "${config.jssAppName}",\n`; - } else { - configText += `config.${prop} = process.env.${constantCase(prop)} || "${config[prop]}",\n`; - } + configText += `config.${prop} = process.env.${constantCase(prop)} || "${config[prop]}",\n`; }); // Set computed values, allowing override with environment variables Object.keys(computedConfig).forEach((prop) => { diff --git a/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js b/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js index b6fa35cc23..a4da5c4aab 100644 --- a/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js +++ b/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js @@ -17,8 +17,8 @@ module.exports = function generateConfig(configOverrides) { const defaultConfig = { sitecoreApiKey: 'no-api-key-set', sitecoreApiHost: '', - jssAppName: 'Unknown', - siteName: '', + jssAppName: process.env.VUE_APP_JSS_APP_NAME, + siteName: process.env.VUE_APP_SITE_NAME, layoutServiceConfigurationName: 'default', }; @@ -49,16 +49,9 @@ const config = {};\n`; // Set base configuration values, allowing override with environment variables Object.keys(config).forEach((prop) => { - if (prop === 'siteName') { - // for the sake of backwards compatibility - make sure to initialize siteName from jssAppName if necessary - configText += `config.${prop} = process.env.VUE_APP_${constantCase(prop)} || "${ - config[prop] - } || process.env.VUE_APP_JSS_APP_NAME || ${config.jssAppName}",\n`; - } else { - configText += `config.${prop} = process.env.VUE_APP_${constantCase('jssAppName')} || "${ - config[prop] - }",\n`; - } + configText += `config.${prop} = process.env.VUE_APP_${constantCase(prop)} || "${ + config[prop] + }",\n`; }); // Set computed values, allowing override with environment variables Object.keys(computedConfig).forEach((prop) => { From 8b551c73e76451b071a6daa13dd7781efd671765 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Fri, 3 Nov 2023 11:10:38 +0200 Subject: [PATCH 10/12] added comments in templates that jssAppName env variables have been deprecated --- .../src/templates/angular/scripts/generate-config.ts | 1 + .../src/templates/nextjs/scripts/generate-config.ts | 8 ++++---- .../node-headless-ssr-experience-edge/src/config.ts | 2 ++ .../src/templates/node-headless-ssr-proxy/src/config.ts | 1 + .../src/templates/react/scripts/generate-config.js | 1 + .../src/templates/vue/scripts/generate-config.js | 1 + 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts index 05ef1b6cf0..add2e1abad 100644 --- a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts +++ b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts @@ -10,6 +10,7 @@ const packageConfig = require('../package.json'); * settings as variables into the JSS app. * NOTE! Any configs returned here will be written into the client-side JS bundle. DO NOT PUT SECRETS HERE. */ +// JSS_APP_NAME env variable has been depracated since v.21.6, SITE_NAME should be used instead export function generateConfig(configOverrides?: { [key: string]: unknown }, outputPath?: string) { const defaultConfig = { production: false, diff --git a/packages/create-sitecore-jss/src/templates/nextjs/scripts/generate-config.ts b/packages/create-sitecore-jss/src/templates/nextjs/scripts/generate-config.ts index 67c7c5b0f8..697e3d55ad 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs/scripts/generate-config.ts +++ b/packages/create-sitecore-jss/src/templates/nextjs/scripts/generate-config.ts @@ -10,7 +10,7 @@ import { jssConfigFactory } from './config'; Generates the /src/temp/config.js file which contains runtime configuration that the app can import and use. */ - +// JSS_APP_NAME env variable has been depracated since v.21.6, SITE_NAME should be used instead const defaultConfig: JssConfig = { sitecoreApiKey: process.env[`${constantCase('sitecoreApiKey')}`], sitecoreApiHost: process.env[`${constantCase('sitecoreApiHost')}`], @@ -34,10 +34,10 @@ generateConfig(defaultConfig); function generateConfig(defaultConfig: JssConfig): void { jssConfigFactory .create(defaultConfig) - .then((config) => { + .then(config => { writeConfig(config); }) - .catch((e) => { + .catch(e => { console.error('Error generating config'); console.error(e); process.exit(1); @@ -55,7 +55,7 @@ function writeConfig(config: JssConfig): void { const config = {};\n`; // Set configuration values, allowing override with environment variables - Object.keys(config).forEach((prop) => { + Object.keys(config).forEach(prop => { configText += `config.${prop} = process.env.${constantCase(prop)} || '${config[prop]}',\n`; }); configText += `module.exports = config;`; diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts index c0f99fd447..759bb94893 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts @@ -1,4 +1,6 @@ import { Config, ServerBundle } from './types'; + +// SITECORE_JSS_APP_NAME env variable has been depracated since v.21.6, SITECORE_SITE_NAME should be used instead const siteName = process.env.SITECORE_SITE_NAME || process.env.SITECORE_JSS_APP_NAME; /** diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts index f1df4dbaff..af600356ab 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts @@ -7,6 +7,7 @@ import { httpAgentsConfig } from './httpAgents'; * The sitecore site name defaults to providing part of the bundle path as well as the dictionary service endpoint. * If not passed as an environment variable or set here, any application name exported from the bundle will be used instead. */ +// SITECORE_JSS_APP_NAME env variable has been depracated since v.21.6, SITECORE_SITE_NAME should be used instead let siteName = process.env.SITECORE_SITE_NAME || process.env.SITECORE_JSS_APP_NAME || 'YOUR SITE NAME'; diff --git a/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js b/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js index 3f87a7fed9..27c5fe66f2 100644 --- a/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js +++ b/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js @@ -9,6 +9,7 @@ const { jssConfigFactory } = require('./config'); /** * REACT_APP is the default prefix for environment variables that will be made available to the app. */ +// REACT_APP_JSS_APP_NAME env variable has been depracated since v.21.6, REACT_APP_SITE_NAME should be used instead const defaultConfig = { sitecoreApiKey: process.env[`${constantCase('reactAppSitecoreApiKey')}`], sitecoreApiHost: process.env[`${constantCase('reactAppSitecoreApiHost')}`], diff --git a/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js b/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js index a4da5c4aab..4e1689e968 100644 --- a/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js +++ b/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js @@ -13,6 +13,7 @@ const packageConfig = require('../package.json'); * NOTE! Any configs returned here will be written into the client-side JS bundle. DO NOT PUT SECRETS HERE. * @param {object} configOverrides Keys in this object will override any equivalent global config keys. */ +// VUE_APP_JSS_APP_NAME env variable has been depracated since v.21.6, VUE_APP_SITE_NAME should be used instead module.exports = function generateConfig(configOverrides) { const defaultConfig = { sitecoreApiKey: 'no-api-key-set', From 3cc7e2046d86a4423513368f93ecb570de25c2e0 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Fri, 3 Nov 2023 15:58:22 +0200 Subject: [PATCH 11/12] fix typos in comments --- .../src/templates/angular/scripts/generate-config.ts | 2 +- .../src/templates/nextjs/scripts/generate-config.ts | 2 +- .../templates/node-headless-ssr-experience-edge/src/config.ts | 2 +- .../src/templates/node-headless-ssr-proxy/src/config.ts | 2 +- .../src/templates/react/scripts/generate-config.js | 2 +- .../src/templates/vue/scripts/generate-config.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts index add2e1abad..a83e6b8b9b 100644 --- a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts +++ b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts @@ -10,7 +10,7 @@ const packageConfig = require('../package.json'); * settings as variables into the JSS app. * NOTE! Any configs returned here will be written into the client-side JS bundle. DO NOT PUT SECRETS HERE. */ -// JSS_APP_NAME env variable has been depracated since v.21.6, SITE_NAME should be used instead +// JSS_APP_NAME env variable has been deprecated since v.21.6, SITE_NAME should be used instead export function generateConfig(configOverrides?: { [key: string]: unknown }, outputPath?: string) { const defaultConfig = { production: false, diff --git a/packages/create-sitecore-jss/src/templates/nextjs/scripts/generate-config.ts b/packages/create-sitecore-jss/src/templates/nextjs/scripts/generate-config.ts index 697e3d55ad..2369bc8f87 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs/scripts/generate-config.ts +++ b/packages/create-sitecore-jss/src/templates/nextjs/scripts/generate-config.ts @@ -10,7 +10,7 @@ import { jssConfigFactory } from './config'; Generates the /src/temp/config.js file which contains runtime configuration that the app can import and use. */ -// JSS_APP_NAME env variable has been depracated since v.21.6, SITE_NAME should be used instead +// JSS_APP_NAME env variable has been deprecated since v.21.6, SITE_NAME should be used instead const defaultConfig: JssConfig = { sitecoreApiKey: process.env[`${constantCase('sitecoreApiKey')}`], sitecoreApiHost: process.env[`${constantCase('sitecoreApiHost')}`], diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts index 759bb94893..38ce65b885 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/src/config.ts @@ -1,6 +1,6 @@ import { Config, ServerBundle } from './types'; -// SITECORE_JSS_APP_NAME env variable has been depracated since v.21.6, SITECORE_SITE_NAME should be used instead +// SITECORE_JSS_APP_NAME env variable has been deprecated since v.21.6, SITECORE_SITE_NAME should be used instead const siteName = process.env.SITECORE_SITE_NAME || process.env.SITECORE_JSS_APP_NAME; /** diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts index af600356ab..4521deacf7 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts @@ -7,7 +7,7 @@ import { httpAgentsConfig } from './httpAgents'; * The sitecore site name defaults to providing part of the bundle path as well as the dictionary service endpoint. * If not passed as an environment variable or set here, any application name exported from the bundle will be used instead. */ -// SITECORE_JSS_APP_NAME env variable has been depracated since v.21.6, SITECORE_SITE_NAME should be used instead +// SITECORE_JSS_APP_NAME env variable has been deprecated since v.21.6, SITECORE_SITE_NAME should be used instead let siteName = process.env.SITECORE_SITE_NAME || process.env.SITECORE_JSS_APP_NAME || 'YOUR SITE NAME'; diff --git a/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js b/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js index 27c5fe66f2..534fe7d4b0 100644 --- a/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js +++ b/packages/create-sitecore-jss/src/templates/react/scripts/generate-config.js @@ -9,7 +9,7 @@ const { jssConfigFactory } = require('./config'); /** * REACT_APP is the default prefix for environment variables that will be made available to the app. */ -// REACT_APP_JSS_APP_NAME env variable has been depracated since v.21.6, REACT_APP_SITE_NAME should be used instead +// REACT_APP_JSS_APP_NAME env variable has been deprecated since v.21.6, REACT_APP_SITE_NAME should be used instead const defaultConfig = { sitecoreApiKey: process.env[`${constantCase('reactAppSitecoreApiKey')}`], sitecoreApiHost: process.env[`${constantCase('reactAppSitecoreApiHost')}`], diff --git a/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js b/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js index 4e1689e968..f55b291773 100644 --- a/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js +++ b/packages/create-sitecore-jss/src/templates/vue/scripts/generate-config.js @@ -13,7 +13,7 @@ const packageConfig = require('../package.json'); * NOTE! Any configs returned here will be written into the client-side JS bundle. DO NOT PUT SECRETS HERE. * @param {object} configOverrides Keys in this object will override any equivalent global config keys. */ -// VUE_APP_JSS_APP_NAME env variable has been depracated since v.21.6, VUE_APP_SITE_NAME should be used instead +// VUE_APP_JSS_APP_NAME env variable has been deprecated since v.21.6, VUE_APP_SITE_NAME should be used instead module.exports = function generateConfig(configOverrides) { const defaultConfig = { sitecoreApiKey: 'no-api-key-set', From d5b0aa3e31b8f05633d00c8dd76b40a22b67ef74 Mon Sep 17 00:00:00 2001 From: yavorsk Date: Fri, 3 Nov 2023 16:57:56 +0200 Subject: [PATCH 12/12] fix test build error --- packages/sitecore-jss-proxy/src/test/config.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/sitecore-jss-proxy/src/test/config.test.ts b/packages/sitecore-jss-proxy/src/test/config.test.ts index fdabbcc183..ba2faff79e 100644 --- a/packages/sitecore-jss-proxy/src/test/config.test.ts +++ b/packages/sitecore-jss-proxy/src/test/config.test.ts @@ -17,6 +17,7 @@ const config: ProxyConfig = { lang: 'en', }; }, + appName: 'APP_NAME', siteName: 'APP_NAME', apiKey: '{GUID}', },