keycloak_theme/src/bin/initialize-email-theme.ts

67 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-05-19 10:46:26 +02:00
import { downloadKeycloakDefaultTheme } from "./shared/downloadKeycloakDefaultTheme";
2023-03-20 01:30:42 +01:00
import { join as pathJoin, relative as pathRelative } from "path";
import { transformCodebase } from "./tools/transformCodebase";
import { promptKeycloakVersion } from "./shared/promptKeycloakVersion";
2024-06-09 09:15:16 +02:00
import { getBuildContext } from "./shared/buildContext";
2023-03-20 01:30:42 +01:00
import * as fs from "fs";
import type { CliCommandOptions } from "./main";
2023-03-24 05:43:34 +01:00
export async function command(params: { cliCommandOptions: CliCommandOptions }) {
const { cliCommandOptions } = params;
2024-06-09 09:15:16 +02:00
const buildContext = getBuildContext({ cliCommandOptions });
const emailThemeSrcDirPath = pathJoin(buildContext.themeSrcDirPath, "email");
2023-03-24 05:43:34 +01:00
if (fs.existsSync(emailThemeSrcDirPath)) {
2024-05-20 15:48:51 +02:00
console.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);
}
console.log("Initialize with the base email theme from which version of Keycloak?");
2024-05-17 05:13:41 +02:00
const { keycloakVersion } = await promptKeycloakVersion({
// NOTE: This is arbitrary
2024-05-20 15:48:51 +02:00
startingFromMajor: 17,
2024-06-11 19:08:36 +02:00
excludeMajorVersions: [],
doOmitPatch: false,
2024-08-13 00:10:34 +02:00
buildContext
2024-05-17 05:13:41 +02:00
});
2023-03-20 01:30:42 +01:00
2024-05-24 17:26:38 +02:00
const { defaultThemeDirPath } = await downloadKeycloakDefaultTheme({
2023-03-20 01:30:42 +01:00
keycloakVersion,
2024-06-09 09:15:16 +02:00
buildContext
2023-03-20 01:30:42 +01:00
});
transformCodebase({
2024-05-24 17:26:38 +02:00
srcDirPath: pathJoin(defaultThemeDirPath, "base", "email"),
2024-05-20 15:48:51 +02: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
2024-05-20 15:48:51 +02:00
fs.writeFileSync(
themePropertyFilePath,
Buffer.from(
`parent=base\n${fs.readFileSync(themePropertyFilePath).toString("utf8")}`,
"utf8"
)
);
2023-03-21 01:50:21 +01:00
}
2024-05-20 15:48:51 +02:00
console.log(
`The \`${pathJoin(
".",
pathRelative(process.cwd(), emailThemeSrcDirPath)
)}\` directory have been created.`
);
2024-05-18 10:24:55 +02:00
console.log("You can delete any file you don't modify.");
2023-03-24 05:43:34 +01:00
}