diff --git a/src/bin/shared/downloadKeycloakDefaultTheme.ts b/src/bin/shared/downloadKeycloakDefaultTheme.ts index 582515b6..6496890d 100644 --- a/src/bin/shared/downloadKeycloakDefaultTheme.ts +++ b/src/bin/shared/downloadKeycloakDefaultTheme.ts @@ -3,7 +3,6 @@ import { type BuildContext } from "./buildContext"; import { assert } from "tsafe/assert"; import { lastKeycloakVersionWithAccountV1 } from "./constants"; import { downloadAndExtractArchive } from "../tools/downloadAndExtractArchive"; -import { isInside } from "../tools/isInside"; export type BuildContextLike = { cacheDirPath: string; @@ -18,27 +17,25 @@ export async function downloadKeycloakDefaultTheme(params: { }): Promise<{ defaultThemeDirPath: string }> { const { keycloakVersion, buildContext } = params; + let kcNodeModulesKeepFilePaths: string[] | undefined = undefined; + let kcNodeModulesKeepFilePaths_lastAccountV1: string[] | undefined = undefined; + const { extractedDirPath } = await downloadAndExtractArchive({ url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`, cacheDirPath: buildContext.cacheDirPath, npmWorkspaceRootDirPath: buildContext.npmWorkspaceRootDirPath, uniqueIdOfOnOnArchiveFile: "downloadKeycloakDefaultTheme", onArchiveFile: async params => { - if (!isInside({ dirPath: "theme", filePath: params.fileRelativePath })) { + const fileRelativePath = pathRelative("theme", params.fileRelativePath); + + if (fileRelativePath.startsWith("..")) { return; } const { readFile, writeFile } = params; - const fileRelativePath = pathRelative("theme", params.fileRelativePath); - skip_keycloak_v2: { - if ( - !isInside({ - dirPath: pathJoin("keycloak.v2"), - filePath: fileRelativePath - }) - ) { + if (!fileRelativePath.startsWith(pathJoin("keycloak.v2"))) { break skip_keycloak_v2; } @@ -50,6 +47,84 @@ export async function downloadKeycloakDefaultTheme(params: { break last_account_v1_transformations; } + skip_web_modules: { + if ( + !fileRelativePath.startsWith( + pathJoin("keycloak", "common", "resources", "web_modules") + ) + ) { + break skip_web_modules; + } + + return; + } + + skip_lib: { + if ( + !fileRelativePath.startsWith( + pathJoin("keycloak", "common", "resources", "lib") + ) + ) { + break skip_lib; + } + + return; + } + + skip_node_modules: { + if ( + !fileRelativePath.startsWith( + pathJoin("keycloak", "common", "resources", "node_modules") + ) + ) { + break skip_node_modules; + } + + if (kcNodeModulesKeepFilePaths_lastAccountV1 === undefined) { + kcNodeModulesKeepFilePaths_lastAccountV1 = [ + pathJoin("patternfly", "dist", "css", "patternfly.min.css"), + pathJoin( + "patternfly", + "dist", + "css", + "patternfly-additions.min.css" + ), + pathJoin( + "patternfly", + "dist", + "fonts", + "OpenSans-Regular-webfont.woff2" + ), + pathJoin( + "patternfly", + "dist", + "fonts", + "OpenSans-Bold-webfont.woff2" + ), + pathJoin( + "patternfly", + "dist", + "fonts", + "OpenSans-Light-webfont.woff2" + ), + pathJoin( + "patternfly", + "dist", + "fonts", + "OpenSans-Semibold-webfont.woff2" + ) + ]; + } + + for (const keepPath of kcNodeModulesKeepFilePaths_lastAccountV1) { + if (fileRelativePath.endsWith(keepPath)) { + break skip_node_modules; + } + } + + return; + } + patch_account_css: { if ( fileRelativePath !== @@ -70,69 +145,6 @@ export async function downloadKeycloakDefaultTheme(params: { return; } - - skip_web_modules: { - if ( - !isInside({ - dirPath: pathJoin( - "keycloak", - "common", - "resources", - "web_modules" - ), - filePath: fileRelativePath - }) - ) { - break skip_web_modules; - } - - return; - } - - skip_unused_node_modules: { - const nodeModulesDirPath = pathJoin( - "keycloak", - "common", - "resources", - "node_modules" - ); - - if ( - !isInside({ - dirPath: nodeModulesDirPath, - filePath: fileRelativePath - }) - ) { - break skip_unused_node_modules; - } - - const toKeepPrefixes = [ - ...[ - "patternfly.min.css", - "patternfly-additions.min.css", - "patternfly-additions.min.css" - ].map(fileBasename => - pathJoin( - nodeModulesDirPath, - "patternfly", - "dist", - "css", - fileBasename - ) - ), - pathJoin(nodeModulesDirPath, "patternfly", "dist", "fonts") - ]; - - if ( - toKeepPrefixes.find(prefix => - fileRelativePath.startsWith(prefix) - ) !== undefined - ) { - break skip_unused_node_modules; - } - - return; - } } skip_unused_resources: { @@ -140,61 +152,76 @@ export async function downloadKeycloakDefaultTheme(params: { break skip_unused_resources; } - for (const dirBasename of [ - "@patternfly-v5", - "@rollup", - "rollup", - "react", - "react-dom", - "shx", - ".pnpm" - ]) { + skip_node_modules: { if ( - isInside({ - dirPath: pathJoin( - "keycloak", - "common", - "resources", - "node_modules", - dirBasename - ), - filePath: fileRelativePath - }) + !fileRelativePath.startsWith( + pathJoin("keycloak", "common", "resources", "node_modules") + ) ) { - return; + break skip_node_modules; } + + if (kcNodeModulesKeepFilePaths === undefined) { + kcNodeModulesKeepFilePaths = [ + pathJoin("@patternfly", "patternfly", "patternfly.min.css"), + pathJoin("patternfly", "dist", "css", "patternfly.min.css"), + pathJoin( + "patternfly", + "dist", + "css", + "patternfly-additions.min.css" + ), + pathJoin( + "patternfly", + "dist", + "fonts", + "OpenSans-Regular-webfont.woff2" + ), + pathJoin( + "patternfly", + "dist", + "fonts", + "OpenSans-Light-webfont.woff2" + ), + pathJoin( + "patternfly", + "dist", + "fonts", + "fontawesome-webfont.woff2" + ), + pathJoin("jquery", "dist", "jquery.min.js") + ]; + } + + for (const keepPath of kcNodeModulesKeepFilePaths) { + if (fileRelativePath.endsWith(keepPath)) { + break skip_node_modules; + } + } + + return; } - for (const dirBasename of ["react", "react-dom"]) { + skip_vendor: { if ( - isInside({ - dirPath: pathJoin( - "keycloak", - "common", - "resources", - "vendor", - dirBasename - ), - filePath: fileRelativePath - }) + !fileRelativePath.startsWith( + pathJoin("keycloak", "common", "resources", "vendor") + ) ) { - return; + break skip_vendor; } + + return; } - if ( - isInside({ - dirPath: pathJoin( - "keycloak", - "common", - "resources", - "node_modules", - "@patternfly", - "react-core" - ), - filePath: fileRelativePath - }) - ) { + skip_rollup_config: { + if ( + fileRelativePath !== + pathJoin("keycloak", "common", "resources", "rollup.config.js") + ) { + break skip_rollup_config; + } + return; } }