2023-03-20 01:30:42 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
import { downloadBuiltinKeycloakTheme } from "./download-builtin-keycloak-theme";
|
|
|
|
import { join as pathJoin, relative as pathRelative } from "path";
|
|
|
|
import { transformCodebase } from "./tools/transformCodebase";
|
|
|
|
import { promptKeycloakVersion } from "./promptKeycloakVersion";
|
|
|
|
import * as fs from "fs";
|
|
|
|
import { getCliOptions } from "./tools/cliOptions";
|
|
|
|
import { getLogger } from "./tools/logger";
|
2023-03-25 04:56:17 +01:00
|
|
|
import { getThemeSrcDirPath } from "./getThemeSrcDirPath";
|
2023-03-24 05:43:34 +01:00
|
|
|
|
|
|
|
export function getEmailThemeSrcDirPath() {
|
|
|
|
const { themeSrcDirPath } = getThemeSrcDirPath();
|
|
|
|
|
|
|
|
const emailThemeSrcDirPath = themeSrcDirPath === undefined ? undefined : pathJoin(themeSrcDirPath, "email");
|
|
|
|
|
|
|
|
return { emailThemeSrcDirPath };
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
2023-03-20 01:30:42 +01:00
|
|
|
const { isSilent } = getCliOptions(process.argv.slice(2));
|
|
|
|
const logger = getLogger({ isSilent });
|
|
|
|
|
2023-03-24 05:43:34 +01:00
|
|
|
const { emailThemeSrcDirPath } = getEmailThemeSrcDirPath();
|
|
|
|
|
|
|
|
if (emailThemeSrcDirPath === undefined) {
|
2023-03-25 04:56:17 +01:00
|
|
|
logger.warn("Couldn't locate your theme source directory");
|
2023-03-24 05:43:34 +01:00
|
|
|
|
|
|
|
process.exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { keycloakVersion } = await promptKeycloakVersion();
|
|
|
|
|
2023-03-24 05:43:34 +01:00
|
|
|
const builtinKeycloakThemeTmpDirPath = pathJoin(emailThemeSrcDirPath, "..", "tmp_xIdP3_builtin_keycloak_theme");
|
2023-03-20 01:30:42 +01:00
|
|
|
|
|
|
|
await downloadBuiltinKeycloakTheme({
|
|
|
|
keycloakVersion,
|
|
|
|
"destDirPath": builtinKeycloakThemeTmpDirPath,
|
|
|
|
isSilent
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
fs.rmSync(builtinKeycloakThemeTmpDirPath, { "recursive": true, "force": true });
|
2023-03-24 05:43:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
main();
|
|
|
|
}
|