From 4506b3f6d495d415d8f2ce600a65f9387f9b81b4 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sun, 22 Oct 2023 16:04:47 +0200 Subject: [PATCH] Remove some dead code --- .../downloadKeycloakStaticResources.ts | 1 - .../generateTheme/readStaticResourcesUsage.ts | 41 +++++++------------ test/bin/readStaticResourcesUsage.spec.ts | 3 +- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.ts b/src/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.ts index 5a2d74d1..c276a15c 100644 --- a/src/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.ts +++ b/src/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.ts @@ -20,7 +20,6 @@ export async function downloadKeycloakStaticResources( keycloakVersion: string; usedResources: { resourcesCommonFilePaths: string[]; - resourcesFilePaths: string[]; } | undefined } ) { diff --git a/src/bin/keycloakify/generateTheme/readStaticResourcesUsage.ts b/src/bin/keycloakify/generateTheme/readStaticResourcesUsage.ts index d49485ac..79a78ca2 100644 --- a/src/bin/keycloakify/generateTheme/readStaticResourcesUsage.ts +++ b/src/bin/keycloakify/generateTheme/readStaticResourcesUsage.ts @@ -6,12 +6,10 @@ import type { ThemeType } from "../generateFtl"; /** Assumes the theme type exists */ export function readStaticResourcesUsage(params: { keycloakifySrcDirPath: string; themeSrcDirPath: string; themeType: ThemeType }): { resourcesCommonFilePaths: string[]; - resourcesFilePaths: string[]; } { const { keycloakifySrcDirPath, themeSrcDirPath, themeType } = params; const resourcesCommonFilePaths = new Set(); - const resourcesFilePaths = new Set(); for (const srcDirPath of [pathJoin(keycloakifySrcDirPath, themeType), pathJoin(themeSrcDirPath, themeType)]) { const filePaths = crawl({ "dirPath": srcDirPath, "returnedPathsType": "absolute" }).filter(filePath => /\.(ts|tsx|js|jsx)$/.test(filePath)); @@ -26,51 +24,43 @@ export function readStaticResourcesUsage(params: { keycloakifySrcDirPath: string const wrap = readPaths({ rawSourceFile }); wrap.resourcesCommonFilePaths.forEach(filePath => resourcesCommonFilePaths.add(filePath)); - wrap.resourcesFilePaths.forEach(filePath => resourcesFilePaths.add(filePath)); } } return { - "resourcesCommonFilePaths": Array.from(resourcesCommonFilePaths), - "resourcesFilePaths": Array.from(resourcesFilePaths) + "resourcesCommonFilePaths": Array.from(resourcesCommonFilePaths) }; } /** Exported for testing purpose */ export function readPaths(params: { rawSourceFile: string }): { resourcesCommonFilePaths: string[]; - resourcesFilePaths: string[]; } { const { rawSourceFile } = params; const resourcesCommonFilePaths = new Set(); - const resourcesFilePaths = new Set(); - for (const isCommon of [true, false]) { - const set = isCommon ? resourcesCommonFilePaths : resourcesFilePaths; + { + const regexp = new RegExp(`resourcesCommonPath\\s*}([^\`]+)\``, "g"); - { - const regexp = new RegExp(`resources${isCommon ? "Common" : ""}Path\\s*}([^\`]+)\``, "g"); + const matches = [...rawSourceFile.matchAll(regexp)]; - const matches = [...rawSourceFile.matchAll(regexp)]; + for (const match of matches) { + const filePath = match[1]; - for (const match of matches) { - const filePath = match[1]; - - set.add(filePath); - } + resourcesCommonFilePaths.add(filePath); } + } - { - const regexp = new RegExp(`resources${isCommon ? "Common" : ""}Path\\s*[+,]\\s*["']([^"'\`]+)["'\`]`, "g"); + { + const regexp = new RegExp(`resourcesCommonPath\\s*[+,]\\s*["']([^"'\`]+)["'\`]`, "g"); - const matches = [...rawSourceFile.matchAll(regexp)]; + const matches = [...rawSourceFile.matchAll(regexp)]; - for (const match of matches) { - const filePath = match[1]; + for (const match of matches) { + const filePath = match[1]; - set.add(filePath); - } + resourcesCommonFilePaths.add(filePath); } } @@ -81,7 +71,6 @@ export function readPaths(params: { rawSourceFile: string }): { }; return { - "resourcesCommonFilePaths": Array.from(resourcesCommonFilePaths).map(normalizePath), - "resourcesFilePaths": Array.from(resourcesFilePaths).map(normalizePath) + "resourcesCommonFilePaths": Array.from(resourcesCommonFilePaths).map(normalizePath) }; } diff --git a/test/bin/readStaticResourcesUsage.spec.ts b/test/bin/readStaticResourcesUsage.spec.ts index 74b74db2..a03fdde7 100644 --- a/test/bin/readStaticResourcesUsage.spec.ts +++ b/test/bin/readStaticResourcesUsage.spec.ts @@ -9,8 +9,7 @@ describe("Ensure it's able to extract used Keycloak resources", () => { "node_modules/patternfly/dist/css/patternfly-additions.min.css", "lib/zocial/zocial.css", "node_modules/jquery/dist/jquery.min.js" - ], - "resourcesFilePaths": ["css/login.css"] + ] }; it("works with coding style n°1", () => {