90 lines
3.1 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";
2024-06-09 09:15:16 +02:00
import type { BuildContext } from "../../shared/buildContext";
2024-05-20 15:48:51 +02:00
import {
2024-07-13 19:33:59 +02:00
RESOURCES_COMMON,
LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1,
ACCOUNT_V1_THEME_NAME
2024-05-20 15:48:51 +02:00
} from "../../shared/constants";
2024-06-23 02:06:45 +02:00
import {
downloadKeycloakDefaultTheme,
BuildContextLike as BuildContextLike_downloadKeycloakDefaultTheme
} from "../../shared/downloadKeycloakDefaultTheme";
2023-09-04 00:25:36 +02:00
import { transformCodebase } from "../../tools/transformCodebase";
2024-06-23 02:06:45 +02:00
export type BuildContextLike = BuildContextLike_downloadKeycloakDefaultTheme;
2023-09-04 00:25:36 +02:00
2024-06-09 09:15:16 +02:00
assert<BuildContext extends BuildContextLike ? true : false>();
2023-09-04 00:25:36 +02:00
2024-06-10 07:57:12 +02:00
export async function bringInAccountV1(params: {
resourcesDirPath: string;
buildContext: BuildContextLike;
}) {
const { resourcesDirPath, buildContext } = params;
2023-09-04 00:25:36 +02:00
2024-05-24 17:26:38 +02:00
const { defaultThemeDirPath } = await downloadKeycloakDefaultTheme({
2024-07-13 19:33:59 +02:00
keycloakVersion: LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1,
2024-06-09 09:15:16 +02:00
buildContext
2023-09-04 00:25:36 +02:00
});
2024-05-20 15:48:51 +02:00
const accountV1DirPath = pathJoin(
2024-06-10 07:57:12 +02:00
resourcesDirPath,
2024-05-20 15:48:51 +02:00
"theme",
2024-07-13 19:33:59 +02:00
ACCOUNT_V1_THEME_NAME,
2024-05-20 15:48:51 +02:00
"account"
);
2023-09-04 00:25:36 +02:00
transformCodebase({
2024-05-24 17:26:38 +02:00
srcDirPath: pathJoin(defaultThemeDirPath, "base", "account"),
2024-05-20 15:48:51 +02:00
destDirPath: accountV1DirPath
2023-09-04 00:25:36 +02:00
});
2024-02-05 08:52:58 +01:00
transformCodebase({
2024-05-24 17:26:38 +02:00
srcDirPath: pathJoin(defaultThemeDirPath, "keycloak", "account", "resources"),
2024-05-20 15:48:51 +02:00
destDirPath: pathJoin(accountV1DirPath, "resources")
2024-02-05 08:52:58 +01:00
});
2023-09-04 00:25:36 +02:00
2024-02-05 08:52:58 +01:00
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(accountV1DirPath, "resources", RESOURCES_COMMON)
2024-02-05 08:52:58 +01:00
});
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",
2024-05-20 15:48:51 +02:00
...[
"patternfly.min.css",
"patternfly-additions.min.css",
"patternfly-additions.min.css"
].map(
fileBasename =>
2024-07-13 19:33:59 +02:00
`${RESOURCES_COMMON}/node_modules/patternfly/dist/css/${fileBasename}`
2024-02-05 08:52:58 +01:00
)
].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"
)
);
}