Complete build option
This commit is contained in:
parent
5a57bb59e5
commit
7c7ce159fe
@ -1,9 +1,10 @@
|
||||
import { parse as urlParse } from "url";
|
||||
import { getParsedPackageJson } from "./parsedPackageJson";
|
||||
import { readParsedPackageJson } from "./parsedPackageJson";
|
||||
import { join as pathJoin } from "path";
|
||||
import parseArgv from "minimist";
|
||||
import { getAbsoluteAndInOsFormatPath } from "../../tools/getAbsoluteAndInOsFormatPath";
|
||||
import { readResolvedViteConfig, getKeycloakifyBuildDirPath } from "./resolvedViteConfig";
|
||||
import { readResolvedViteConfig } from "./resolvedViteConfig";
|
||||
import { getKeycloakifyBuildDirPath } from "./getKeycloakifyBuildDirPath";
|
||||
|
||||
/** Consolidated build option gathered form CLI arguments and config in package.json */
|
||||
export type BuildOptions = {
|
||||
@ -31,7 +32,7 @@ export type BuildOptions = {
|
||||
export function readBuildOptions(params: { reactAppRootDirPath: string; processArgv: string[] }): BuildOptions {
|
||||
const { reactAppRootDirPath, processArgv } = params;
|
||||
|
||||
const parsedPackageJson = getParsedPackageJson({ reactAppRootDirPath });
|
||||
const parsedPackageJson = readParsedPackageJson({ reactAppRootDirPath });
|
||||
|
||||
const { resolvedViteConfig } =
|
||||
readResolvedViteConfig({
|
||||
@ -61,7 +62,25 @@ export function readBuildOptions(params: { reactAppRootDirPath: string; processA
|
||||
reactAppRootDirPath,
|
||||
"bundler": resolvedViteConfig !== undefined ? "vite" : "webpack"
|
||||
});
|
||||
//const keycloakifyBuildDirPath = keycloakifyBuildDirPath_vite ?? pathJoin(reactAppRootDirPath, "build_keycloak");
|
||||
|
||||
const reactAppBuildDirPath = (() => {
|
||||
webpack: {
|
||||
if (resolvedViteConfig !== undefined) {
|
||||
break webpack;
|
||||
}
|
||||
|
||||
if (parsedPackageJson.keycloakify?.reactAppBuildDirPath !== undefined) {
|
||||
return getAbsoluteAndInOsFormatPath({
|
||||
"pathIsh": parsedPackageJson.keycloakify?.reactAppBuildDirPath,
|
||||
"cwd": reactAppRootDirPath
|
||||
});
|
||||
}
|
||||
|
||||
return pathJoin(reactAppRootDirPath, "build");
|
||||
}
|
||||
|
||||
return pathJoin(reactAppRootDirPath, resolvedViteConfig.buildDir);
|
||||
})();
|
||||
|
||||
return {
|
||||
"bundler": resolvedViteConfig !== undefined ? "vite" : "webpack",
|
||||
@ -92,43 +111,31 @@ export function readBuildOptions(params: { reactAppRootDirPath: string; processA
|
||||
"doCreateJar": parsedPackageJson.keycloakify?.doCreateJar ?? true,
|
||||
"loginThemeResourcesFromKeycloakVersion": parsedPackageJson.keycloakify?.loginThemeResourcesFromKeycloakVersion ?? "11.0.3",
|
||||
reactAppRootDirPath,
|
||||
"reactAppBuildDirPath": (() => {
|
||||
if (resolvedViteConfig !== undefined) {
|
||||
return pathJoin(reactAppRootDirPath, resolvedViteConfig.buildDir);
|
||||
}
|
||||
|
||||
if (parsedPackageJson.keycloakify?.reactAppBuildDirPath !== undefined) {
|
||||
return getAbsoluteAndInOsFormatPath({
|
||||
"pathIsh": parsedPackageJson.keycloakify?.reactAppBuildDirPath,
|
||||
"cwd": reactAppRootDirPath
|
||||
});
|
||||
}
|
||||
|
||||
return pathJoin(reactAppRootDirPath, "build");
|
||||
})(),
|
||||
|
||||
"publicDirPath": (() => {
|
||||
if (resolvedViteConfig !== undefined) {
|
||||
return resolvedViteConfig.publicDirPath;
|
||||
}
|
||||
|
||||
if (process.env.PUBLIC_DIR_PATH !== undefined) {
|
||||
return getAbsoluteAndInOsFormatPath({
|
||||
"pathIsh": process.env.PUBLIC_DIR_PATH,
|
||||
"cwd": reactAppRootDirPath
|
||||
});
|
||||
}
|
||||
|
||||
return pathJoin(reactAppRootDirPath, "public");
|
||||
})(),
|
||||
reactAppBuildDirPath,
|
||||
keycloakifyBuildDirPath,
|
||||
"publicDirPath": (() => {
|
||||
webpack: {
|
||||
if (resolvedViteConfig !== undefined) {
|
||||
break webpack;
|
||||
}
|
||||
|
||||
if (process.env.PUBLIC_DIR_PATH !== undefined) {
|
||||
return getAbsoluteAndInOsFormatPath({
|
||||
"pathIsh": process.env.PUBLIC_DIR_PATH,
|
||||
"cwd": reactAppRootDirPath
|
||||
});
|
||||
}
|
||||
|
||||
return pathJoin(reactAppRootDirPath, "public");
|
||||
}
|
||||
|
||||
return pathJoin(reactAppRootDirPath, resolvedViteConfig.publicDir);
|
||||
})(),
|
||||
"cacheDirPath": pathJoin(
|
||||
(() => {
|
||||
let { XDG_CACHE_HOME } = process.env;
|
||||
|
||||
if (XDG_CACHE_HOME !== undefined) {
|
||||
if (process.env.XDG_CACHE_HOME !== undefined) {
|
||||
return getAbsoluteAndInOsFormatPath({
|
||||
"pathIsh": XDG_CACHE_HOME,
|
||||
"pathIsh": process.env.XDG_CACHE_HOME,
|
||||
"cwd": reactAppRootDirPath
|
||||
});
|
||||
}
|
||||
@ -138,20 +145,39 @@ export function readBuildOptions(params: { reactAppRootDirPath: string; processA
|
||||
"keycloakify"
|
||||
),
|
||||
"urlPathname": (() => {
|
||||
const { homepage } = parsedPackageJson;
|
||||
webpack: {
|
||||
if (resolvedViteConfig !== undefined) {
|
||||
break webpack;
|
||||
}
|
||||
|
||||
let url: URL | undefined = undefined;
|
||||
const { homepage } = parsedPackageJson;
|
||||
|
||||
if (homepage !== undefined) {
|
||||
url = new URL(homepage);
|
||||
let url: URL | undefined = undefined;
|
||||
|
||||
if (homepage !== undefined) {
|
||||
url = new URL(homepage);
|
||||
}
|
||||
|
||||
if (url === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const out = url.pathname.replace(/([^/])$/, "$1/");
|
||||
return out === "/" ? undefined : out;
|
||||
}
|
||||
|
||||
if (url === undefined) {
|
||||
return undefined;
|
||||
return resolvedViteConfig.urlPathname;
|
||||
})(),
|
||||
"assetsDirPath": (() => {
|
||||
webpack: {
|
||||
if (resolvedViteConfig !== undefined) {
|
||||
break webpack;
|
||||
}
|
||||
|
||||
return pathJoin(reactAppBuildDirPath, "static");
|
||||
}
|
||||
|
||||
const out = url.pathname.replace(/([^/])$/, "$1/");
|
||||
return out === "/" ? undefined : out;
|
||||
return pathJoin(reactAppBuildDirPath, resolvedViteConfig.assetsDir);
|
||||
})()
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
import { getAbsoluteAndInOsFormatPath } from "../../tools/getAbsoluteAndInOsFormatPath";
|
||||
import { join as pathJoin } from "path";
|
||||
|
||||
export function getKeycloakifyBuildDirPath(params: {
|
||||
reactAppRootDirPath: string;
|
||||
parsedPackageJson_keycloakify_keycloakifyBuildDirPath: string | undefined;
|
||||
bundler: "vite" | "webpack";
|
||||
}) {
|
||||
const { reactAppRootDirPath, parsedPackageJson_keycloakify_keycloakifyBuildDirPath, bundler } = params;
|
||||
|
||||
const keycloakifyBuildDirPath = (() => {
|
||||
if (parsedPackageJson_keycloakify_keycloakifyBuildDirPath !== undefined) {
|
||||
getAbsoluteAndInOsFormatPath({
|
||||
"pathIsh": parsedPackageJson_keycloakify_keycloakifyBuildDirPath,
|
||||
"cwd": reactAppRootDirPath
|
||||
});
|
||||
}
|
||||
|
||||
return pathJoin(
|
||||
reactAppRootDirPath,
|
||||
`${(() => {
|
||||
switch (bundler) {
|
||||
case "vite":
|
||||
return "dist";
|
||||
case "webpack":
|
||||
return "build";
|
||||
}
|
||||
})()}_keycloak`
|
||||
);
|
||||
})();
|
||||
|
||||
return { keycloakifyBuildDirPath };
|
||||
}
|
@ -1 +1 @@
|
||||
export * from "./buildOptions2";
|
||||
export * from "./buildOptions";
|
||||
|
@ -41,7 +41,7 @@ const zParsedPackageJson = z.object({
|
||||
assert<Equals<ReturnType<(typeof zParsedPackageJson)["parse"]>, ParsedPackageJson>>();
|
||||
|
||||
let parsedPackageJson: undefined | ParsedPackageJson;
|
||||
export function getParsedPackageJson(params: { reactAppRootDirPath: string }) {
|
||||
export function readParsedPackageJson(params: { reactAppRootDirPath: string }) {
|
||||
const { reactAppRootDirPath } = params;
|
||||
if (parsedPackageJson) {
|
||||
return parsedPackageJson;
|
||||
|
@ -5,7 +5,7 @@ import { z } from "zod";
|
||||
import { join as pathJoin } from "path";
|
||||
import { resolvedViteConfigJsonBasename } from "../../constants";
|
||||
import type { OptionalIfCanBeUndefined } from "../../tools/OptionalIfCanBeUndefined";
|
||||
import { getAbsoluteAndInOsFormatPath } from "../../tools/getAbsoluteAndInOsFormatPath";
|
||||
import { getKeycloakifyBuildDirPath } from "./getKeycloakifyBuildDirPath";
|
||||
|
||||
export type ResolvedViteConfig = {
|
||||
buildDir: string;
|
||||
@ -83,34 +83,3 @@ export function readResolvedViteConfig(params: {
|
||||
|
||||
return { resolvedViteConfig };
|
||||
}
|
||||
|
||||
export function getKeycloakifyBuildDirPath(params: {
|
||||
reactAppRootDirPath: string;
|
||||
parsedPackageJson_keycloakify_keycloakifyBuildDirPath: string | undefined;
|
||||
bundler: "vite" | "webpack";
|
||||
}) {
|
||||
const { reactAppRootDirPath, parsedPackageJson_keycloakify_keycloakifyBuildDirPath, bundler } = params;
|
||||
|
||||
const keycloakifyBuildDirPath = (() => {
|
||||
if (parsedPackageJson_keycloakify_keycloakifyBuildDirPath !== undefined) {
|
||||
getAbsoluteAndInOsFormatPath({
|
||||
"pathIsh": parsedPackageJson_keycloakify_keycloakifyBuildDirPath,
|
||||
"cwd": reactAppRootDirPath
|
||||
});
|
||||
}
|
||||
|
||||
return pathJoin(
|
||||
reactAppRootDirPath,
|
||||
`${(() => {
|
||||
switch (bundler) {
|
||||
case "vite":
|
||||
return "dist";
|
||||
case "webpack":
|
||||
return "build";
|
||||
}
|
||||
})()}_keycloak`
|
||||
);
|
||||
})();
|
||||
|
||||
return { keycloakifyBuildDirPath };
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path";
|
||||
import { getParsedPackageJson } from "../bin/keycloakify/parsedPackageJson";
|
||||
import { readParsedPackageJson } from "../bin/keycloakify/buildOptions/parsedPackageJson";
|
||||
import type { Plugin } from "vite";
|
||||
import { assert } from "tsafe/assert";
|
||||
import * as fs from "fs";
|
||||
import { resolvedViteConfigJsonBasename, nameOfTheGlobal, basenameOfTheKeycloakifyResourcesDir } from "../bin/constants";
|
||||
import { type ResolvedViteConfig, getKeycloakifyBuildDirPath } from "../bin/keycloakify/resolvedViteConfig";
|
||||
import type { ResolvedViteConfig } from "../bin/keycloakify/buildOptions/resolvedViteConfig";
|
||||
import { getKeycloakifyBuildDirPath } from "../bin/keycloakify/buildOptions/getKeycloakifyBuildDirPath";
|
||||
import { replaceAll } from "../bin/tools/String.prototype.replaceAll";
|
||||
import { id } from "tsafe/id";
|
||||
|
||||
@ -35,7 +36,7 @@ export function keycloakify(): Plugin {
|
||||
})();
|
||||
|
||||
const { keycloakifyBuildDirPath } = getKeycloakifyBuildDirPath({
|
||||
"parsedPackageJson_keycloakify_keycloakifyBuildDirPath": getParsedPackageJson({ reactAppRootDirPath }).keycloakify
|
||||
"parsedPackageJson_keycloakify_keycloakifyBuildDirPath": readParsedPackageJson({ reactAppRootDirPath }).keycloakify
|
||||
?.keycloakifyBuildDirPath,
|
||||
reactAppRootDirPath,
|
||||
"bundler": "vite"
|
||||
|
Loading…
x
Reference in New Issue
Block a user