2021-02-21 18:55:06 +01:00
|
|
|
|
|
2021-02-28 18:40:57 +01:00
|
|
|
|
import { transformCodebase } from "../tools/transformCodebase";
|
2021-02-21 18:55:06 +01:00
|
|
|
|
import * as fs from "fs";
|
|
|
|
|
import { join as pathJoin } from "path";
|
|
|
|
|
import {
|
|
|
|
|
replaceImportFromStaticInCssCode,
|
|
|
|
|
replaceImportFromStaticInJsCode
|
|
|
|
|
} from "./replaceImportFromStatic";
|
2021-03-07 01:47:03 +01:00
|
|
|
|
import { generateFtlFilesCodeFactory, pageIds } from "./generateFtl";
|
2021-03-04 21:43:36 +01:00
|
|
|
|
import { builtinThemesUrl } from "../install-builtin-keycloak-themes";
|
2021-03-02 01:05:15 +01:00
|
|
|
|
import { downloadAndUnzip } from "../tools/downloadAndUnzip";
|
|
|
|
|
import * as child_process from "child_process";
|
2021-03-02 12:17:24 +01:00
|
|
|
|
import { ftlValuesGlobalName } from "./ftlValuesGlobalName";
|
2021-02-21 18:55:06 +01:00
|
|
|
|
|
|
|
|
|
export function generateKeycloakThemeResources(
|
|
|
|
|
params: {
|
|
|
|
|
themeName: string;
|
|
|
|
|
reactAppBuildDirPath: string;
|
|
|
|
|
keycloakThemeBuildingDirPath: string;
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
const { themeName, reactAppBuildDirPath, keycloakThemeBuildingDirPath } = params;
|
|
|
|
|
|
|
|
|
|
const themeDirPath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName, "login");
|
|
|
|
|
|
|
|
|
|
let allCssGlobalsToDefine: Record<string, string> = {};
|
|
|
|
|
|
|
|
|
|
transformCodebase({
|
2021-03-02 01:05:15 +01:00
|
|
|
|
"destDirPath": pathJoin(themeDirPath, "resources", "build"),
|
2021-02-21 18:55:06 +01:00
|
|
|
|
"srcDirPath": reactAppBuildDirPath,
|
2021-03-03 02:31:02 +01:00
|
|
|
|
"transformSourceCode": ({ filePath, sourceCode }) => {
|
2021-02-21 18:55:06 +01:00
|
|
|
|
|
|
|
|
|
if (/\.css?$/i.test(filePath)) {
|
|
|
|
|
|
|
|
|
|
const { cssGlobalsToDefine, fixedCssCode } = replaceImportFromStaticInCssCode(
|
|
|
|
|
{ "cssCode": sourceCode.toString("utf8") }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
allCssGlobalsToDefine = {
|
|
|
|
|
...allCssGlobalsToDefine,
|
|
|
|
|
...cssGlobalsToDefine
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return { "modifiedSourceCode": Buffer.from(fixedCssCode, "utf8") };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (/\.js?$/i.test(filePath)) {
|
|
|
|
|
|
|
|
|
|
const { fixedJsCode } = replaceImportFromStaticInJsCode({
|
|
|
|
|
"jsCode": sourceCode.toString("utf8"),
|
|
|
|
|
ftlValuesGlobalName
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return { "modifiedSourceCode": Buffer.from(fixedJsCode, "utf8") };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { "modifiedSourceCode": sourceCode };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const { generateFtlFilesCode } = generateFtlFilesCodeFactory({
|
|
|
|
|
"cssGlobalsToDefine": allCssGlobalsToDefine,
|
|
|
|
|
ftlValuesGlobalName,
|
|
|
|
|
"indexHtmlCode": fs.readFileSync(
|
|
|
|
|
pathJoin(reactAppBuildDirPath, "index.html")
|
|
|
|
|
).toString("utf8")
|
|
|
|
|
});
|
|
|
|
|
|
2021-03-07 01:47:03 +01:00
|
|
|
|
pageIds.forEach(pageId => {
|
2021-02-21 18:55:06 +01:00
|
|
|
|
|
2021-03-06 22:41:36 +01:00
|
|
|
|
const { ftlCode } = generateFtlFilesCode({ pageId });
|
2021-02-21 18:55:06 +01:00
|
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
2021-03-06 22:41:36 +01:00
|
|
|
|
pathJoin(themeDirPath, pageId),
|
2021-02-21 18:55:06 +01:00
|
|
|
|
Buffer.from(ftlCode, "utf8")
|
2021-03-07 01:47:03 +01:00
|
|
|
|
);
|
2021-02-21 18:55:06 +01:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2021-03-02 01:05:15 +01:00
|
|
|
|
{
|
|
|
|
|
|
2021-03-03 02:31:02 +01:00
|
|
|
|
const tmpDirPath = pathJoin(themeDirPath, "..", "tmp_xxKdLpdIdLd");
|
2021-03-02 01:05:15 +01:00
|
|
|
|
|
|
|
|
|
downloadAndUnzip({
|
2021-03-04 21:43:36 +01:00
|
|
|
|
"url": builtinThemesUrl,
|
2021-03-03 02:31:02 +01:00
|
|
|
|
"destDirPath": tmpDirPath
|
2021-03-02 01:05:15 +01:00
|
|
|
|
});
|
|
|
|
|
|
2021-03-03 02:31:02 +01:00
|
|
|
|
transformCodebase({
|
|
|
|
|
"srcDirPath": pathJoin(tmpDirPath, "keycloak", "login", "resources"),
|
|
|
|
|
"destDirPath": pathJoin(themeDirPath, "resources")
|
|
|
|
|
});
|
2021-03-02 01:05:15 +01:00
|
|
|
|
|
2021-03-03 02:31:02 +01:00
|
|
|
|
child_process.execSync(`rm -r ${tmpDirPath}`);
|
2021-03-02 01:05:15 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-22 00:35:52 +01:00
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
pathJoin(themeDirPath, "theme.properties"),
|
2021-03-05 19:50:08 +01:00
|
|
|
|
Buffer.from("parent=keycloak", "utf8")
|
2021-02-22 00:35:52 +01:00
|
|
|
|
);
|
|
|
|
|
|
2021-02-21 18:55:06 +01:00
|
|
|
|
}
|
|
|
|
|
|