keycloak_theme/src/bin/download-builtin-keycloak-theme.ts

98 lines
3.9 KiB
TypeScript
Raw Normal View History

2021-02-21 23:40:10 +01:00
#!/usr/bin/env node
2021-03-03 02:31:02 +01:00
import { join as pathJoin } from "path";
import { downloadAndUnzip } from "./tools/downloadAndUnzip";
2022-04-20 00:39:40 +02:00
import { promptKeycloakVersion } from "./promptKeycloakVersion";
2022-09-08 12:06:26 +03:00
import { getLogger } from "./tools/logger";
2023-04-02 03:10:16 +02:00
import { readBuildOptions } from "./keycloakify/BuildOptions";
2023-08-20 03:00:45 +02:00
import * as child_process from "child_process";
import * as fs from "fs";
2021-02-21 23:06:42 +01:00
2023-08-21 04:29:32 +02:00
export async function downloadBuiltinKeycloakTheme(params: { projectDirPath: string; keycloakVersion: string; destDirPath: string }) {
const { projectDirPath, keycloakVersion, destDirPath } = params;
2023-08-20 03:00:45 +02:00
await downloadAndUnzip({
2023-08-21 05:54:17 +02:00
"doUseCache": true,
projectDirPath,
destDirPath,
"url": `https://github.com/keycloak/keycloak/archive/refs/tags/${keycloakVersion}.zip`,
"specificDirsToExtract": ["", "-community"].map(ext => `keycloak-${keycloakVersion}/themes/src/main/resources${ext}/theme`),
"preCacheTransform": {
2023-08-24 08:58:00 +02:00
"actionCacheId": "npm install and build",
"action": async ({ destDirPath }) => {
install_common_node_modules: {
const commonResourcesDirPath = pathJoin(destDirPath, "keycloak", "common", "resources");
2023-08-20 03:00:45 +02:00
if (!fs.existsSync(commonResourcesDirPath)) {
break install_common_node_modules;
}
2023-08-20 03:00:45 +02:00
if (!fs.existsSync(pathJoin(commonResourcesDirPath, "package.json"))) {
break install_common_node_modules;
}
2023-08-20 03:00:45 +02:00
if (fs.existsSync(pathJoin(commonResourcesDirPath, "node_modules"))) {
break install_common_node_modules;
}
2023-08-20 03:00:45 +02:00
child_process.execSync("npm install --omit=dev", {
"cwd": commonResourcesDirPath,
"stdio": "ignore"
});
}
2023-08-20 03:00:45 +02:00
install_and_move_to_common_resources_generated_in_keycloak_v2: {
const accountV2DirSrcDirPath = pathJoin(destDirPath, "keycloak.v2", "account", "src");
2023-08-20 03:00:45 +02:00
if (!fs.existsSync(accountV2DirSrcDirPath)) {
break install_and_move_to_common_resources_generated_in_keycloak_v2;
}
2023-08-20 03:00:45 +02:00
child_process.execSync("npm install", { "cwd": accountV2DirSrcDirPath, "stdio": "ignore" });
2023-08-20 03:00:45 +02:00
const packageJsonFilePath = pathJoin(accountV2DirSrcDirPath, "package.json");
2023-08-20 03:00:45 +02:00
const packageJsonRaw = fs.readFileSync(packageJsonFilePath);
2023-08-20 03:00:45 +02:00
const parsedPackageJson = JSON.parse(packageJsonRaw.toString("utf8"));
2023-08-20 03:00:45 +02:00
parsedPackageJson.scripts.build = parsedPackageJson.scripts.build
.replace("npm run check-types", "true")
.replace("npm run babel", "true");
2023-08-20 03:00:45 +02:00
fs.writeFileSync(packageJsonFilePath, Buffer.from(JSON.stringify(parsedPackageJson, null, 2), "utf8"));
2023-08-20 03:00:45 +02:00
child_process.execSync("npm run build", { "cwd": accountV2DirSrcDirPath, "stdio": "ignore" });
2023-08-20 03:00:45 +02:00
fs.writeFileSync(packageJsonFilePath, packageJsonRaw);
2023-08-20 03:00:45 +02:00
fs.rmSync(pathJoin(accountV2DirSrcDirPath, "node_modules"), { "recursive": true });
}
}
}
});
}
2021-02-28 18:40:57 +01:00
async function main() {
const buildOptions = readBuildOptions({
"projectDirPath": process.cwd(),
"processArgv": process.argv.slice(2)
});
const logger = getLogger({ "isSilent": buildOptions.isSilent });
const { keycloakVersion } = await promptKeycloakVersion();
const destDirPath = pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources", "theme");
logger.log(`Downloading builtins theme of Keycloak ${keycloakVersion} here ${destDirPath}`);
await downloadBuiltinKeycloakTheme({
"projectDirPath": process.cwd(),
keycloakVersion,
2023-08-21 04:29:32 +02:00
destDirPath
});
}
if (require.main === module) {
main();
2021-02-28 18:40:57 +01:00
}