79 lines
3.2 KiB
TypeScript
Raw Normal View History

2023-09-04 00:25:36 +02:00
import * as fs from "fs";
2024-02-05 08:52:58 +01:00
import { join as pathJoin } from "path";
2023-09-04 00:25:36 +02:00
import { assert } from "tsafe/assert";
import type { BuildOptions } from "../../shared/buildOptions";
import { resources_common, lastKeycloakVersionWithAccountV1, accountV1ThemeName } from "../../shared/constants";
import { downloadBuiltinKeycloakTheme } from "../../shared/downloadBuiltinKeycloakTheme";
2023-09-04 00:25:36 +02:00
import { transformCodebase } from "../../tools/transformCodebase";
2024-02-05 08:52:58 +01:00
import { rmSync } from "../../tools/fs.rmSync";
2023-09-04 00:25:36 +02:00
2024-01-30 07:10:53 +01:00
type BuildOptionsLike = {
2023-09-04 00:25:36 +02:00
cacheDirPath: string;
2024-02-11 18:28:58 +01:00
npmWorkspaceRootDirPath: string;
2023-09-04 00:25:36 +02:00
};
2024-05-13 00:40:16 +02:00
assert<BuildOptions extends BuildOptionsLike ? true : false>();
2023-09-04 00:25:36 +02:00
2024-05-12 20:47:03 +02:00
export async function bringInAccountV1(params: { buildOptions: BuildOptionsLike; srcMainResourcesDirPath: string }) {
const { buildOptions, srcMainResourcesDirPath } = params;
2023-09-04 00:25:36 +02:00
2024-05-12 20:47:03 +02:00
const builtinKeycloakThemeTmpDirPath = pathJoin(srcMainResourcesDirPath, "..", "tmp_yxdE2_builtin_keycloak_theme");
2023-09-04 00:25:36 +02:00
await downloadBuiltinKeycloakTheme({
"destDirPath": builtinKeycloakThemeTmpDirPath,
"keycloakVersion": lastKeycloakVersionWithAccountV1,
buildOptions
});
2024-05-12 20:47:03 +02:00
const accountV1DirPath = pathJoin(srcMainResourcesDirPath, "theme", accountV1ThemeName, "account");
2023-09-04 00:25:36 +02:00
transformCodebase({
"srcDirPath": pathJoin(builtinKeycloakThemeTmpDirPath, "base", "account"),
"destDirPath": accountV1DirPath
});
2024-02-05 08:52:58 +01:00
transformCodebase({
"srcDirPath": pathJoin(builtinKeycloakThemeTmpDirPath, "keycloak", "account", "resources"),
"destDirPath": pathJoin(accountV1DirPath, "resources")
});
2023-09-04 00:25:36 +02:00
2024-02-05 08:52:58 +01:00
transformCodebase({
"srcDirPath": pathJoin(builtinKeycloakThemeTmpDirPath, "keycloak", "common", "resources"),
"destDirPath": pathJoin(accountV1DirPath, "resources", resources_common)
});
2023-09-04 00:25:36 +02:00
2024-02-05 08:52:58 +01:00
rmSync(builtinKeycloakThemeTmpDirPath, { "recursive": true });
2023-09-04 00:25:36 +02:00
fs.writeFileSync(
pathJoin(accountV1DirPath, "theme.properties"),
Buffer.from(
[
"accountResourceProvider=account-v1",
2023-09-04 00:25:36 +02:00
"",
"locales=ar,ca,cs,da,de,en,es,fr,fi,hu,it,ja,lt,nl,no,pl,pt-BR,ru,sk,sv,tr,zh-CN",
"",
2024-02-05 08:52:58 +01:00
"styles=" +
[
"css/account.css",
"img/icon-sidebar-active.png",
"img/logo.png",
...["patternfly.min.css", "patternfly-additions.min.css", "patternfly-additions.min.css"].map(
fileBasename => `${resources_common}/node_modules/patternfly/dist/css/${fileBasename}`
)
].join(" "),
2023-09-04 00:25:36 +02:00
"",
"##### css classes for form buttons",
"# main class used for all buttons",
"kcButtonClass=btn",
"# classes defining priority of the button - primary or default (there is typically only one priority button for the form)",
"kcButtonPrimaryClass=btn-primary",
"kcButtonDefaultClass=btn-default",
"# classes defining size of the button",
"kcButtonLargeClass=btn-lg",
""
].join("\n"),
"utf8"
)
);
}