keycloak_theme/src/bin/shared/downloadKeycloakStaticResources.ts

54 lines
1.7 KiB
TypeScript
Raw Normal View History

import { transformCodebase } from "../tools/transformCodebase";
2024-02-05 08:52:58 +01:00
import { join as pathJoin } from "path";
2024-05-24 17:26:38 +02:00
import {
downloadKeycloakDefaultTheme,
2024-06-09 09:15:16 +02:00
type BuildContextLike as BuildContextLike_downloadKeycloakDefaultTheme
2024-05-24 17:26:38 +02:00
} from "./downloadKeycloakDefaultTheme";
2024-07-13 19:33:59 +02:00
import { RESOURCES_COMMON, type ThemeType } from "./constants";
2024-06-09 09:15:16 +02:00
import type { BuildContext } from "./buildContext";
2023-10-02 22:49:04 +02:00
import { assert } from "tsafe/assert";
2024-05-24 17:26:38 +02:00
import { existsAsync } from "../tools/fs.existsAsync";
2024-06-09 09:15:16 +02:00
export type BuildContextLike = BuildContextLike_downloadKeycloakDefaultTheme & {};
2023-09-03 23:26:34 +02:00
2024-06-09 09:15:16 +02:00
assert<BuildContext extends BuildContextLike ? true : false>();
2024-02-05 08:52:58 +01:00
export async function downloadKeycloakStaticResources(params: {
themeType: ThemeType;
themeDirPath: string;
keycloakVersion: string;
2024-06-09 09:15:16 +02:00
buildContext: BuildContextLike;
2024-02-05 08:52:58 +01:00
}) {
2024-06-09 09:15:16 +02:00
const { themeType, themeDirPath, keycloakVersion, buildContext } = params;
2023-11-26 15:07:27 +01:00
2024-05-24 17:26:38 +02:00
const { defaultThemeDirPath } = await downloadKeycloakDefaultTheme({
keycloakVersion,
2024-06-09 09:15:16 +02:00
buildContext
});
2024-05-24 17:26:38 +02:00
const resourcesDirPath = pathJoin(themeDirPath, themeType, "resources");
repatriate_base_resources: {
const srcDirPath = pathJoin(defaultThemeDirPath, "base", themeType, "resources");
if (!(await existsAsync(srcDirPath))) {
break repatriate_base_resources;
}
transformCodebase({
srcDirPath,
destDirPath: resourcesDirPath
});
}
transformCodebase({
2024-05-24 17:26:38 +02:00
srcDirPath: pathJoin(defaultThemeDirPath, "keycloak", themeType, "resources"),
destDirPath: resourcesDirPath
});
transformCodebase({
2024-05-24 17:26:38 +02:00
srcDirPath: pathJoin(defaultThemeDirPath, "keycloak", "common", "resources"),
2024-07-13 19:33:59 +02:00
destDirPath: pathJoin(resourcesDirPath, RESOURCES_COMMON)
});
2023-11-26 15:07:27 +01:00
}