Stop passing as parameter the non variadic srcMainResource path

This commit is contained in:
Joseph Garrone 2024-05-17 00:39:05 +02:00
parent d5bb7679ca
commit f935922241
5 changed files with 39 additions and 22 deletions

View File

@ -10,14 +10,15 @@ import { rmSync } from "../../tools/fs.rmSync";
type BuildOptionsLike = { type BuildOptionsLike = {
cacheDirPath: string; cacheDirPath: string;
npmWorkspaceRootDirPath: string; npmWorkspaceRootDirPath: string;
keycloakifyBuildDirPath: string;
}; };
assert<BuildOptions extends BuildOptionsLike ? true : false>(); assert<BuildOptions extends BuildOptionsLike ? true : false>();
export async function bringInAccountV1(params: { buildOptions: BuildOptionsLike; srcMainResourcesDirPath: string }) { export async function bringInAccountV1(params: { buildOptions: BuildOptionsLike }) {
const { buildOptions, srcMainResourcesDirPath } = params; const { buildOptions } = params;
const builtinKeycloakThemeTmpDirPath = pathJoin(srcMainResourcesDirPath, "..", "tmp_yxdE2_builtin_keycloak_theme"); const builtinKeycloakThemeTmpDirPath = pathJoin(buildOptions.cacheDirPath, "tmp_yxdE2_builtin_keycloak_theme");
await downloadBuiltinKeycloakTheme({ await downloadBuiltinKeycloakTheme({
"destDirPath": builtinKeycloakThemeTmpDirPath, "destDirPath": builtinKeycloakThemeTmpDirPath,
@ -25,7 +26,7 @@ export async function bringInAccountV1(params: { buildOptions: BuildOptionsLike;
buildOptions buildOptions
}); });
const accountV1DirPath = pathJoin(srcMainResourcesDirPath, "theme", accountV1ThemeName, "account"); const accountV1DirPath = pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources", "theme", accountV1ThemeName, "account");
transformCodebase({ transformCodebase({
"srcDirPath": pathJoin(builtinKeycloakThemeTmpDirPath, "base", "account"), "srcDirPath": pathJoin(builtinKeycloakThemeTmpDirPath, "base", "account"),

View File

@ -35,22 +35,19 @@ export type BuildOptionsLike = {
urlPathname: string | undefined; urlPathname: string | undefined;
npmWorkspaceRootDirPath: string; npmWorkspaceRootDirPath: string;
reactAppRootDirPath: string; reactAppRootDirPath: string;
keycloakifyBuildDirPath: string;
}; };
assert<BuildOptions extends BuildOptionsLike ? true : false>(); assert<BuildOptions extends BuildOptionsLike ? true : false>();
export async function generateSrcMainResources(params: { export async function generateSrcMainResources(params: { themeName: string; buildOptions: BuildOptionsLike }): Promise<void> {
themeName: string; const { themeName, buildOptions } = params;
buildOptions: BuildOptionsLike;
srcMainResourcesDirPath: string;
}): Promise<void> {
const { themeName, buildOptions, srcMainResourcesDirPath } = params;
const { themeSrcDirPath } = getThemeSrcDirPath({ "reactAppRootDirPath": buildOptions.reactAppRootDirPath }); const { themeSrcDirPath } = getThemeSrcDirPath({ "reactAppRootDirPath": buildOptions.reactAppRootDirPath });
const getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => { const getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => {
const { themeType } = params; const { themeType } = params;
return pathJoin(srcMainResourcesDirPath, "theme", themeName, themeType); return pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources", "theme", themeName, themeType);
}; };
const cssGlobalsToDefine: Record<string, string> = {}; const cssGlobalsToDefine: Record<string, string> = {};
@ -245,7 +242,6 @@ export async function generateSrcMainResources(params: {
} }
await bringInAccountV1({ await bringInAccountV1({
srcMainResourcesDirPath,
buildOptions buildOptions
}); });
@ -256,7 +252,14 @@ export async function generateSrcMainResources(params: {
} }
{ {
const keycloakThemeJsonFilePath = pathJoin(srcMainResourcesDirPath, "META-INF", "keycloak-themes.json"); const keycloakThemeJsonFilePath = pathJoin(
buildOptions.keycloakifyBuildDirPath,
"src",
"main",
"resources",
"META-INF",
"keycloak-themes.json"
);
try { try {
fs.mkdirSync(pathDirname(keycloakThemeJsonFilePath)); fs.mkdirSync(pathDirname(keycloakThemeJsonFilePath));

View File

@ -1,4 +1,3 @@
import { join as pathJoin } from "path";
import type { BuildOptions } from "../../shared/buildOptions"; import type { BuildOptions } from "../../shared/buildOptions";
import { assert } from "tsafe/assert"; import { assert } from "tsafe/assert";
import { generateSrcMainResources, type BuildOptionsLike as BuildOptionsLike_generateSrcMainResources } from "./generateSrcMainResources"; import { generateSrcMainResources, type BuildOptionsLike as BuildOptionsLike_generateSrcMainResources } from "./generateSrcMainResources";
@ -16,11 +15,8 @@ export async function generateTheme(params: { buildOptions: BuildOptionsLike }):
const [themeName, ...themeVariantNames] = buildOptions.themeNames; const [themeName, ...themeVariantNames] = buildOptions.themeNames;
const srcMainResourcesDirPath = pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources");
await generateSrcMainResources({ await generateSrcMainResources({
themeName, themeName,
srcMainResourcesDirPath,
buildOptions buildOptions
}); });
@ -28,7 +24,7 @@ export async function generateTheme(params: { buildOptions: BuildOptionsLike }):
generateThemeVariations({ generateThemeVariations({
themeName, themeName,
themeVariantName, themeVariantName,
srcMainResourcesDirPath buildOptions
}); });
} }
} }

View File

@ -1,12 +1,19 @@
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 { assert } from "tsafe/assert"; import { assert } from "tsafe/assert";
import * as fs from "fs"; import * as fs from "fs";
export function generateThemeVariations(params: { themeName: string; themeVariantName: string; srcMainResourcesDirPath: string }) { export type BuildOptionsLike = {
const { themeName, themeVariantName, srcMainResourcesDirPath } = params; keycloakifyBuildDirPath: string;
};
const mainThemeDirPath = pathJoin(srcMainResourcesDirPath, "theme", themeName); assert<BuildOptions extends BuildOptionsLike ? true : false>();
export function generateThemeVariations(params: { themeName: string; themeVariantName: string; buildOptions: BuildOptionsLike }) {
const { themeName, themeVariantName, buildOptions } = params;
const mainThemeDirPath = pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources", "theme", themeName);
transformCodebase({ transformCodebase({
"srcDirPath": mainThemeDirPath, "srcDirPath": mainThemeDirPath,
@ -30,7 +37,14 @@ export function generateThemeVariations(params: { themeName: string; themeVarian
}); });
{ {
const keycloakThemeJsonFilePath = pathJoin(srcMainResourcesDirPath, "META-INF", "keycloak-themes.json"); const keycloakThemeJsonFilePath = pathJoin(
buildOptions.keycloakifyBuildDirPath,
"src",
"main",
"resources",
"META-INF",
"keycloak-themes.json"
);
const modifiedParsedJson = JSON.parse(fs.readFileSync(keycloakThemeJsonFilePath).toString("utf8")) as { const modifiedParsedJson = JSON.parse(fs.readFileSync(keycloakThemeJsonFilePath).toString("utf8")) as {
themes: { name: string; types: string[] }[]; themes: { name: string; types: string[] }[];

View File

@ -41,6 +41,9 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
}); });
} }
// TODO: find from META-INF/keycloak-themes.json
const doesImplementAccountTheme = true;
await buildJars({ await buildJars({
doesImplementAccountTheme, doesImplementAccountTheme,
buildOptions buildOptions