Infer META-INF/keycloak-themes.jar
This commit is contained in:
parent
6bd5451230
commit
deaeab0f61
@ -15,7 +15,6 @@ import { readFileSync } from "fs";
|
|||||||
import { isInside } from "../../tools/isInside";
|
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 { existsAsync } from "../../tools/fs.existsAsync";
|
import { existsAsync } from "../../tools/fs.existsAsync";
|
||||||
|
|
||||||
export type BuildContextLike = BuildContextLike_generatePom & {
|
export type BuildContextLike = BuildContextLike_generatePom & {
|
||||||
@ -106,29 +105,45 @@ export async function buildJar(params: {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
remove_account_v1_in_meta_inf: {
|
{
|
||||||
if (!doesImplementAccountV1Theme) {
|
const filePath = pathJoin(
|
||||||
// NOTE: We do not have account v1 anyway
|
tmpResourcesDirPath,
|
||||||
break remove_account_v1_in_meta_inf;
|
"META-INF",
|
||||||
}
|
"keycloak-themes.json"
|
||||||
|
|
||||||
if (keycloakAccountV1Version !== null) {
|
|
||||||
// NOTE: No, we need to keep account-v1 in meta-inf
|
|
||||||
break remove_account_v1_in_meta_inf;
|
|
||||||
}
|
|
||||||
|
|
||||||
writeMetaInfKeycloakThemes({
|
|
||||||
resourcesDirPath: tmpResourcesDirPath,
|
|
||||||
getNewMetaInfKeycloakTheme: ({ metaInfKeycloakTheme }) => {
|
|
||||||
assert(metaInfKeycloakTheme !== undefined);
|
|
||||||
|
|
||||||
metaInfKeycloakTheme.themes = metaInfKeycloakTheme.themes.filter(
|
|
||||||
({ name }) => name !== "account-v1"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return metaInfKeycloakTheme;
|
await fs.mkdir(pathDirname(filePath));
|
||||||
}
|
|
||||||
});
|
await fs.writeFile(
|
||||||
|
filePath,
|
||||||
|
Buffer.from(
|
||||||
|
JSON.stringify(
|
||||||
|
{
|
||||||
|
themes: await (async () => {
|
||||||
|
const dirPath = pathJoin(tmpResourcesDirPath, "theme");
|
||||||
|
|
||||||
|
const themeNames = await fs.readdir(dirPath);
|
||||||
|
|
||||||
|
return Promise.all(
|
||||||
|
themeNames.map(async themeName => {
|
||||||
|
const types = await fs.readdir(
|
||||||
|
pathJoin(dirPath, themeName)
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: themeName,
|
||||||
|
types
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
})()
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
),
|
||||||
|
"utf8"
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
route_legacy_pages: {
|
route_legacy_pages: {
|
||||||
|
@ -31,11 +31,6 @@ import {
|
|||||||
type BuildContextLike as BuildContextLike_generateMessageProperties
|
type BuildContextLike as BuildContextLike_generateMessageProperties
|
||||||
} from "./generateMessageProperties";
|
} from "./generateMessageProperties";
|
||||||
import { readThisNpmPackageVersion } from "../../tools/readThisNpmPackageVersion";
|
import { readThisNpmPackageVersion } from "../../tools/readThisNpmPackageVersion";
|
||||||
import {
|
|
||||||
writeMetaInfKeycloakThemes,
|
|
||||||
type MetaInfKeycloakTheme
|
|
||||||
} from "../../shared/metaInfKeycloakThemes";
|
|
||||||
import { objectEntries } from "tsafe/objectEntries";
|
|
||||||
import { escapeStringForPropertiesFile } from "../../tools/escapeStringForPropertiesFile";
|
import { escapeStringForPropertiesFile } from "../../tools/escapeStringForPropertiesFile";
|
||||||
import { getThisCodebaseRootDirPath } from "../../tools/getThisCodebaseRootDirPath";
|
import { getThisCodebaseRootDirPath } from "../../tools/getThisCodebaseRootDirPath";
|
||||||
import propertiesParser from "properties-parser";
|
import propertiesParser from "properties-parser";
|
||||||
@ -770,33 +765,4 @@ export async function generateResources(params: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate meta-inf/keycloak-themes.json
|
|
||||||
{
|
|
||||||
const metaInfKeycloakThemes: MetaInfKeycloakTheme = { themes: [] };
|
|
||||||
|
|
||||||
for (const themeName of buildContext.themeNames) {
|
|
||||||
metaInfKeycloakThemes.themes.push({
|
|
||||||
name: themeName,
|
|
||||||
types: objectEntries(buildContext.implementedThemeTypes)
|
|
||||||
.filter(([, v]) => v.isImplemented || v.isImplemented_native)
|
|
||||||
.map(([themeType]) => themeType)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
buildContext.implementedThemeTypes.account.isImplemented &&
|
|
||||||
buildContext.implementedThemeTypes.account.type === "Multi-Page"
|
|
||||||
) {
|
|
||||||
metaInfKeycloakThemes.themes.push({
|
|
||||||
name: "account-v1",
|
|
||||||
types: ["account"]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
writeMetaInfKeycloakThemes({
|
|
||||||
resourcesDirPath,
|
|
||||||
getNewMetaInfKeycloakTheme: () => metaInfKeycloakThemes
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
import { join as pathJoin, dirname as pathDirname } from "path";
|
|
||||||
import type { ThemeType } from "./constants";
|
|
||||||
import * as fs from "fs";
|
|
||||||
|
|
||||||
export type MetaInfKeycloakTheme = {
|
|
||||||
themes: { name: string; types: (ThemeType | "email")[] }[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export function writeMetaInfKeycloakThemes(params: {
|
|
||||||
resourcesDirPath: string;
|
|
||||||
getNewMetaInfKeycloakTheme: (params: {
|
|
||||||
metaInfKeycloakTheme: MetaInfKeycloakTheme | undefined;
|
|
||||||
}) => MetaInfKeycloakTheme;
|
|
||||||
}) {
|
|
||||||
const { resourcesDirPath, getNewMetaInfKeycloakTheme } = params;
|
|
||||||
|
|
||||||
const filePath = pathJoin(resourcesDirPath, "META-INF", "keycloak-themes.json");
|
|
||||||
|
|
||||||
const currentMetaInfKeycloakTheme = !fs.existsSync(filePath)
|
|
||||||
? undefined
|
|
||||||
: (JSON.parse(
|
|
||||||
fs.readFileSync(filePath).toString("utf8")
|
|
||||||
) as MetaInfKeycloakTheme);
|
|
||||||
|
|
||||||
const newMetaInfKeycloakThemes = getNewMetaInfKeycloakTheme({
|
|
||||||
metaInfKeycloakTheme: currentMetaInfKeycloakTheme
|
|
||||||
});
|
|
||||||
|
|
||||||
{
|
|
||||||
const dirPath = pathDirname(filePath);
|
|
||||||
if (!fs.existsSync(dirPath)) {
|
|
||||||
fs.mkdirSync(dirPath, { recursive: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(
|
|
||||||
filePath,
|
|
||||||
Buffer.from(JSON.stringify(newMetaInfKeycloakThemes, null, 2), "utf8")
|
|
||||||
);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user