factorize access to META-INF/keycloak-themes.json
This commit is contained in:
@ -10,6 +10,7 @@ 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 { getMetaInfKeycloakThemesJsonPath } from "../../shared/metaInfKeycloakThemes";
|
||||||
|
|
||||||
export type BuildOptionsLike = BuildOptionsLike_generatePom & {
|
export type BuildOptionsLike = BuildOptionsLike_generatePom & {
|
||||||
keycloakifyBuildDirPath: string;
|
keycloakifyBuildDirPath: string;
|
||||||
@ -34,7 +35,7 @@ export async function buildJar(params: {
|
|||||||
rmSync(keycloakifyBuildTmpDirPath, { "recursive": true, "force": true });
|
rmSync(keycloakifyBuildTmpDirPath, { "recursive": true, "force": true });
|
||||||
|
|
||||||
{
|
{
|
||||||
const keycloakThemesJsonFilePath = pathJoin("src", "main", "resources", "META-INF", "keycloak-themes.json");
|
const keycloakThemesJsonFilePath = getMetaInfKeycloakThemesJsonPath({ "keycloakifyBuildDirPath": "" });
|
||||||
|
|
||||||
const themePropertiesFilePathSet = new Set(
|
const themePropertiesFilePathSet = new Set(
|
||||||
...buildOptions.themeNames.map(themeName => pathJoin("src", "main", "resources", "theme", themeName, "account", "theme.properties"))
|
...buildOptions.themeNames.map(themeName => pathJoin("src", "main", "resources", "theme", themeName, "account", "theme.properties"))
|
||||||
|
@ -5,6 +5,8 @@ import { getKeycloakVersionRangeForJar } from "./getKeycloakVersionRangeForJar";
|
|||||||
import { buildJar, BuildOptionsLike as BuildOptionsLike_buildJar } from "./buildJar";
|
import { buildJar, BuildOptionsLike as BuildOptionsLike_buildJar } from "./buildJar";
|
||||||
import type { BuildOptions } from "../../shared/buildOptions";
|
import type { BuildOptions } from "../../shared/buildOptions";
|
||||||
import { getJarFileBasename } from "./getJarFileBasename";
|
import { getJarFileBasename } from "./getJarFileBasename";
|
||||||
|
import { readMetaInfKeycloakThemes } from "../../shared/metaInfKeycloakThemes";
|
||||||
|
import { accountV1ThemeName } from "../../shared/constants";
|
||||||
|
|
||||||
export type BuildOptionsLike = BuildOptionsLike_buildJar & {
|
export type BuildOptionsLike = BuildOptionsLike_buildJar & {
|
||||||
keycloakifyBuildDirPath: string;
|
keycloakifyBuildDirPath: string;
|
||||||
@ -15,8 +17,9 @@ assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
|||||||
export async function buildJars(params: { buildOptions: BuildOptionsLike }): Promise<void> {
|
export async function buildJars(params: { buildOptions: BuildOptionsLike }): Promise<void> {
|
||||||
const { buildOptions } = params;
|
const { buildOptions } = params;
|
||||||
|
|
||||||
// TODO:
|
const doesImplementAccountTheme = readMetaInfKeycloakThemes({
|
||||||
const doesImplementAccountTheme= ;
|
"keycloakifyBuildDirPath": buildOptions.keycloakifyBuildDirPath
|
||||||
|
}).themes.some(({ name }) => name === accountV1ThemeName);
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
keycloakAccountV1Versions
|
keycloakAccountV1Versions
|
||||||
|
@ -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, resolve as pathResolve, dirname as pathDirname } from "path";
|
import { join as pathJoin, resolve as pathResolve } from "path";
|
||||||
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
|
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
|
||||||
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
|
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
|
||||||
import { generateFtlFilesCodeFactory } from "../generateFtl";
|
import { generateFtlFilesCodeFactory } from "../generateFtl";
|
||||||
@ -23,6 +23,8 @@ import { bringInAccountV1 } from "./bringInAccountV1";
|
|||||||
import { getThemeSrcDirPath } from "../../shared/getThemeSrcDirPath";
|
import { getThemeSrcDirPath } from "../../shared/getThemeSrcDirPath";
|
||||||
import { rmSync } from "../../tools/fs.rmSync";
|
import { rmSync } from "../../tools/fs.rmSync";
|
||||||
import { readThisNpmProjectVersion } from "../../tools/readThisNpmProjectVersion";
|
import { readThisNpmProjectVersion } from "../../tools/readThisNpmProjectVersion";
|
||||||
|
import { writeMetaInfKeycloakThemes, type MetaInfKeycloakTheme } from "../../shared/metaInfKeycloakThemes";
|
||||||
|
import { objectEntries } from "tsafe/objectEntries";
|
||||||
|
|
||||||
export type BuildOptionsLike = {
|
export type BuildOptionsLike = {
|
||||||
bundler: "vite" | "webpack";
|
bundler: "vite" | "webpack";
|
||||||
@ -40,10 +42,7 @@ export type BuildOptionsLike = {
|
|||||||
|
|
||||||
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
||||||
|
|
||||||
export async function generateSrcMainResourcesForMainTheme(params: {
|
export async function generateSrcMainResourcesForMainTheme(params: { themeName: string; buildOptions: BuildOptionsLike }): Promise<void> {
|
||||||
themeName: string;
|
|
||||||
buildOptions: BuildOptionsLike
|
|
||||||
}): Promise<void> {
|
|
||||||
const { themeName, buildOptions } = params;
|
const { themeName, buildOptions } = params;
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({ "reactAppRootDirPath": buildOptions.reactAppRootDirPath });
|
const { themeSrcDirPath } = getThemeSrcDirPath({ "reactAppRootDirPath": buildOptions.reactAppRootDirPath });
|
||||||
@ -230,44 +229,32 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedKeycloakThemeJson: { themes: { name: string; types: string[] }[] } = { "themes": [] };
|
if (implementedThemeTypes.account) {
|
||||||
|
await bringInAccountV1({
|
||||||
|
buildOptions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
parsedKeycloakThemeJson.themes.push({
|
{
|
||||||
|
const metaInfKeycloakThemes: MetaInfKeycloakTheme = { "themes": [] };
|
||||||
|
|
||||||
|
metaInfKeycloakThemes.themes.push({
|
||||||
"name": themeName,
|
"name": themeName,
|
||||||
"types": Object.entries(implementedThemeTypes)
|
"types": objectEntries(implementedThemeTypes)
|
||||||
.filter(([, isImplemented]) => isImplemented)
|
.filter(([, isImplemented]) => isImplemented)
|
||||||
.map(([themeType]) => themeType)
|
.map(([themeType]) => themeType)
|
||||||
});
|
});
|
||||||
|
|
||||||
account_specific_extra_work: {
|
if (implementedThemeTypes.account) {
|
||||||
if (!implementedThemeTypes.account) {
|
metaInfKeycloakThemes.themes.push({
|
||||||
break account_specific_extra_work;
|
|
||||||
}
|
|
||||||
|
|
||||||
await bringInAccountV1({
|
|
||||||
buildOptions
|
|
||||||
});
|
|
||||||
|
|
||||||
parsedKeycloakThemeJson.themes.push({
|
|
||||||
"name": accountV1ThemeName,
|
"name": accountV1ThemeName,
|
||||||
"types": ["account"]
|
"types": ["account"]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
writeMetaInfKeycloakThemes({
|
||||||
const keycloakThemeJsonFilePath = pathJoin(
|
"keycloakifyBuildDirPath": buildOptions.keycloakifyBuildDirPath,
|
||||||
buildOptions.keycloakifyBuildDirPath,
|
metaInfKeycloakThemes
|
||||||
"src",
|
});
|
||||||
"main",
|
|
||||||
"resources",
|
|
||||||
"META-INF",
|
|
||||||
"keycloak-themes.json"
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
fs.mkdirSync(pathDirname(keycloakThemeJsonFilePath));
|
|
||||||
} catch {}
|
|
||||||
|
|
||||||
fs.writeFileSync(keycloakThemeJsonFilePath, Buffer.from(JSON.stringify(parsedKeycloakThemeJson, null, 2), "utf8"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { join as pathJoin, extname as pathExtname, sep as pathSep } from "path";
|
import { join as pathJoin, extname as pathExtname, sep as pathSep } from "path";
|
||||||
import { transformCodebase } from "../../tools/transformCodebase";
|
import { transformCodebase } from "../../tools/transformCodebase";
|
||||||
import type { BuildOptions } from "../../shared/buildOptions";
|
import type { BuildOptions } from "../../shared/buildOptions";
|
||||||
|
import { readMetaInfKeycloakThemes, writeMetaInfKeycloakThemes } from "../../shared/metaInfKeycloakThemes";
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import * as fs from "fs";
|
|
||||||
|
|
||||||
export type BuildOptionsLike = {
|
export type BuildOptionsLike = {
|
||||||
keycloakifyBuildDirPath: string;
|
keycloakifyBuildDirPath: string;
|
||||||
@ -37,28 +37,20 @@ export function generateSrcMainResourcesForThemeVariant(params: { themeName: str
|
|||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
const keycloakThemeJsonFilePath = pathJoin(
|
const updatedMetaInfKeycloakThemes = readMetaInfKeycloakThemes({ "keycloakifyBuildDirPath": buildOptions.keycloakifyBuildDirPath });
|
||||||
buildOptions.keycloakifyBuildDirPath,
|
|
||||||
"src",
|
|
||||||
"main",
|
|
||||||
"resources",
|
|
||||||
"META-INF",
|
|
||||||
"keycloak-themes.json"
|
|
||||||
);
|
|
||||||
|
|
||||||
const modifiedParsedJson = JSON.parse(fs.readFileSync(keycloakThemeJsonFilePath).toString("utf8")) as {
|
updatedMetaInfKeycloakThemes.themes.push({
|
||||||
themes: { name: string; types: string[] }[];
|
|
||||||
};
|
|
||||||
|
|
||||||
modifiedParsedJson.themes.push({
|
|
||||||
"name": themeVariantName,
|
"name": themeVariantName,
|
||||||
"types": (() => {
|
"types": (() => {
|
||||||
const theme = modifiedParsedJson.themes.find(({ name }) => name === themeName);
|
const theme = updatedMetaInfKeycloakThemes.themes.find(({ name }) => name === themeName);
|
||||||
assert(theme !== undefined);
|
assert(theme !== undefined);
|
||||||
return theme.types;
|
return theme.types;
|
||||||
})()
|
})()
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.writeFileSync(keycloakThemeJsonFilePath, Buffer.from(JSON.stringify(modifiedParsedJson, null, 2), "utf8"));
|
writeMetaInfKeycloakThemes({
|
||||||
|
"keycloakifyBuildDirPath": buildOptions.keycloakifyBuildDirPath,
|
||||||
|
"metaInfKeycloakThemes": updatedMetaInfKeycloakThemes
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
src/bin/shared/metaInfKeycloakThemes.ts
Normal file
34
src/bin/shared/metaInfKeycloakThemes.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
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 getMetaInfKeycloakThemesJsonPath(params: { keycloakifyBuildDirPath: string }) {
|
||||||
|
const { keycloakifyBuildDirPath } = params;
|
||||||
|
|
||||||
|
return pathJoin(keycloakifyBuildDirPath, "src", "main", "resources", "META-INF", "keycloak-themes.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function readMetaInfKeycloakThemes(params: { keycloakifyBuildDirPath: string }): MetaInfKeycloakTheme {
|
||||||
|
const { keycloakifyBuildDirPath } = params;
|
||||||
|
|
||||||
|
return JSON.parse(fs.readFileSync(getMetaInfKeycloakThemesJsonPath({ keycloakifyBuildDirPath })).toString("utf8")) as MetaInfKeycloakTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function writeMetaInfKeycloakThemes(params: { keycloakifyBuildDirPath: string; metaInfKeycloakThemes: MetaInfKeycloakTheme }) {
|
||||||
|
const { keycloakifyBuildDirPath, metaInfKeycloakThemes } = params;
|
||||||
|
|
||||||
|
const metaInfKeycloakThemesJsonPath = getMetaInfKeycloakThemesJsonPath({ keycloakifyBuildDirPath });
|
||||||
|
|
||||||
|
{
|
||||||
|
const dirPath = pathDirname(metaInfKeycloakThemesJsonPath);
|
||||||
|
if (!fs.existsSync(dirPath)) {
|
||||||
|
fs.mkdirSync(dirPath, { "recursive": true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(metaInfKeycloakThemesJsonPath, Buffer.from(JSON.stringify(metaInfKeycloakThemes, null, 2), "utf8"));
|
||||||
|
}
|
Reference in New Issue
Block a user