keycloak_theme/src/bin/copy-keycloak-resources-to-public.ts

67 lines
2.1 KiB
TypeScript
Raw Normal View History

#!/usr/bin/env node
import { downloadKeycloakStaticResources } from "./keycloakify/generateTheme/downloadKeycloakStaticResources";
import { join as pathJoin, relative as pathRelative, isAbsolute as pathIsAbsolute } from "path";
import { readBuildOptions } from "./keycloakify/BuildOptions";
import { themeTypes, keycloak_resources, lastKeycloakVersionWithAccountV1 } from "./constants";
import * as fs from "fs";
(async () => {
const cwd = process.cwd();
const projectDirPath = cwd;
const publicDirPath = (() => {
from_env_var: {
const value = process.env["PUBLIC_DIR_PATH"];
if (value === undefined) {
break from_env_var;
}
return pathIsAbsolute(value) ? value : pathJoin(cwd, value);
}
return pathJoin(projectDirPath, "public");
})();
const buildOptions = readBuildOptions({
"processArgv": process.argv.slice(2),
"projectDirPath": process.cwd()
});
const reservedDirPath = pathJoin(publicDirPath, keycloak_resources);
for (const themeType of themeTypes) {
await downloadKeycloakStaticResources({
projectDirPath,
"keycloakVersion": (() => {
switch (themeType) {
case "login":
return buildOptions.loginThemeDefaultResourcesFromKeycloakVersion;
case "account":
return lastKeycloakVersionWithAccountV1;
}
})(),
themeType,
"themeDirPath": reservedDirPath,
2023-08-24 08:58:00 +02:00
"usedResources": undefined
});
}
fs.writeFileSync(
pathJoin(reservedDirPath, "README.txt"),
Buffer.from(
// prettier-ignore
[
"This is just a test folder that helps develop",
"the login and register page without having to run a Keycloak container"
].join(" ")
)
);
fs.writeFileSync(pathJoin(publicDirPath, "keycloak-resources", ".gitignore"), Buffer.from("*", "utf8"));
2023-04-19 05:32:19 +02:00
console.log(`${pathRelative(projectDirPath, reservedDirPath)} directory created.`);
})();