Fix async io not awaited and don't crash if .ftl files does not exist for some reason
This commit is contained in:
parent
4f11415107
commit
f57f311aab
@ -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,40 +136,49 @@ 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)
|
||||||
const ftlFilePath = pathJoin(
|
.map(pageId =>
|
||||||
tmpResourcesDirPath,
|
buildContext.themeNames.map(async themeName => {
|
||||||
"theme",
|
const ftlFilePath = pathJoin(
|
||||||
themeName,
|
tmpResourcesDirPath,
|
||||||
"login",
|
"theme",
|
||||||
pageId
|
themeName,
|
||||||
);
|
"login",
|
||||||
|
pageId
|
||||||
|
);
|
||||||
|
|
||||||
const ftlFileContent = readFileSync(ftlFilePath).toString("utf8");
|
// NOTE: https://github.com/keycloakify/keycloakify/issues/665
|
||||||
|
if (!(await existsAsync(ftlFilePath))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const ftlFileBasename = (() => {
|
const ftlFileContent = readFileSync(ftlFilePath).toString("utf8");
|
||||||
switch (pageId) {
|
|
||||||
case "register.ftl":
|
|
||||||
return "register-user-profile.ftl";
|
|
||||||
case "login-update-profile.ftl":
|
|
||||||
return "update-user-profile.ftl";
|
|
||||||
}
|
|
||||||
assert<Equals<typeof pageId, never>>(false);
|
|
||||||
})();
|
|
||||||
|
|
||||||
const modifiedFtlFileContent = ftlFileContent.replace(
|
const ftlFileBasename = (() => {
|
||||||
`"ftlTemplateFileName": "${pageId}"`,
|
switch (pageId) {
|
||||||
`"ftlTemplateFileName": "${ftlFileBasename}"`
|
case "register.ftl":
|
||||||
);
|
return "register-user-profile.ftl";
|
||||||
|
case "login-update-profile.ftl":
|
||||||
|
return "update-user-profile.ftl";
|
||||||
|
}
|
||||||
|
assert<Equals<typeof pageId, never>>(false);
|
||||||
|
})();
|
||||||
|
|
||||||
assert(modifiedFtlFileContent !== ftlFileContent);
|
const modifiedFtlFileContent = ftlFileContent.replace(
|
||||||
|
`"ftlTemplateFileName": "${pageId}"`,
|
||||||
|
`"ftlTemplateFileName": "${ftlFileBasename}"`
|
||||||
|
);
|
||||||
|
|
||||||
fs.writeFile(
|
assert(modifiedFtlFileContent !== ftlFileContent);
|
||||||
pathJoin(pathDirname(ftlFilePath), ftlFileBasename),
|
|
||||||
Buffer.from(modifiedFtlFileContent, "utf8")
|
await fs.writeFile(
|
||||||
);
|
pathJoin(pathDirname(ftlFilePath), ftlFileBasename),
|
||||||
})
|
Buffer.from(modifiedFtlFileContent, "utf8")
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.flat()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user