2024-05-15 05:14:01 +02:00
|
|
|
import { downloadBuiltinKeycloakTheme } from "./shared/downloadBuiltinKeycloakTheme";
|
2023-03-20 01:30:42 +01:00
|
|
|
import { join as pathJoin, relative as pathRelative } from "path";
|
|
|
|
import { transformCodebase } from "./tools/transformCodebase";
|
2024-05-15 05:14:01 +02:00
|
|
|
import { promptKeycloakVersion } from "./shared/promptKeycloakVersion";
|
|
|
|
import { readBuildOptions } from "./shared/buildOptions";
|
2023-03-20 01:30:42 +01:00
|
|
|
import * as fs from "fs";
|
|
|
|
import { getLogger } from "./tools/logger";
|
2024-05-15 05:14:01 +02:00
|
|
|
import { getThemeSrcDirPath } from "./shared/getThemeSrcDirPath";
|
2024-02-05 08:52:58 +01:00
|
|
|
import { rmSync } from "./tools/fs.rmSync";
|
2024-05-15 05:14:01 +02:00
|
|
|
import type { CliCommandOptions } from "./main";
|
2023-03-24 05:43:34 +01:00
|
|
|
|
2024-05-15 05:14:01 +02:00
|
|
|
export async function command(params: { cliCommandOptions: CliCommandOptions }) {
|
|
|
|
const { cliCommandOptions } = params;
|
|
|
|
|
|
|
|
const buildOptions = readBuildOptions({ cliCommandOptions });
|
2023-04-19 05:04:11 +02:00
|
|
|
|
2023-09-03 23:26:34 +02:00
|
|
|
const logger = getLogger({ "isSilent": buildOptions.isSilent });
|
2023-03-20 01:30:42 +01:00
|
|
|
|
2023-06-19 00:09:21 +02:00
|
|
|
const { themeSrcDirPath } = getThemeSrcDirPath({
|
2024-02-08 00:56:33 +01:00
|
|
|
"reactAppRootDirPath": buildOptions.reactAppRootDirPath
|
2023-04-02 03:10:16 +02:00
|
|
|
});
|
2023-03-24 05:43:34 +01:00
|
|
|
|
2023-06-19 00:09:21 +02:00
|
|
|
const emailThemeSrcDirPath = pathJoin(themeSrcDirPath, "email");
|
|
|
|
|
2023-03-24 05:43:34 +01:00
|
|
|
if (fs.existsSync(emailThemeSrcDirPath)) {
|
|
|
|
logger.warn(`There is already a ${pathRelative(process.cwd(), emailThemeSrcDirPath)} directory in your project. Aborting.`);
|
2023-03-20 01:30:42 +01:00
|
|
|
|
|
|
|
process.exit(-1);
|
|
|
|
}
|
|
|
|
|
2024-05-17 05:13:41 +02:00
|
|
|
const { keycloakVersion } = await promptKeycloakVersion({
|
|
|
|
"startingFromMajor": 17
|
|
|
|
});
|
2023-03-20 01:30:42 +01:00
|
|
|
|
2024-05-17 00:54:54 +02:00
|
|
|
const builtinKeycloakThemeTmpDirPath = pathJoin(buildOptions.cacheDirPath, "initialize-email-theme_tmp");
|
|
|
|
|
|
|
|
rmSync(builtinKeycloakThemeTmpDirPath, { "recursive": true, "force": true });
|
2023-03-20 01:30:42 +01:00
|
|
|
|
|
|
|
await downloadBuiltinKeycloakTheme({
|
|
|
|
keycloakVersion,
|
2023-09-03 23:26:34 +02:00
|
|
|
"destDirPath": builtinKeycloakThemeTmpDirPath,
|
|
|
|
buildOptions
|
2023-03-20 01:30:42 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
transformCodebase({
|
|
|
|
"srcDirPath": pathJoin(builtinKeycloakThemeTmpDirPath, "base", "email"),
|
2023-03-24 05:43:34 +01:00
|
|
|
"destDirPath": emailThemeSrcDirPath
|
2023-03-20 01:30:42 +01:00
|
|
|
});
|
|
|
|
|
2023-03-21 01:50:21 +01:00
|
|
|
{
|
2023-03-24 05:43:34 +01:00
|
|
|
const themePropertyFilePath = pathJoin(emailThemeSrcDirPath, "theme.properties");
|
2023-03-21 01:50:21 +01:00
|
|
|
|
|
|
|
fs.writeFileSync(themePropertyFilePath, Buffer.from(`parent=base\n${fs.readFileSync(themePropertyFilePath).toString("utf8")}`, "utf8"));
|
|
|
|
}
|
|
|
|
|
2023-03-24 05:43:34 +01:00
|
|
|
logger.log(`${pathRelative(process.cwd(), emailThemeSrcDirPath)} ready to be customized, feel free to remove every file you do not customize`);
|
2023-03-20 01:30:42 +01:00
|
|
|
|
2024-05-17 00:54:54 +02:00
|
|
|
rmSync(builtinKeycloakThemeTmpDirPath, { "recursive": true });
|
2023-03-24 05:43:34 +01:00
|
|
|
}
|