2023-04-18 03:10:29 +02:00
|
|
|
import { transformCodebase } from "../../tools/transformCodebase";
|
|
|
|
import * as fs from "fs";
|
2023-09-03 07:14:57 +02:00
|
|
|
import { join as pathJoin } from "path";
|
2023-04-18 03:10:29 +02:00
|
|
|
import { downloadBuiltinKeycloakTheme } from "../../download-builtin-keycloak-theme";
|
2023-09-03 07:14:57 +02:00
|
|
|
import { resources_common, type ThemeType } from "../../constants";
|
2023-09-03 23:26:34 +02:00
|
|
|
import { BuildOptions } from "../BuildOptions";
|
2023-10-02 22:49:04 +02:00
|
|
|
import { assert } from "tsafe/assert";
|
2023-04-19 05:04:11 +02:00
|
|
|
import * as crypto from "crypto";
|
2023-04-18 03:10:29 +02:00
|
|
|
|
2023-09-03 23:26:34 +02:00
|
|
|
export type BuildOptionsLike = {
|
|
|
|
cacheDirPath: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
2023-04-18 03:10:29 +02:00
|
|
|
|
|
|
|
export async function downloadKeycloakStaticResources(
|
|
|
|
// prettier-ignore
|
|
|
|
params: {
|
|
|
|
themeType: ThemeType;
|
|
|
|
themeDirPath: string;
|
|
|
|
keycloakVersion: string;
|
2023-08-24 08:58:00 +02:00
|
|
|
usedResources: {
|
|
|
|
resourcesCommonFilePaths: string[];
|
|
|
|
resourcesFilePaths: string[];
|
2023-09-03 23:26:34 +02:00
|
|
|
} | undefined;
|
|
|
|
buildOptions: BuildOptionsLike;
|
2023-04-18 03:10:29 +02:00
|
|
|
}
|
|
|
|
) {
|
2023-09-03 23:26:34 +02:00
|
|
|
const { themeType, themeDirPath, keycloakVersion, usedResources, buildOptions } = params;
|
2023-08-24 08:58:00 +02:00
|
|
|
|
2023-04-19 05:04:11 +02:00
|
|
|
const tmpDirPath = pathJoin(
|
|
|
|
themeDirPath,
|
|
|
|
`tmp_suLeKsxId_${crypto.createHash("sha256").update(`${themeType}-${keycloakVersion}`).digest("hex").slice(0, 8)}`
|
|
|
|
);
|
2023-04-18 03:10:29 +02:00
|
|
|
|
|
|
|
await downloadBuiltinKeycloakTheme({
|
|
|
|
keycloakVersion,
|
2023-09-03 23:26:34 +02:00
|
|
|
"destDirPath": tmpDirPath,
|
|
|
|
buildOptions
|
2023-04-18 03:10:29 +02:00
|
|
|
});
|
|
|
|
|
2023-09-03 07:14:57 +02:00
|
|
|
const resourcesPath = pathJoin(themeDirPath, themeType, "resources");
|
|
|
|
|
2023-04-18 03:10:29 +02:00
|
|
|
transformCodebase({
|
|
|
|
"srcDirPath": pathJoin(tmpDirPath, "keycloak", themeType, "resources"),
|
2023-09-03 07:14:57 +02:00
|
|
|
"destDirPath": resourcesPath,
|
2023-08-24 08:58:00 +02:00
|
|
|
"transformSourceCode":
|
|
|
|
usedResources === undefined
|
|
|
|
? undefined
|
|
|
|
: ({ fileRelativePath, sourceCode }) => {
|
|
|
|
if (!usedResources.resourcesFilePaths.includes(fileRelativePath)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return { "modifiedSourceCode": sourceCode };
|
|
|
|
}
|
2023-04-18 03:10:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
transformCodebase({
|
|
|
|
"srcDirPath": pathJoin(tmpDirPath, "keycloak", "common", "resources"),
|
2023-09-03 07:14:57 +02:00
|
|
|
"destDirPath": pathJoin(resourcesPath, resources_common),
|
2023-08-24 08:58:00 +02:00
|
|
|
"transformSourceCode":
|
|
|
|
usedResources === undefined
|
|
|
|
? undefined
|
|
|
|
: ({ fileRelativePath, sourceCode }) => {
|
|
|
|
if (!usedResources.resourcesCommonFilePaths.includes(fileRelativePath)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return { "modifiedSourceCode": sourceCode };
|
|
|
|
}
|
2023-04-18 03:10:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
fs.rmSync(tmpDirPath, { "recursive": true, "force": true });
|
2023-11-26 14:45:23 +01:00
|
|
|
}
|