2024-05-15 05:14:01 +02:00
|
|
|
import {
|
|
|
|
downloadKeycloakStaticResources,
|
|
|
|
type BuildOptionsLike as BuildOptionsLike_downloadKeycloakStaticResources
|
|
|
|
} from "./downloadKeycloakStaticResources";
|
|
|
|
import { join as pathJoin, relative as pathRelative } from "path";
|
2024-05-20 15:48:51 +02:00
|
|
|
import {
|
|
|
|
themeTypes,
|
|
|
|
keycloak_resources,
|
|
|
|
lastKeycloakVersionWithAccountV1
|
|
|
|
} 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";
|
|
|
|
import type { BuildOptions } from "./buildOptions";
|
|
|
|
|
|
|
|
export type BuildOptionsLike = BuildOptionsLike_downloadKeycloakStaticResources & {
|
|
|
|
loginThemeResourcesFromKeycloakVersion: string;
|
|
|
|
publicDirPath: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
export async function copyKeycloakResourcesToPublic(params: {
|
|
|
|
buildOptions: BuildOptionsLike;
|
|
|
|
}) {
|
2024-05-15 05:14:01 +02:00
|
|
|
const { buildOptions } = params;
|
|
|
|
|
|
|
|
const destDirPath = pathJoin(buildOptions.publicDirPath, keycloak_resources);
|
|
|
|
|
|
|
|
const keycloakifyBuildinfoFilePath = pathJoin(destDirPath, "keycloakify.buildinfo");
|
|
|
|
|
|
|
|
const keycloakifyBuildinfoRaw = JSON.stringify(
|
|
|
|
{
|
|
|
|
destDirPath,
|
2024-05-20 15:48:51 +02:00
|
|
|
keycloakifyVersion: readThisNpmPackageVersion(),
|
|
|
|
buildOptions: {
|
|
|
|
loginThemeResourcesFromKeycloakVersion: readThisNpmPackageVersion(),
|
|
|
|
cacheDirPath: pathRelative(destDirPath, buildOptions.cacheDirPath),
|
|
|
|
npmWorkspaceRootDirPath: pathRelative(
|
|
|
|
destDirPath,
|
|
|
|
buildOptions.npmWorkspaceRootDirPath
|
|
|
|
)
|
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-05-15 05:14:01 +02:00
|
|
|
for (const themeType of themeTypes) {
|
|
|
|
await downloadKeycloakStaticResources({
|
2024-05-20 15:48:51 +02:00
|
|
|
keycloakVersion: (() => {
|
2024-05-15 05:14:01 +02:00
|
|
|
switch (themeType) {
|
|
|
|
case "login":
|
|
|
|
return buildOptions.loginThemeResourcesFromKeycloakVersion;
|
|
|
|
case "account":
|
|
|
|
return lastKeycloakVersionWithAccountV1;
|
|
|
|
}
|
|
|
|
})(),
|
|
|
|
themeType,
|
2024-05-20 15:48:51 +02:00
|
|
|
themeDirPath: destDirPath,
|
2024-05-15 05:14:01 +02:00
|
|
|
buildOptions
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|