refactor
This commit is contained in:
parent
c8ca598465
commit
ff6b91b801
@ -66,8 +66,11 @@ export async function generateResources(params: {
|
|||||||
rmSync(resourcesDirPath, { recursive: true });
|
rmSync(resourcesDirPath, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
const getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => {
|
const getThemeTypeDirPath = (params: {
|
||||||
const { themeType } = params;
|
themeType: ThemeType | "email";
|
||||||
|
themeName: string;
|
||||||
|
}) => {
|
||||||
|
const { themeType, themeName } = params;
|
||||||
return pathJoin(resourcesDirPath, "theme", themeName, themeType);
|
return pathJoin(resourcesDirPath, "theme", themeName, themeType);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -85,7 +88,7 @@ export async function generateResources(params: {
|
|||||||
(assert(buildContext.implementedThemeTypes.account.isImplemented),
|
(assert(buildContext.implementedThemeTypes.account.isImplemented),
|
||||||
buildContext.implementedThemeTypes.account.type === "Single-Page");
|
buildContext.implementedThemeTypes.account.type === "Single-Page");
|
||||||
|
|
||||||
const themeTypeDirPath = getThemeTypeDirPath({ themeType });
|
const themeTypeDirPath = getThemeTypeDirPath({ themeName, themeType });
|
||||||
|
|
||||||
apply_replacers_and_move_to_theme_resources: {
|
apply_replacers_and_move_to_theme_resources: {
|
||||||
const destDirPath = pathJoin(
|
const destDirPath = pathJoin(
|
||||||
@ -106,6 +109,7 @@ export async function generateResources(params: {
|
|||||||
transformCodebase({
|
transformCodebase({
|
||||||
srcDirPath: pathJoin(
|
srcDirPath: pathJoin(
|
||||||
getThemeTypeDirPath({
|
getThemeTypeDirPath({
|
||||||
|
themeName,
|
||||||
themeType: "login"
|
themeType: "login"
|
||||||
}),
|
}),
|
||||||
"resources",
|
"resources",
|
||||||
@ -251,7 +255,7 @@ export async function generateResources(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const messagesDirPath_dest = pathJoin(
|
const messagesDirPath_dest = pathJoin(
|
||||||
getThemeTypeDirPath({ themeType: "account" }),
|
getThemeTypeDirPath({ themeName, themeType: "account" }),
|
||||||
"messages"
|
"messages"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -365,7 +369,7 @@ export async function generateResources(params: {
|
|||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
srcDirPath: emailThemeSrcDirPath,
|
srcDirPath: emailThemeSrcDirPath,
|
||||||
destDirPath: getThemeTypeDirPath({ themeType: "email" })
|
destDirPath: getThemeTypeDirPath({ themeName, themeType: "email" })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,7 +384,10 @@ export async function generateResources(params: {
|
|||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
srcDirPath: pathJoin(getThisCodebaseRootDirPath(), "res", "account-v1"),
|
srcDirPath: pathJoin(getThisCodebaseRootDirPath(), "res", "account-v1"),
|
||||||
destDirPath: pathJoin(resourcesDirPath, "theme", "account-v1", "account")
|
destDirPath: getThemeTypeDirPath({
|
||||||
|
themeName: "account-v1",
|
||||||
|
themeType: "account"
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,12 +420,10 @@ export async function generateResources(params: {
|
|||||||
if (themeVariantName === themeName) {
|
if (themeVariantName === themeName) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const mainThemeDirPath = pathJoin(resourcesDirPath, "theme", themeName);
|
|
||||||
const themeVariantDirPath = pathJoin(mainThemeDirPath, "..", themeVariantName);
|
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
srcDirPath: mainThemeDirPath,
|
srcDirPath: pathJoin(resourcesDirPath, "theme", themeName),
|
||||||
destDirPath: themeVariantDirPath,
|
destDirPath: pathJoin(resourcesDirPath, "theme", themeVariantName),
|
||||||
transformSourceCode: ({ fileRelativePath, sourceCode }) => {
|
transformSourceCode: ({ fileRelativePath, sourceCode }) => {
|
||||||
if (
|
if (
|
||||||
pathExtname(fileRelativePath) === ".ftl" &&
|
pathExtname(fileRelativePath) === ".ftl" &&
|
||||||
@ -445,37 +450,34 @@ export async function generateResources(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const themeName of buildContext.themeNames) {
|
for (const themeName of buildContext.themeNames) {
|
||||||
objectEntries(writeMessagePropertiesFilesByThemeType).forEach(
|
for (const [themeType, writeMessagePropertiesFiles] of objectEntries(
|
||||||
([themeType, writeMessagePropertiesFiles]) => {
|
writeMessagePropertiesFilesByThemeType
|
||||||
if (writeMessagePropertiesFiles === undefined) {
|
)) {
|
||||||
return;
|
// NOTE: This is just a quirk of the type system: We can't really differentiate in a record
|
||||||
}
|
// between the case where the key isn't present and the case where the value is `undefined`.
|
||||||
writeMessagePropertiesFiles({
|
if (writeMessagePropertiesFiles === undefined) {
|
||||||
messageDirPath: pathJoin(
|
return;
|
||||||
resourcesDirPath,
|
|
||||||
"theme",
|
|
||||||
themeName,
|
|
||||||
themeType,
|
|
||||||
"messages"
|
|
||||||
),
|
|
||||||
themeName
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
);
|
writeMessagePropertiesFiles({
|
||||||
|
messageDirPath: pathJoin(
|
||||||
|
getThemeTypeDirPath({ themeName, themeType }),
|
||||||
|
"messages"
|
||||||
|
),
|
||||||
|
themeName
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
email: {
|
modify_email_theme_per_variant: {
|
||||||
if (!buildContext.implementedThemeTypes.email.isImplemented) {
|
if (!buildContext.implementedThemeTypes.email.isImplemented) {
|
||||||
break email;
|
break modify_email_theme_per_variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const themeName of buildContext.themeNames) {
|
for (const themeName of buildContext.themeNames) {
|
||||||
const emailThemeDirPath = pathJoin(
|
const emailThemeDirPath = getThemeTypeDirPath({
|
||||||
resourcesDirPath,
|
|
||||||
"theme",
|
|
||||||
themeName,
|
themeName,
|
||||||
"email"
|
themeType: "email"
|
||||||
);
|
});
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
srcDirPath: emailThemeDirPath,
|
srcDirPath: emailThemeDirPath,
|
||||||
@ -489,7 +491,7 @@ export async function generateResources(params: {
|
|||||||
modifiedSourceCode: Buffer.from(
|
modifiedSourceCode: Buffer.from(
|
||||||
sourceCode
|
sourceCode
|
||||||
.toString("utf8")
|
.toString("utf8")
|
||||||
.replace(/xKeycloakify.themeName/g, `"${themeName}"`),
|
.replace(/xKeycloakify\.themeName/g, `"${themeName}"`),
|
||||||
"utf8"
|
"utf8"
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user