Make it clearer what's going on when calling post build script

This commit is contained in:
Joseph Garrone 2024-05-16 09:35:31 +02:00
parent b2a00737d3
commit d5bb7679ca
2 changed files with 12 additions and 9 deletions

View File

@ -20,7 +20,9 @@ import { readFieldNameUsage } from "./readFieldNameUsage";
import { readExtraPagesNames } from "./readExtraPageNames"; import { readExtraPagesNames } from "./readExtraPageNames";
import { generateMessageProperties } from "./generateMessageProperties"; import { generateMessageProperties } from "./generateMessageProperties";
import { bringInAccountV1 } from "./bringInAccountV1"; import { bringInAccountV1 } from "./bringInAccountV1";
import { getThemeSrcDirPath } from "../../shared/getThemeSrcDirPath";
import { rmSync } from "../../tools/fs.rmSync"; import { rmSync } from "../../tools/fs.rmSync";
import { readThisNpmProjectVersion } from "../../tools/readThisNpmProjectVersion";
export type BuildOptionsLike = { export type BuildOptionsLike = {
bundler: "vite" | "webpack"; bundler: "vite" | "webpack";
@ -32,19 +34,19 @@ export type BuildOptionsLike = {
assetsDirPath: string; assetsDirPath: string;
urlPathname: string | undefined; urlPathname: string | undefined;
npmWorkspaceRootDirPath: string; npmWorkspaceRootDirPath: string;
reactAppRootDirPath: 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; themeName: string;
themeSrcDirPath: string;
keycloakifySrcDirPath: string;
buildOptions: BuildOptionsLike; buildOptions: BuildOptionsLike;
keycloakifyVersion: string;
srcMainResourcesDirPath: string; srcMainResourcesDirPath: string;
}): Promise<void> { }): Promise<void> {
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 getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => {
const { themeType } = params; const { themeType } = params;
@ -137,10 +139,9 @@ export async function generateSrcMainResources(params: {
"indexHtmlCode": fs.readFileSync(pathJoin(buildOptions.reactAppBuildDirPath, "index.html")).toString("utf8"), "indexHtmlCode": fs.readFileSync(pathJoin(buildOptions.reactAppBuildDirPath, "index.html")).toString("utf8"),
cssGlobalsToDefine, cssGlobalsToDefine,
buildOptions, buildOptions,
keycloakifyVersion, "keycloakifyVersion": readThisNpmProjectVersion(),
themeType, themeType,
"fieldNames": readFieldNameUsage({ "fieldNames": readFieldNameUsage({
keycloakifySrcDirPath,
themeSrcDirPath, themeSrcDirPath,
themeType themeType
}) })

View File

@ -27,13 +27,15 @@ export function keycloakify(params?: Params) {
shouldGenerateSourcemap = resolvedConfig.build.sourcemap !== false; shouldGenerateSourcemap = resolvedConfig.build.sourcemap !== false;
run_post_build_script_case: { 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; break run_post_build_script_case;
} }
await postBuild?.(JSON.parse(postBuildArgJson)); const buildOptions = JSON.parse(envValue) as BuildOptions;
await postBuild?.(buildOptions);
process.exit(0); process.exit(0);
} }