2024-05-15 05:14:01 +02:00
|
|
|
import {
|
|
|
|
downloadKeycloakStaticResources,
|
2024-06-09 09:15:16 +02:00
|
|
|
type BuildContextLike as BuildContextLike_downloadKeycloakStaticResources
|
2024-05-15 05:14:01 +02:00
|
|
|
} from "./downloadKeycloakStaticResources";
|
|
|
|
import { join as pathJoin, relative as pathRelative } from "path";
|
2024-05-20 15:48:51 +02:00
|
|
|
import {
|
2024-07-13 19:33:59 +02:00
|
|
|
THEME_TYPES,
|
|
|
|
KEYCLOAK_RESOURCES,
|
|
|
|
LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1
|
2024-05-20 15:48:51 +02:00
|
|
|
} from "../shared/constants";
|
2024-05-18 10:24:55 +02:00
|
|
|
import { readThisNpmPackageVersion } from "../tools/readThisNpmPackageVersion";
|
2024-05-15 05:14:01 +02:00
|
|
|
import { assert } from "tsafe/assert";
|
|
|
|
import * as fs from "fs";
|
|
|
|
import { rmSync } from "../tools/fs.rmSync";
|
2024-06-09 09:15:16 +02:00
|
|
|
import type { BuildContext } from "./buildContext";
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-06-09 09:15:16 +02:00
|
|
|
export type BuildContextLike = BuildContextLike_downloadKeycloakStaticResources & {
|
2024-05-15 05:14:01 +02:00
|
|
|
loginThemeResourcesFromKeycloakVersion: string;
|
|
|
|
publicDirPath: string;
|
|
|
|
};
|
|
|
|
|
2024-06-09 09:15:16 +02:00
|
|
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
export async function copyKeycloakResourcesToPublic(params: {
|
2024-06-09 09:15:16 +02:00
|
|
|
buildContext: BuildContextLike;
|
2024-05-20 15:48:51 +02:00
|
|
|
}) {
|
2024-06-09 09:15:16 +02:00
|
|
|
const { buildContext } = params;
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-07-13 19:33:59 +02:00
|
|
|
const destDirPath = pathJoin(buildContext.publicDirPath, KEYCLOAK_RESOURCES);
|
2024-05-15 05:14:01 +02:00
|
|
|
|
|
|
|
const keycloakifyBuildinfoFilePath = pathJoin(destDirPath, "keycloakify.buildinfo");
|
|
|
|
|
|
|
|
const keycloakifyBuildinfoRaw = JSON.stringify(
|
|
|
|
{
|
|
|
|
destDirPath,
|
2024-05-20 15:48:51 +02:00
|
|
|
keycloakifyVersion: readThisNpmPackageVersion(),
|
2024-06-09 09:15:16 +02:00
|
|
|
buildContext: {
|
2024-05-20 15:48:51 +02:00
|
|
|
loginThemeResourcesFromKeycloakVersion: readThisNpmPackageVersion(),
|
2024-06-09 09:15:16 +02:00
|
|
|
cacheDirPath: pathRelative(destDirPath, buildContext.cacheDirPath),
|
2024-06-23 21:23:06 +02:00
|
|
|
fetchOptions: buildContext.fetchOptions
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
2
|
|
|
|
);
|
|
|
|
|
|
|
|
skip_if_already_done: {
|
|
|
|
if (!fs.existsSync(keycloakifyBuildinfoFilePath)) {
|
|
|
|
break skip_if_already_done;
|
|
|
|
}
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
const keycloakifyBuildinfoRaw_previousRun = fs
|
|
|
|
.readFileSync(keycloakifyBuildinfoFilePath)
|
|
|
|
.toString("utf8");
|
2024-05-15 05:14:01 +02:00
|
|
|
|
|
|
|
if (keycloakifyBuildinfoRaw_previousRun !== keycloakifyBuildinfoRaw) {
|
|
|
|
break skip_if_already_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
rmSync(destDirPath, { force: true, recursive: true });
|
2024-05-15 05:14:01 +02:00
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
fs.mkdirSync(destDirPath, { recursive: true });
|
2024-05-18 04:48:04 +02:00
|
|
|
|
|
|
|
fs.writeFileSync(pathJoin(destDirPath, ".gitignore"), Buffer.from("*", "utf8"));
|
|
|
|
|
2024-07-13 19:33:59 +02:00
|
|
|
for (const themeType of THEME_TYPES) {
|
2024-05-15 05:14:01 +02:00
|
|
|
await downloadKeycloakStaticResources({
|
2024-05-20 15:48:51 +02:00
|
|
|
keycloakVersion: (() => {
|
2024-05-15 05:14:01 +02:00
|
|
|
switch (themeType) {
|
|
|
|
case "login":
|
2024-06-09 09:15:16 +02:00
|
|
|
return buildContext.loginThemeResourcesFromKeycloakVersion;
|
2024-05-15 05:14:01 +02:00
|
|
|
case "account":
|
2024-07-13 19:33:59 +02:00
|
|
|
return LAST_KEYCLOAK_VERSION_WITH_ACCOUNT_V1;
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|
|
|
|
})(),
|
|
|
|
themeType,
|
2024-05-20 15:48:51 +02:00
|
|
|
themeDirPath: destDirPath,
|
2024-06-09 09:15:16 +02:00
|
|
|
buildContext
|
2024-05-15 05:14:01 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
pathJoin(destDirPath, "README.txt"),
|
|
|
|
Buffer.from(
|
|
|
|
// prettier-ignore
|
|
|
|
[
|
|
|
|
"This is just a test folder that helps develop",
|
2024-05-18 04:48:04 +02:00
|
|
|
"the login and register page without having to run a Keycloak container\n",
|
|
|
|
"This directory will be automatically excluded from the final build."
|
2024-05-15 05:14:01 +02:00
|
|
|
].join(" ")
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
fs.writeFileSync(
|
|
|
|
keycloakifyBuildinfoFilePath,
|
|
|
|
Buffer.from(keycloakifyBuildinfoRaw, "utf8")
|
|
|
|
);
|
2024-05-15 05:14:01 +02:00
|
|
|
}
|