From 52d948d8904ad0b9988d64420f06be3e65631633 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 9 Apr 2024 12:20:41 +0200 Subject: [PATCH] app-backend: update meta tag injection to be able to update existing tag Signed-off-by: Patrik Oldsberg --- plugins/app-backend/src/service/router.ts | 31 +++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/plugins/app-backend/src/service/router.ts b/plugins/app-backend/src/service/router.ts index f58091f762..86736d832e 100644 --- a/plugins/app-backend/src/service/router.ts +++ b/plugins/app-backend/src/service/router.ts @@ -257,20 +257,23 @@ async function injectAppMode(options: { rootDir: string; }) { const { appMode, rootDir } = options; - const originalIndexHtmlContent = await fs.readFile( - resolvePath(rootDir, 'index.html'), - 'utf8', - ); - if (originalIndexHtmlContent.includes('backstage-app-mode')) return; - const modifiedIndexHtmlContent = originalIndexHtmlContent.replace( - //, - ``, - ); - await fs.writeFile( - resolvePath(rootDir, 'index.html'), - modifiedIndexHtmlContent, - 'utf8', - ); + const content = await fs.readFile(resolvePath(rootDir, 'index.html'), 'utf8'); + + const metaTag = ``; + + let newContent; + if (content.includes('backstage-app-mode')) { + console.log(`DEBUG: REPLACE`, metaTag); + newContent = content.replace( + //, + metaTag, + ); + console.log(`DEBUG: newContent=`, newContent); + } else { + newContent = content.replace(//, `${metaTag}`); + } + + await fs.writeFile(resolvePath(rootDir, 'index.html'), newContent, 'utf8'); } async function createEntryPointRouter({