From 5fdc8df0e81320f0ac20aa597b311b671a8847fc Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 19 Dec 2021 13:46:14 +0100 Subject: [PATCH] cli: make config available in index.html template Signed-off-by: Patrik Oldsberg --- .changeset/nice-feet-hope.md | 30 ++++++++++++++ .changeset/purple-grapes-kick.md | 15 +++++++ .changeset/soft-scissors-own.md | 5 +++ packages/app/public/index.html | 24 ++++++----- packages/cli/src/lib/bundler/config.ts | 41 ++++++++++++------- .../packages/app/public/index.html | 12 +++--- .../embedded-techdocs-app/public/index.html | 2 +- 7 files changed, 97 insertions(+), 32 deletions(-) create mode 100644 .changeset/nice-feet-hope.md create mode 100644 .changeset/purple-grapes-kick.md create mode 100644 .changeset/soft-scissors-own.md diff --git a/.changeset/nice-feet-hope.md b/.changeset/nice-feet-hope.md new file mode 100644 index 0000000000..cfc660020f --- /dev/null +++ b/.changeset/nice-feet-hope.md @@ -0,0 +1,30 @@ +--- +'@backstage/create-app': patch +--- + +The `index.html` template of the app has been updated to use the new `config` global provided by the Backstage CLI. + +To apply this change to an existing app, make the following changes to `packages/app/public/index.html`: + +```diff +- <%= app.title %> ++ <%= config.getString('app.title') %> +``` + +```diff +- <% if (app.googleAnalyticsTrackingId && typeof app.googleAnalyticsTrackingId === 'string') { %> ++ <% if (config.has('app.googleAnalyticsTrackingId')) { %> + +``` + +```diff +- gtag('config', '<%= app.googleAnalyticsTrackingId %>'); ++ gtag( ++ 'config', ++ '<%= config.getString("app.googleAnalyticsTrackingId") %>', ++ ); +``` diff --git a/.changeset/purple-grapes-kick.md b/.changeset/purple-grapes-kick.md new file mode 100644 index 0000000000..9d64d4e17c --- /dev/null +++ b/.changeset/purple-grapes-kick.md @@ -0,0 +1,15 @@ +--- +'@backstage/cli': patch +--- + +The frontend configuration is now available as a `config` global during templating of the `index.html` file. This allows for much more flexibility as the values available during templating is not longer hardcoded to a fixed set of values. + +For example, to access the app title, you would now do the following: + +```html +<%= config.getString('app.title') %> +``` + +Along with this change, usage of the existing `app.` values has been deprecated and will be removed in a future release. The general pattern for migrating existing usage is to replace `<%= app. %>` with `<%= config.getString('app.') %>`, although in some cases you may need to use for example `config.has('app.')` or `config.getOptionalString('app.')` instead. + +The [`@backstage/create-app` changelog](https://github.com/backstage/backstage/blob/master/packages/create-app/CHANGELOG.md#049) also contains more details how to migrate existing usage. diff --git a/.changeset/soft-scissors-own.md b/.changeset/soft-scissors-own.md new file mode 100644 index 0000000000..e57a018d50 --- /dev/null +++ b/.changeset/soft-scissors-own.md @@ -0,0 +1,5 @@ +--- +'embedded-techdocs-app': patch +--- + +The `index.html` template was updated to use the new `config` global. diff --git a/packages/app/public/index.html b/packages/app/public/index.html index d86f09f0b0..8273576b01 100644 --- a/packages/app/public/index.html +++ b/packages/app/public/index.html @@ -47,13 +47,12 @@ min-height: 100%; } - <%= app.title %> + <%= config.getString('app.title') %> - <% if (app.googleAnalyticsTrackingId && typeof - app.googleAnalyticsTrackingId==='string' ) { %> + <% if (config.has('app.googleAnalyticsTrackingId')) { %> - <% } %> <% if (app.datadogRum.clientToken && app.datadogRum.applicationId ) - { %> + <% } %> <% if (config.has('app.datadogRum')) { %> <% } %> diff --git a/packages/embedded-techdocs-app/public/index.html b/packages/embedded-techdocs-app/public/index.html index a6102f010d..fb874df173 100644 --- a/packages/embedded-techdocs-app/public/index.html +++ b/packages/embedded-techdocs-app/public/index.html @@ -47,7 +47,7 @@ min-height: 100%; } - <%= app.title %> + <%= config.getString('app.title') %>