Find the email theme in src
This commit is contained in:
@ -1,27 +1,63 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import { downloadBuiltinKeycloakTheme } from "./download-builtin-keycloak-theme";
|
import { downloadBuiltinKeycloakTheme } from "./download-builtin-keycloak-theme";
|
||||||
import { keycloakThemeEmailDirPath } from "./keycloakify";
|
|
||||||
import { join as pathJoin, relative as pathRelative } from "path";
|
import { join as pathJoin, relative as pathRelative } from "path";
|
||||||
import { transformCodebase } from "./tools/transformCodebase";
|
import { transformCodebase } from "./tools/transformCodebase";
|
||||||
import { promptKeycloakVersion } from "./promptKeycloakVersion";
|
import { promptKeycloakVersion } from "./promptKeycloakVersion";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { getCliOptions } from "./tools/cliOptions";
|
import { getCliOptions } from "./tools/cliOptions";
|
||||||
import { getLogger } from "./tools/logger";
|
import { getLogger } from "./tools/logger";
|
||||||
|
import { crawl } from "./tools/crawl";
|
||||||
|
import { exclude } from "tsafe/exclude";
|
||||||
|
|
||||||
(async () => {
|
const reactProjectDirPath = process.cwd();
|
||||||
|
|
||||||
|
const themeSrcDirBasename = "keycloak-theme";
|
||||||
|
|
||||||
|
function getThemeSrcDirPath() {
|
||||||
|
const themeSrcDirPath: string | undefined = crawl(pathJoin(reactProjectDirPath, "src"))
|
||||||
|
.map(fileRelativePath => {
|
||||||
|
const split = fileRelativePath.split(themeSrcDirBasename);
|
||||||
|
|
||||||
|
if (split.length !== 2) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return split[0] + themeSrcDirBasename;
|
||||||
|
})
|
||||||
|
.filter(exclude(undefined))[0];
|
||||||
|
return { themeSrcDirPath };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getEmailThemeSrcDirPath() {
|
||||||
|
const { themeSrcDirPath } = getThemeSrcDirPath();
|
||||||
|
|
||||||
|
const emailThemeSrcDirPath = themeSrcDirPath === undefined ? undefined : pathJoin(themeSrcDirPath, "email");
|
||||||
|
|
||||||
|
return { emailThemeSrcDirPath };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
const { isSilent } = getCliOptions(process.argv.slice(2));
|
const { isSilent } = getCliOptions(process.argv.slice(2));
|
||||||
const logger = getLogger({ isSilent });
|
const logger = getLogger({ isSilent });
|
||||||
|
|
||||||
if (fs.existsSync(keycloakThemeEmailDirPath)) {
|
const { emailThemeSrcDirPath } = getEmailThemeSrcDirPath();
|
||||||
logger.warn(`There is already a ${pathRelative(process.cwd(), keycloakThemeEmailDirPath)} directory in your project. Aborting.`);
|
|
||||||
|
if (emailThemeSrcDirPath === undefined) {
|
||||||
|
logger.warn(`Couldn't locate you ${themeSrcDirBasename} directory`);
|
||||||
|
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(emailThemeSrcDirPath)) {
|
||||||
|
logger.warn(`There is already a ${pathRelative(process.cwd(), emailThemeSrcDirPath)} directory in your project. Aborting.`);
|
||||||
|
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { keycloakVersion } = await promptKeycloakVersion();
|
const { keycloakVersion } = await promptKeycloakVersion();
|
||||||
|
|
||||||
const builtinKeycloakThemeTmpDirPath = pathJoin(keycloakThemeEmailDirPath, "..", "tmp_xIdP3_builtin_keycloak_theme");
|
const builtinKeycloakThemeTmpDirPath = pathJoin(emailThemeSrcDirPath, "..", "tmp_xIdP3_builtin_keycloak_theme");
|
||||||
|
|
||||||
await downloadBuiltinKeycloakTheme({
|
await downloadBuiltinKeycloakTheme({
|
||||||
keycloakVersion,
|
keycloakVersion,
|
||||||
@ -31,18 +67,20 @@ import { getLogger } from "./tools/logger";
|
|||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
"srcDirPath": pathJoin(builtinKeycloakThemeTmpDirPath, "base", "email"),
|
"srcDirPath": pathJoin(builtinKeycloakThemeTmpDirPath, "base", "email"),
|
||||||
"destDirPath": keycloakThemeEmailDirPath
|
"destDirPath": emailThemeSrcDirPath
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
const themePropertyFilePath = pathJoin(keycloakThemeEmailDirPath, "theme.properties");
|
const themePropertyFilePath = pathJoin(emailThemeSrcDirPath, "theme.properties");
|
||||||
|
|
||||||
fs.writeFileSync(themePropertyFilePath, Buffer.from(`parent=base\n${fs.readFileSync(themePropertyFilePath).toString("utf8")}`, "utf8"));
|
fs.writeFileSync(themePropertyFilePath, Buffer.from(`parent=base\n${fs.readFileSync(themePropertyFilePath).toString("utf8")}`, "utf8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.log(
|
logger.log(`${pathRelative(process.cwd(), emailThemeSrcDirPath)} ready to be customized, feel free to remove every file you do not customize`);
|
||||||
`${pathRelative(process.cwd(), keycloakThemeEmailDirPath)} ready to be customized, feel free to remove every file you do not customize`
|
|
||||||
);
|
|
||||||
|
|
||||||
fs.rmSync(builtinKeycloakThemeTmpDirPath, { "recursive": true, "force": true });
|
fs.rmSync(builtinKeycloakThemeTmpDirPath, { "recursive": true, "force": true });
|
||||||
})();
|
}
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
|
main();
|
||||||
|
}
|
||||||
|
@ -10,7 +10,6 @@ import { isInside } from "../tools/isInside";
|
|||||||
import type { BuildOptions } from "./BuildOptions";
|
import type { BuildOptions } from "./BuildOptions";
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import { Reflect } from "tsafe/Reflect";
|
import { Reflect } from "tsafe/Reflect";
|
||||||
import { getLogger } from "../tools/logger";
|
|
||||||
|
|
||||||
export type BuildOptionsLike = BuildOptionsLike.Standalone | BuildOptionsLike.ExternalAssets;
|
export type BuildOptionsLike = BuildOptionsLike.Standalone | BuildOptionsLike.ExternalAssets;
|
||||||
|
|
||||||
@ -56,13 +55,11 @@ export namespace BuildOptionsLike {
|
|||||||
export async function generateKeycloakThemeResources(params: {
|
export async function generateKeycloakThemeResources(params: {
|
||||||
reactAppBuildDirPath: string;
|
reactAppBuildDirPath: string;
|
||||||
keycloakThemeBuildingDirPath: string;
|
keycloakThemeBuildingDirPath: string;
|
||||||
keycloakThemeEmailDirPath: string;
|
emailThemeSrcDirPath: string | undefined;
|
||||||
keycloakVersion: string;
|
keycloakVersion: string;
|
||||||
buildOptions: BuildOptionsLike;
|
buildOptions: BuildOptionsLike;
|
||||||
}): Promise<{ doBundlesEmailTemplate: boolean }> {
|
}): Promise<{ doBundlesEmailTemplate: boolean }> {
|
||||||
const { reactAppBuildDirPath, keycloakThemeBuildingDirPath, keycloakThemeEmailDirPath, keycloakVersion, buildOptions } = params;
|
const { reactAppBuildDirPath, keycloakThemeBuildingDirPath, emailThemeSrcDirPath, keycloakVersion, buildOptions } = params;
|
||||||
|
|
||||||
const logger = getLogger({ isSilent: buildOptions.isSilent });
|
|
||||||
|
|
||||||
const getThemeDirPath = (themeType: ThemeType | "email") =>
|
const getThemeDirPath = (themeType: ThemeType | "email") =>
|
||||||
pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", buildOptions.themeName, themeType);
|
pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", buildOptions.themeName, themeType);
|
||||||
@ -228,13 +225,7 @@ export async function generateKeycloakThemeResources(params: {
|
|||||||
let doBundlesEmailTemplate: boolean;
|
let doBundlesEmailTemplate: boolean;
|
||||||
|
|
||||||
email: {
|
email: {
|
||||||
if (!fs.existsSync(keycloakThemeEmailDirPath)) {
|
if (emailThemeSrcDirPath === undefined) {
|
||||||
logger.log(
|
|
||||||
[
|
|
||||||
`Not bundling email template because ${pathBasename(keycloakThemeEmailDirPath)} does not exist`,
|
|
||||||
`To start customizing the email template, run: 👉 npx create-keycloak-email-directory 👈`
|
|
||||||
].join("\n")
|
|
||||||
);
|
|
||||||
doBundlesEmailTemplate = false;
|
doBundlesEmailTemplate = false;
|
||||||
break email;
|
break email;
|
||||||
}
|
}
|
||||||
@ -242,7 +233,7 @@ export async function generateKeycloakThemeResources(params: {
|
|||||||
doBundlesEmailTemplate = true;
|
doBundlesEmailTemplate = true;
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
"srcDirPath": keycloakThemeEmailDirPath,
|
"srcDirPath": emailThemeSrcDirPath,
|
||||||
"destDirPath": getThemeDirPath("email")
|
"destDirPath": getThemeDirPath("email")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,12 @@ import { getLogger } from "../tools/logger";
|
|||||||
import { getCliOptions } from "../tools/cliOptions";
|
import { getCliOptions } from "../tools/cliOptions";
|
||||||
import jar from "../tools/jar";
|
import jar from "../tools/jar";
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import type { Equals } from "tsafe";
|
import { Equals } from "tsafe";
|
||||||
|
import { getEmailThemeSrcDirPath } from "../initialize-email-theme";
|
||||||
|
|
||||||
const reactProjectDirPath = process.cwd();
|
const reactProjectDirPath = process.cwd();
|
||||||
|
|
||||||
export const keycloakThemeBuildingDirPath = pathJoin(reactProjectDirPath, "build_keycloak");
|
export const keycloakThemeBuildingDirPath = pathJoin(reactProjectDirPath, "build_keycloak");
|
||||||
export const keycloakThemeEmailDirPath = pathJoin(reactProjectDirPath, "src", "keycloak-theme", "email");
|
|
||||||
|
|
||||||
export async function main() {
|
export async function main() {
|
||||||
const { isSilent, hasExternalAssets } = getCliOptions(process.argv.slice(2));
|
const { isSilent, hasExternalAssets } = getCliOptions(process.argv.slice(2));
|
||||||
@ -38,7 +38,7 @@ export async function main() {
|
|||||||
|
|
||||||
const { doBundlesEmailTemplate } = await generateKeycloakThemeResources({
|
const { doBundlesEmailTemplate } = await generateKeycloakThemeResources({
|
||||||
keycloakThemeBuildingDirPath,
|
keycloakThemeBuildingDirPath,
|
||||||
keycloakThemeEmailDirPath,
|
"emailThemeSrcDirPath": getEmailThemeSrcDirPath().emailThemeSrcDirPath,
|
||||||
"reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"),
|
"reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"),
|
||||||
buildOptions,
|
buildOptions,
|
||||||
//We have to leave it at that otherwise we break our default theme.
|
//We have to leave it at that otherwise we break our default theme.
|
||||||
|
Reference in New Issue
Block a user