Remove some dead code

This commit is contained in:
Joseph Garrone 2023-10-22 16:04:47 +02:00
parent 804abef0de
commit 4506b3f6d4
3 changed files with 16 additions and 29 deletions

View File

@ -20,7 +20,6 @@ export async function downloadKeycloakStaticResources(
keycloakVersion: string; keycloakVersion: string;
usedResources: { usedResources: {
resourcesCommonFilePaths: string[]; resourcesCommonFilePaths: string[];
resourcesFilePaths: string[];
} | undefined } | undefined
} }
) { ) {

View File

@ -6,12 +6,10 @@ import type { ThemeType } from "../generateFtl";
/** Assumes the theme type exists */ /** Assumes the theme type exists */
export function readStaticResourcesUsage(params: { keycloakifySrcDirPath: string; themeSrcDirPath: string; themeType: ThemeType }): { export function readStaticResourcesUsage(params: { keycloakifySrcDirPath: string; themeSrcDirPath: string; themeType: ThemeType }): {
resourcesCommonFilePaths: string[]; resourcesCommonFilePaths: string[];
resourcesFilePaths: string[];
} { } {
const { keycloakifySrcDirPath, themeSrcDirPath, themeType } = params; const { keycloakifySrcDirPath, themeSrcDirPath, themeType } = params;
const resourcesCommonFilePaths = new Set<string>(); const resourcesCommonFilePaths = new Set<string>();
const resourcesFilePaths = new Set<string>();
for (const srcDirPath of [pathJoin(keycloakifySrcDirPath, themeType), pathJoin(themeSrcDirPath, themeType)]) { 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)); 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 }); const wrap = readPaths({ rawSourceFile });
wrap.resourcesCommonFilePaths.forEach(filePath => resourcesCommonFilePaths.add(filePath)); wrap.resourcesCommonFilePaths.forEach(filePath => resourcesCommonFilePaths.add(filePath));
wrap.resourcesFilePaths.forEach(filePath => resourcesFilePaths.add(filePath));
} }
} }
return { return {
"resourcesCommonFilePaths": Array.from(resourcesCommonFilePaths), "resourcesCommonFilePaths": Array.from(resourcesCommonFilePaths)
"resourcesFilePaths": Array.from(resourcesFilePaths)
}; };
} }
/** Exported for testing purpose */ /** Exported for testing purpose */
export function readPaths(params: { rawSourceFile: string }): { export function readPaths(params: { rawSourceFile: string }): {
resourcesCommonFilePaths: string[]; resourcesCommonFilePaths: string[];
resourcesFilePaths: string[];
} { } {
const { rawSourceFile } = params; const { rawSourceFile } = params;
const resourcesCommonFilePaths = new Set<string>(); const resourcesCommonFilePaths = new Set<string>();
const resourcesFilePaths = new Set<string>();
for (const isCommon of [true, false]) { {
const set = isCommon ? resourcesCommonFilePaths : resourcesFilePaths; const regexp = new RegExp(`resourcesCommonPath\\s*}([^\`]+)\``, "g");
{ const matches = [...rawSourceFile.matchAll(regexp)];
const regexp = new RegExp(`resources${isCommon ? "Common" : ""}Path\\s*}([^\`]+)\``, "g");
const matches = [...rawSourceFile.matchAll(regexp)]; for (const match of matches) {
const filePath = match[1];
for (const match of matches) { resourcesCommonFilePaths.add(filePath);
const filePath = match[1];
set.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) { for (const match of matches) {
const filePath = match[1]; const filePath = match[1];
set.add(filePath); resourcesCommonFilePaths.add(filePath);
}
} }
} }
@ -81,7 +71,6 @@ export function readPaths(params: { rawSourceFile: string }): {
}; };
return { return {
"resourcesCommonFilePaths": Array.from(resourcesCommonFilePaths).map(normalizePath), "resourcesCommonFilePaths": Array.from(resourcesCommonFilePaths).map(normalizePath)
"resourcesFilePaths": Array.from(resourcesFilePaths).map(normalizePath)
}; };
} }

View File

@ -9,8 +9,7 @@ describe("Ensure it's able to extract used Keycloak resources", () => {
"node_modules/patternfly/dist/css/patternfly-additions.min.css", "node_modules/patternfly/dist/css/patternfly-additions.min.css",
"lib/zocial/zocial.css", "lib/zocial/zocial.css",
"node_modules/jquery/dist/jquery.min.js" "node_modules/jquery/dist/jquery.min.js"
], ]
"resourcesFilePaths": ["css/login.css"]
}; };
it("works with coding style n°1", () => { it("works with coding style n°1", () => {