From 8c99aa4b9d8f0047842d44adca4d46bbf45bbafd Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sun, 17 Nov 2024 23:50:49 +0100 Subject: [PATCH] gererate diffrent comment depending on the file type --- ...etUiModuleFileSourceCodeReadyToBeCopied.ts | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/bin/postinstall/getUiModuleFileSourceCodeReadyToBeCopied.ts b/src/bin/postinstall/getUiModuleFileSourceCodeReadyToBeCopied.ts index 7c63acb0..69b4c3cc 100644 --- a/src/bin/postinstall/getUiModuleFileSourceCodeReadyToBeCopied.ts +++ b/src/bin/postinstall/getUiModuleFileSourceCodeReadyToBeCopied.ts @@ -32,29 +32,37 @@ export async function getUiModuleFileSourceCodeReadyToBeCopied(params: { await fsPr.readFile(pathJoin(uiModuleDirPath, KEYCLOAK_THEME, fileRelativePath)) ).toString("utf8"); - const comment = (() => { - if (isForEjection) { - return [ - `/*`, - ` * This file was ejected from ${uiModuleName} version ${uiModuleVersion}.`, - ` */` - ].join("\n"); - } else { - return [ - `/*`, - ` *`, - ` * WARNING: Before modifying this file run the following command:`, - ` * `, - ` * $ npx keycloakify eject-file --file ${fileRelativePath.split(pathSep).join("/")}`, - ` * `, - ` * This file comes from ${uiModuleName} version ${uiModuleVersion}.`, - ` *`, - ` */` - ].join("\n"); - } - })(); + const toComment = (lines: string[]) => { + for (const ext of [".ts", ".tsx", ".css", ".less", ".sass", ".js", ".jsx"]) { + if (!fileRelativePath.endsWith(ext)) { + continue; + } - sourceCode = [comment, ``, sourceCode].join("\n"); + return [`/**`, ...lines.map(line => ` * ${line}`), ` */`].join("\n"); + } + + if (fileRelativePath.endsWith(".html")) { + return [``].join("\n"); + } + + return undefined; + }; + + const comment = toComment( + isForEjection + ? [`This file was ejected from ${uiModuleName} version ${uiModuleVersion}.`] + : [ + `WARNING: Before modifying this file run the following command:`, + ``, + `$ npx keycloakify eject-file --file ${fileRelativePath.split(pathSep).join("/")}`, + ``, + `This file comes from ${uiModuleName} version ${uiModuleVersion}.` + ] + ); + + if (comment !== undefined) { + sourceCode = [comment, ``, sourceCode].join("\n"); + } const destFilePath = pathJoin(buildContext.themeSrcDirPath, fileRelativePath);