Readability improvement
This commit is contained in:
parent
6603852355
commit
9a5ac5f13f
@ -17,7 +17,6 @@ import { isInside } from "../../tools/isInside";
|
||||
import child_process from "child_process";
|
||||
import { rmSync } from "../../tools/fs.rmSync";
|
||||
import { getMetaInfKeycloakThemesJsonFilePath } from "../../shared/metaInfKeycloakThemes";
|
||||
import type { Param0 } from "tsafe";
|
||||
|
||||
export type BuildOptionsLike = BuildOptionsLike_generatePom & {
|
||||
keycloakifyBuildDirPath: string;
|
||||
@ -50,25 +49,42 @@ export async function buildJar(params: {
|
||||
rmSync(keycloakifyBuildTmpDirPath, { recursive: true, force: true });
|
||||
|
||||
{
|
||||
const metaInfKeycloakThemesJsonRelativePath =
|
||||
getMetaInfKeycloakThemesJsonFilePath({
|
||||
keycloakifyBuildDirPath: ""
|
||||
});
|
||||
const transformCodebase_common = (params: {
|
||||
fileRelativePath: string;
|
||||
sourceCode: Buffer;
|
||||
}): { modifiedSourceCode: Buffer } | undefined => {
|
||||
const { fileRelativePath, sourceCode } = params;
|
||||
|
||||
const { transformCodebase_common } = (() => {
|
||||
const includingAccountV1ThemeNames = [
|
||||
...buildOptions.themeNames,
|
||||
accountV1ThemeName
|
||||
];
|
||||
|
||||
const transformCodebase_common: Param0<
|
||||
typeof transformCodebase
|
||||
>["transformSourceCode"] = ({ fileRelativePath, sourceCode }) => {
|
||||
if (metaInfKeycloakThemesJsonRelativePath === fileRelativePath) {
|
||||
if (
|
||||
fileRelativePath ===
|
||||
getMetaInfKeycloakThemesJsonFilePath({ keycloakifyBuildDirPath: "." })
|
||||
) {
|
||||
return { modifiedSourceCode: sourceCode };
|
||||
}
|
||||
|
||||
for (const themeName of includingAccountV1ThemeNames) {
|
||||
for (const themeName of [...buildOptions.themeNames, accountV1ThemeName]) {
|
||||
if (
|
||||
isInside({
|
||||
dirPath: pathJoin("src", "main", "resources", "theme", themeName),
|
||||
filePath: fileRelativePath
|
||||
})
|
||||
) {
|
||||
return { modifiedSourceCode: sourceCode };
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const transformCodebase_patchForUsingBuiltinAccountV1 =
|
||||
keycloakAccountV1Version !== null
|
||||
? undefined
|
||||
: (params: {
|
||||
fileRelativePath: string;
|
||||
sourceCode: Buffer;
|
||||
}): { modifiedSourceCode: Buffer } | undefined => {
|
||||
const { fileRelativePath, sourceCode } = params;
|
||||
|
||||
if (
|
||||
isInside({
|
||||
dirPath: pathJoin(
|
||||
@ -76,49 +92,20 @@ export async function buildJar(params: {
|
||||
"main",
|
||||
"resources",
|
||||
"theme",
|
||||
themeName
|
||||
accountV1ThemeName
|
||||
),
|
||||
filePath: fileRelativePath
|
||||
})
|
||||
) {
|
||||
return { modifiedSourceCode: sourceCode };
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
return { transformCodebase_common };
|
||||
})();
|
||||
|
||||
const { transformCodebase_patchForUsingBuiltinAccountV1 } = (() => {
|
||||
if (keycloakAccountV1Version !== null) {
|
||||
return {
|
||||
transformCodebase_patchForUsingBuiltinAccountV1: undefined
|
||||
};
|
||||
}
|
||||
|
||||
const accountV1RelativeDirPath = pathJoin(
|
||||
"src",
|
||||
"main",
|
||||
"resources",
|
||||
"theme",
|
||||
accountV1ThemeName
|
||||
);
|
||||
|
||||
const transformCodebase_patchForUsingBuiltinAccountV1: Param0<
|
||||
typeof transformCodebase
|
||||
>["transformSourceCode"] = ({ fileRelativePath, sourceCode }) => {
|
||||
if (
|
||||
isInside({
|
||||
dirPath: accountV1RelativeDirPath,
|
||||
filePath: fileRelativePath
|
||||
fileRelativePath ===
|
||||
getMetaInfKeycloakThemesJsonFilePath({
|
||||
keycloakifyBuildDirPath: "."
|
||||
})
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (fileRelativePath === metaInfKeycloakThemesJsonRelativePath) {
|
||||
const keycloakThemesJsonParsed = JSON.parse(
|
||||
sourceCode.toString("utf8")
|
||||
) as {
|
||||
@ -161,7 +148,9 @@ export async function buildJar(params: {
|
||||
"utf8"
|
||||
);
|
||||
|
||||
assert(Buffer.compare(modifiedSourceCode, sourceCode) !== 0);
|
||||
assert(
|
||||
Buffer.compare(modifiedSourceCode, sourceCode) !== 0
|
||||
);
|
||||
|
||||
return { modifiedSourceCode };
|
||||
}
|
||||
@ -170,38 +159,28 @@ export async function buildJar(params: {
|
||||
return { modifiedSourceCode: sourceCode };
|
||||
};
|
||||
|
||||
return { transformCodebase_patchForUsingBuiltinAccountV1 };
|
||||
})();
|
||||
|
||||
console.log("Transforming codebase...");
|
||||
const start = Date.now();
|
||||
|
||||
transformCodebase({
|
||||
srcDirPath: buildOptions.keycloakifyBuildDirPath,
|
||||
destDirPath: keycloakifyBuildTmpDirPath,
|
||||
transformSourceCode: params => {
|
||||
const resultCommon = transformCodebase_common(params);
|
||||
|
||||
if (resultCommon === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (transformCodebase_patchForUsingBuiltinAccountV1 === undefined) {
|
||||
return resultCommon;
|
||||
}
|
||||
|
||||
const { modifiedSourceCode, newFileName } = resultCommon;
|
||||
if (resultCommon === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
assert(newFileName === undefined);
|
||||
const { modifiedSourceCode } = resultCommon;
|
||||
|
||||
return transformCodebase_patchForUsingBuiltinAccountV1?.({
|
||||
return transformCodebase_patchForUsingBuiltinAccountV1({
|
||||
...params,
|
||||
sourceCode: modifiedSourceCode
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`Transforming codebase done in ${Date.now() - start}ms`);
|
||||
}
|
||||
|
||||
route_legacy_pages: {
|
||||
|
@ -12,7 +12,7 @@ export function getMetaInfKeycloakThemesJsonFilePath(params: {
|
||||
const { keycloakifyBuildDirPath } = params;
|
||||
|
||||
return pathJoin(
|
||||
keycloakifyBuildDirPath,
|
||||
keycloakifyBuildDirPath === "." ? "" : keycloakifyBuildDirPath,
|
||||
"src",
|
||||
"main",
|
||||
"resources",
|
||||
|
Loading…
x
Reference in New Issue
Block a user