From 84bb2338d17fb24ce9cc72900e1ddd50cad18507 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sat, 25 May 2024 12:19:03 +0200 Subject: [PATCH] Filter out many of the unused keycloak resources --- .../shared/downloadKeycloakDefaultTheme.ts | 83 ++++++++++++++++++- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/src/bin/shared/downloadKeycloakDefaultTheme.ts b/src/bin/shared/downloadKeycloakDefaultTheme.ts index 7770a616..a7214a9c 100644 --- a/src/bin/shared/downloadKeycloakDefaultTheme.ts +++ b/src/bin/shared/downloadKeycloakDefaultTheme.ts @@ -72,14 +72,19 @@ export async function downloadKeycloakDefaultTheme(params: { } skip_unused_node_modules: { - const dirPath = pathJoin( + const nodeModulesDirPath = pathJoin( "keycloak", "common", "resources", "node_modules" ); - if (!isInside({ dirPath, filePath: fileRelativePath })) { + if ( + !isInside({ + dirPath: nodeModulesDirPath, + filePath: fileRelativePath + }) + ) { break skip_unused_node_modules; } @@ -89,9 +94,15 @@ export async function downloadKeycloakDefaultTheme(params: { "patternfly-additions.min.css", "patternfly-additions.min.css" ].map(fileBasename => - pathJoin(dirPath, "patternfly", "dist", "css", fileBasename) + pathJoin( + nodeModulesDirPath, + "patternfly", + "dist", + "css", + fileBasename + ) ), - pathJoin(dirPath, "patternfly", "dist", "fonts") + pathJoin(nodeModulesDirPath, "patternfly", "dist", "fonts") ]; if ( @@ -106,6 +117,70 @@ export async function downloadKeycloakDefaultTheme(params: { } } + skip_unused_resources: { + if (keycloakVersion !== "24.0.4") { + break skip_unused_resources; + } + + for (const dirBasename of [ + "@patternfly-v5", + "@rollup", + "rollup", + "react", + "react-dom", + "shx", + ".pnpm" + ]) { + if ( + isInside({ + dirPath: pathJoin( + "keycloak", + "common", + "resources", + "node_modules", + dirBasename + ), + filePath: fileRelativePath + }) + ) { + return; + } + } + + for (const dirBasename of ["react", "react-dom"]) { + if ( + isInside({ + dirPath: pathJoin( + "keycloak", + "common", + "resources", + "vendor", + dirBasename + ), + filePath: fileRelativePath + }) + ) { + return; + } + } + + if ( + isInside({ + dirPath: pathJoin( + "keycloak", + "common", + "resources", + "node_modules", + "@patternfly", + "react-core" + ), + filePath: fileRelativePath + }) + ) { + return; + } + } + await writeFile({ fileRelativePath }); } });