From d5bb7679ca76a363438898da4e5f8da4c6e9427c Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Thu, 16 May 2024 09:35:31 +0200 Subject: [PATCH] Make it clearer what's going on when calling post build script --- .../generateTheme/generateSrcMainResources.ts | 13 +++++++------ src/vite-plugin/vite-plugin.ts | 8 +++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/bin/keycloakify/generateTheme/generateSrcMainResources.ts b/src/bin/keycloakify/generateTheme/generateSrcMainResources.ts index 927abd3e..98cc46c5 100644 --- a/src/bin/keycloakify/generateTheme/generateSrcMainResources.ts +++ b/src/bin/keycloakify/generateTheme/generateSrcMainResources.ts @@ -20,7 +20,9 @@ import { readFieldNameUsage } from "./readFieldNameUsage"; import { readExtraPagesNames } from "./readExtraPageNames"; import { generateMessageProperties } from "./generateMessageProperties"; import { bringInAccountV1 } from "./bringInAccountV1"; +import { getThemeSrcDirPath } from "../../shared/getThemeSrcDirPath"; import { rmSync } from "../../tools/fs.rmSync"; +import { readThisNpmProjectVersion } from "../../tools/readThisNpmProjectVersion"; export type BuildOptionsLike = { bundler: "vite" | "webpack"; @@ -32,19 +34,19 @@ export type BuildOptionsLike = { assetsDirPath: string; urlPathname: string | undefined; npmWorkspaceRootDirPath: string; + reactAppRootDirPath: string; }; assert(); export async function generateSrcMainResources(params: { themeName: string; - themeSrcDirPath: string; - keycloakifySrcDirPath: string; buildOptions: BuildOptionsLike; - keycloakifyVersion: string; srcMainResourcesDirPath: string; }): Promise { - const { themeName, themeSrcDirPath, keycloakifySrcDirPath, buildOptions, keycloakifyVersion, srcMainResourcesDirPath } = params; + const { themeName, buildOptions, srcMainResourcesDirPath } = params; + + const { themeSrcDirPath } = getThemeSrcDirPath({ "reactAppRootDirPath": buildOptions.reactAppRootDirPath }); const getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => { const { themeType } = params; @@ -137,10 +139,9 @@ export async function generateSrcMainResources(params: { "indexHtmlCode": fs.readFileSync(pathJoin(buildOptions.reactAppBuildDirPath, "index.html")).toString("utf8"), cssGlobalsToDefine, buildOptions, - keycloakifyVersion, + "keycloakifyVersion": readThisNpmProjectVersion(), themeType, "fieldNames": readFieldNameUsage({ - keycloakifySrcDirPath, themeSrcDirPath, themeType }) diff --git a/src/vite-plugin/vite-plugin.ts b/src/vite-plugin/vite-plugin.ts index 1a997289..111c1073 100644 --- a/src/vite-plugin/vite-plugin.ts +++ b/src/vite-plugin/vite-plugin.ts @@ -27,13 +27,15 @@ export function keycloakify(params?: Params) { shouldGenerateSourcemap = resolvedConfig.build.sourcemap !== false; run_post_build_script_case: { - const postBuildArgJson = process.env[vitePluginSubScriptEnvNames.runPostBuildScript]; + const envValue = process.env[vitePluginSubScriptEnvNames.runPostBuildScript]; - if (postBuildArgJson === undefined) { + if (envValue === undefined) { break run_post_build_script_case; } - await postBuild?.(JSON.parse(postBuildArgJson)); + const buildOptions = JSON.parse(envValue) as BuildOptions; + + await postBuild?.(buildOptions); process.exit(0); }