Fix bug with asset paths
This commit is contained in:
src/bin/keycloakify/generateTheme
@ -30,7 +30,6 @@ export async function downloadKeycloakStaticResources(
|
|||||||
|
|
||||||
const tmpDirPath = pathJoin(
|
const tmpDirPath = pathJoin(
|
||||||
themeDirPath,
|
themeDirPath,
|
||||||
"..",
|
|
||||||
`tmp_suLeKsxId_${crypto.createHash("sha256").update(`${themeType}-${keycloakVersion}`).digest("hex").slice(0, 8)}`
|
`tmp_suLeKsxId_${crypto.createHash("sha256").update(`${themeType}-${keycloakVersion}`).digest("hex").slice(0, 8)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { transformCodebase } from "../../tools/transformCodebase";
|
import { transformCodebase } from "../../tools/transformCodebase";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { join as pathJoin, basename as pathBasename } from "path";
|
import { join as pathJoin, basename as pathBasename, resolve as pathResolve } from "path";
|
||||||
import { replaceImportsFromStaticInJsCode } from "../replacers/replaceImportsFromStaticInJsCode";
|
import { replaceImportsFromStaticInJsCode } from "../replacers/replaceImportsFromStaticInJsCode";
|
||||||
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
|
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
|
||||||
import { generateFtlFilesCodeFactory, loginThemePageIds, accountThemePageIds } from "../generateFtl";
|
import { generateFtlFilesCodeFactory, loginThemePageIds, accountThemePageIds } from "../generateFtl";
|
||||||
@ -36,7 +36,7 @@ export async function generateTheme(params: {
|
|||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const { themeName, themeSrcDirPath, keycloakifySrcDirPath, buildOptions, keycloakifyVersion } = params;
|
const { themeName, themeSrcDirPath, keycloakifySrcDirPath, buildOptions, keycloakifyVersion } = params;
|
||||||
|
|
||||||
const getThemeDirPath = (params: { themeType: ThemeType | "email"; isRetrocompat?: true }) => {
|
const getThemeTypeDirPath = (params: { themeType: ThemeType | "email"; isRetrocompat?: true }) => {
|
||||||
const { themeType, isRetrocompat = false } = params;
|
const { themeType, isRetrocompat = false } = params;
|
||||||
return pathJoin(
|
return pathJoin(
|
||||||
buildOptions.keycloakifyBuildDirPath,
|
buildOptions.keycloakifyBuildDirPath,
|
||||||
@ -58,7 +58,7 @@ export async function generateTheme(params: {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const themeDirPath = getThemeDirPath({ themeType });
|
const themeTypeDirPath = getThemeTypeDirPath({ themeType });
|
||||||
|
|
||||||
copy_app_resources_to_theme_path: {
|
copy_app_resources_to_theme_path: {
|
||||||
const isFirstPass = themeType.indexOf(themeType) === 0;
|
const isFirstPass = themeType.indexOf(themeType) === 0;
|
||||||
@ -68,7 +68,7 @@ export async function generateTheme(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
"destDirPath": pathJoin(themeDirPath, "resources", "build"),
|
"destDirPath": pathJoin(themeTypeDirPath, "resources", "build"),
|
||||||
"srcDirPath": buildOptions.reactAppBuildDirPath,
|
"srcDirPath": buildOptions.reactAppBuildDirPath,
|
||||||
"transformSourceCode": ({ filePath, sourceCode }) => {
|
"transformSourceCode": ({ filePath, sourceCode }) => {
|
||||||
//NOTE: Prevent cycles, excludes the folder we generated for debug in public/
|
//NOTE: Prevent cycles, excludes the folder we generated for debug in public/
|
||||||
@ -146,18 +146,18 @@ export async function generateTheme(params: {
|
|||||||
].forEach(pageId => {
|
].forEach(pageId => {
|
||||||
const { ftlCode } = generateFtlFilesCode({ pageId });
|
const { ftlCode } = generateFtlFilesCode({ pageId });
|
||||||
|
|
||||||
fs.mkdirSync(themeDirPath, { "recursive": true });
|
fs.mkdirSync(themeTypeDirPath, { "recursive": true });
|
||||||
|
|
||||||
fs.writeFileSync(pathJoin(themeDirPath, pageId), Buffer.from(ftlCode, "utf8"));
|
fs.writeFileSync(pathJoin(themeTypeDirPath, pageId), Buffer.from(ftlCode, "utf8"));
|
||||||
});
|
});
|
||||||
|
|
||||||
generateMessageProperties({
|
generateMessageProperties({
|
||||||
themeSrcDirPath,
|
themeSrcDirPath,
|
||||||
themeType
|
themeType
|
||||||
}).forEach(({ languageTag, propertiesFileSource }) => {
|
}).forEach(({ languageTag, propertiesFileSource }) => {
|
||||||
const messagesDirPath = pathJoin(themeDirPath, "messages");
|
const messagesDirPath = pathJoin(themeTypeDirPath, "messages");
|
||||||
|
|
||||||
fs.mkdirSync(pathJoin(themeDirPath, "messages"), { "recursive": true });
|
fs.mkdirSync(pathJoin(themeTypeDirPath, "messages"), { "recursive": true });
|
||||||
|
|
||||||
const propertiesFilePath = pathJoin(messagesDirPath, `messages_${languageTag}.properties`);
|
const propertiesFilePath = pathJoin(messagesDirPath, `messages_${languageTag}.properties`);
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ export async function generateTheme(params: {
|
|||||||
return buildOptions.loginThemeResourcesFromKeycloakVersion;
|
return buildOptions.loginThemeResourcesFromKeycloakVersion;
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
themeDirPath,
|
"themeDirPath": pathResolve(pathJoin(themeTypeDirPath, "..")),
|
||||||
themeType,
|
themeType,
|
||||||
"usedResources": readStaticResourcesUsage({
|
"usedResources": readStaticResourcesUsage({
|
||||||
keycloakifySrcDirPath,
|
keycloakifySrcDirPath,
|
||||||
@ -184,7 +184,7 @@ export async function generateTheme(params: {
|
|||||||
});
|
});
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
pathJoin(themeDirPath, "theme.properties"),
|
pathJoin(themeTypeDirPath, "theme.properties"),
|
||||||
Buffer.from(
|
Buffer.from(
|
||||||
[
|
[
|
||||||
`parent=${(() => {
|
`parent=${(() => {
|
||||||
@ -204,8 +204,8 @@ export async function generateTheme(params: {
|
|||||||
|
|
||||||
if (themeType === "account" && buildOptions.doBuildRetrocompatAccountTheme) {
|
if (themeType === "account" && buildOptions.doBuildRetrocompatAccountTheme) {
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
"srcDirPath": themeDirPath,
|
"srcDirPath": themeTypeDirPath,
|
||||||
"destDirPath": getThemeDirPath({ themeType, "isRetrocompat": true }),
|
"destDirPath": getThemeTypeDirPath({ themeType, "isRetrocompat": true }),
|
||||||
"transformSourceCode": ({ filePath, sourceCode }) => {
|
"transformSourceCode": ({ filePath, sourceCode }) => {
|
||||||
if (pathBasename(filePath) === "theme.properties") {
|
if (pathBasename(filePath) === "theme.properties") {
|
||||||
return {
|
return {
|
||||||
@ -228,7 +228,7 @@ export async function generateTheme(params: {
|
|||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
"srcDirPath": emailThemeSrcDirPath,
|
"srcDirPath": emailThemeSrcDirPath,
|
||||||
"destDirPath": getThemeDirPath({ "themeType": "email" })
|
"destDirPath": getThemeTypeDirPath({ "themeType": "email" })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user