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