Fix async io not awaited and don't crash if .ftl files does not exist for some reason

This commit is contained in:
Joseph Garrone
2024-09-24 19:46:36 +02:00
parent 4f11415107
commit f57f311aab

View File

@ -16,6 +16,7 @@ import { isInside } from "../../tools/isInside";
import child_process from "child_process"; import child_process from "child_process";
import { rmSync } from "../../tools/fs.rmSync"; import { rmSync } from "../../tools/fs.rmSync";
import { writeMetaInfKeycloakThemes } from "../../shared/metaInfKeycloakThemes"; import { writeMetaInfKeycloakThemes } from "../../shared/metaInfKeycloakThemes";
import { existsAsync } from "../../tools/fs.existsAsync";
export type BuildContextLike = BuildContextLike_generatePom & { export type BuildContextLike = BuildContextLike_generatePom & {
keycloakifyBuildDirPath: string; keycloakifyBuildDirPath: string;
@ -135,8 +136,10 @@ export async function buildJar(params: {
break route_legacy_pages; break route_legacy_pages;
} }
(["register.ftl", "login-update-profile.ftl"] as const).forEach(pageId => await Promise.all(
buildContext.themeNames.map(themeName => { (["register.ftl", "login-update-profile.ftl"] as const)
.map(pageId =>
buildContext.themeNames.map(async themeName => {
const ftlFilePath = pathJoin( const ftlFilePath = pathJoin(
tmpResourcesDirPath, tmpResourcesDirPath,
"theme", "theme",
@ -145,6 +148,11 @@ export async function buildJar(params: {
pageId pageId
); );
// NOTE: https://github.com/keycloakify/keycloakify/issues/665
if (!(await existsAsync(ftlFilePath))) {
return;
}
const ftlFileContent = readFileSync(ftlFilePath).toString("utf8"); const ftlFileContent = readFileSync(ftlFilePath).toString("utf8");
const ftlFileBasename = (() => { const ftlFileBasename = (() => {
@ -164,11 +172,13 @@ export async function buildJar(params: {
assert(modifiedFtlFileContent !== ftlFileContent); assert(modifiedFtlFileContent !== ftlFileContent);
fs.writeFile( await fs.writeFile(
pathJoin(pathDirname(ftlFilePath), ftlFileBasename), pathJoin(pathDirname(ftlFilePath), ftlFileBasename),
Buffer.from(modifiedFtlFileContent, "utf8") Buffer.from(modifiedFtlFileContent, "utf8")
); );
}) })
)
.flat()
); );
} }