Rename reactAppRootDirPath -> projectDirPath and reactAppBuildDirPath -> projectBuildDirPath
This commit is contained in:
parent
6e95dacd3a
commit
3453a17c15
@ -54,7 +54,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
console.log(`→ ${pageId}`);
|
console.log(`→ ${pageId}`);
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({
|
const { themeSrcDirPath } = getThemeSrcDirPath({
|
||||||
reactAppRootDirPath: buildOptions.reactAppRootDirPath
|
projectDirPath: buildOptions.projectDirPath
|
||||||
});
|
});
|
||||||
|
|
||||||
const componentBasename = capitalize(kebabCaseToCamelCase(pageId)).replace(
|
const componentBasename = capitalize(kebabCaseToCamelCase(pageId)).replace(
|
||||||
|
@ -69,7 +69,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
console.log(`→ ${pageIdOrComponent}`);
|
console.log(`→ ${pageIdOrComponent}`);
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({
|
const { themeSrcDirPath } = getThemeSrcDirPath({
|
||||||
reactAppRootDirPath: buildOptions.reactAppRootDirPath
|
projectDirPath: buildOptions.projectDirPath
|
||||||
});
|
});
|
||||||
|
|
||||||
const componentBasename = (() => {
|
const componentBasename = (() => {
|
||||||
|
@ -13,7 +13,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
const buildOptions = readBuildOptions({ cliCommandOptions });
|
const buildOptions = readBuildOptions({ cliCommandOptions });
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({
|
const { themeSrcDirPath } = getThemeSrcDirPath({
|
||||||
reactAppRootDirPath: buildOptions.reactAppRootDirPath
|
projectDirPath: buildOptions.projectDirPath
|
||||||
});
|
});
|
||||||
|
|
||||||
const emailThemeSrcDirPath = pathJoin(themeSrcDirPath, "email");
|
const emailThemeSrcDirPath = pathJoin(themeSrcDirPath, "email");
|
||||||
|
@ -19,7 +19,7 @@ export type BuildOptionsLike = {
|
|||||||
bundler: "vite" | "webpack";
|
bundler: "vite" | "webpack";
|
||||||
themeVersion: string;
|
themeVersion: string;
|
||||||
urlPathname: string | undefined;
|
urlPathname: string | undefined;
|
||||||
reactAppBuildDirPath: string;
|
projectBuildDirPath: string;
|
||||||
assetsDirPath: string;
|
assetsDirPath: string;
|
||||||
kcContextExclusionsFtlCode: string | undefined;
|
kcContextExclusionsFtlCode: string | undefined;
|
||||||
};
|
};
|
||||||
|
@ -46,10 +46,10 @@ export type BuildOptionsLike = BuildOptionsLike_kcContextExclusionsFtlCode &
|
|||||||
bundler: "vite" | "webpack";
|
bundler: "vite" | "webpack";
|
||||||
extraThemeProperties: string[] | undefined;
|
extraThemeProperties: string[] | undefined;
|
||||||
loginThemeResourcesFromKeycloakVersion: string;
|
loginThemeResourcesFromKeycloakVersion: string;
|
||||||
reactAppBuildDirPath: string;
|
projectBuildDirPath: string;
|
||||||
assetsDirPath: string;
|
assetsDirPath: string;
|
||||||
urlPathname: string | undefined;
|
urlPathname: string | undefined;
|
||||||
reactAppRootDirPath: string;
|
projectDirPath: string;
|
||||||
keycloakifyBuildDirPath: string;
|
keycloakifyBuildDirPath: string;
|
||||||
environmentVariables: { name: string; default: string }[];
|
environmentVariables: { name: string; default: string }[];
|
||||||
};
|
};
|
||||||
@ -63,7 +63,7 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
const { themeName, buildOptions } = params;
|
const { themeName, buildOptions } = params;
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({
|
const { themeSrcDirPath } = getThemeSrcDirPath({
|
||||||
reactAppRootDirPath: buildOptions.reactAppRootDirPath
|
projectDirPath: buildOptions.projectDirPath
|
||||||
});
|
});
|
||||||
|
|
||||||
const getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => {
|
const getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => {
|
||||||
@ -124,7 +124,7 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
srcDirPath: buildOptions.reactAppBuildDirPath,
|
srcDirPath: buildOptions.projectBuildDirPath,
|
||||||
destDirPath,
|
destDirPath,
|
||||||
transformSourceCode: ({ filePath, sourceCode }) => {
|
transformSourceCode: ({ filePath, sourceCode }) => {
|
||||||
//NOTE: Prevent cycles, excludes the folder we generated for debug in public/
|
//NOTE: Prevent cycles, excludes the folder we generated for debug in public/
|
||||||
@ -132,7 +132,7 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
if (
|
if (
|
||||||
isInside({
|
isInside({
|
||||||
dirPath: pathJoin(
|
dirPath: pathJoin(
|
||||||
buildOptions.reactAppBuildDirPath,
|
buildOptions.projectBuildDirPath,
|
||||||
keycloak_resources
|
keycloak_resources
|
||||||
),
|
),
|
||||||
filePath
|
filePath
|
||||||
@ -179,7 +179,7 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
const { generateFtlFilesCode } = generateFtlFilesCodeFactory({
|
const { generateFtlFilesCode } = generateFtlFilesCodeFactory({
|
||||||
themeName,
|
themeName,
|
||||||
indexHtmlCode: fs
|
indexHtmlCode: fs
|
||||||
.readFileSync(pathJoin(buildOptions.reactAppBuildDirPath, "index.html"))
|
.readFileSync(pathJoin(buildOptions.projectBuildDirPath, "index.html"))
|
||||||
.toString("utf8"),
|
.toString("utf8"),
|
||||||
cssGlobalsToDefine,
|
cssGlobalsToDefine,
|
||||||
buildOptions,
|
buildOptions,
|
||||||
|
@ -84,7 +84,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
}
|
}
|
||||||
|
|
||||||
child_process.execSync("npx vite", {
|
child_process.execSync("npx vite", {
|
||||||
cwd: buildOptions.reactAppRootDirPath,
|
cwd: buildOptions.projectDirPath,
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
[vitePluginSubScriptEnvNames.runPostBuildScript]:
|
[vitePluginSubScriptEnvNames.runPostBuildScript]:
|
||||||
|
@ -5,7 +5,7 @@ import { replaceImportsInJsCode_webpack } from "./webpack";
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
|
||||||
export type BuildOptionsLike = {
|
export type BuildOptionsLike = {
|
||||||
reactAppBuildDirPath: string;
|
projectBuildDirPath: string;
|
||||||
assetsDirPath: string;
|
assetsDirPath: string;
|
||||||
urlPathname: string | undefined;
|
urlPathname: string | undefined;
|
||||||
bundler: "vite" | "webpack";
|
bundler: "vite" | "webpack";
|
||||||
|
@ -8,7 +8,7 @@ import * as nodePath from "path";
|
|||||||
import { replaceAll } from "../../../tools/String.prototype.replaceAll";
|
import { replaceAll } from "../../../tools/String.prototype.replaceAll";
|
||||||
|
|
||||||
export type BuildOptionsLike = {
|
export type BuildOptionsLike = {
|
||||||
reactAppBuildDirPath: string;
|
projectBuildDirPath: string;
|
||||||
assetsDirPath: string;
|
assetsDirPath: string;
|
||||||
urlPathname: string | undefined;
|
urlPathname: string | undefined;
|
||||||
};
|
};
|
||||||
@ -62,7 +62,7 @@ export function replaceImportsInJsCode_vite(params: {
|
|||||||
// Example: "assets/ or "foo/bar/"
|
// Example: "assets/ or "foo/bar/"
|
||||||
const staticDir = (() => {
|
const staticDir = (() => {
|
||||||
let out = pathRelative(
|
let out = pathRelative(
|
||||||
buildOptions.reactAppBuildDirPath,
|
buildOptions.projectBuildDirPath,
|
||||||
buildOptions.assetsDirPath
|
buildOptions.assetsDirPath
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ export function replaceImportsInJsCode_vite(params: {
|
|||||||
|
|
||||||
if (out === "/") {
|
if (out === "/") {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The assetsDirPath must be a subdirectory of reactAppBuildDirPath`
|
`The assetsDirPath must be a subdirectory of projectBuildDirPath`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import * as nodePath from "path";
|
|||||||
import { replaceAll } from "../../../tools/String.prototype.replaceAll";
|
import { replaceAll } from "../../../tools/String.prototype.replaceAll";
|
||||||
|
|
||||||
export type BuildOptionsLike = {
|
export type BuildOptionsLike = {
|
||||||
reactAppBuildDirPath: string;
|
projectBuildDirPath: string;
|
||||||
assetsDirPath: string;
|
assetsDirPath: string;
|
||||||
urlPathname: string | undefined;
|
urlPathname: string | undefined;
|
||||||
};
|
};
|
||||||
@ -50,7 +50,7 @@ export function replaceImportsInJsCode_webpack(params: {
|
|||||||
// Example: "static/ or "foo/bar/"
|
// Example: "static/ or "foo/bar/"
|
||||||
const staticDir = (() => {
|
const staticDir = (() => {
|
||||||
let out = pathRelative(
|
let out = pathRelative(
|
||||||
buildOptions.reactAppBuildDirPath,
|
buildOptions.projectBuildDirPath,
|
||||||
buildOptions.assetsDirPath
|
buildOptions.assetsDirPath
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ export function replaceImportsInJsCode_webpack(params: {
|
|||||||
|
|
||||||
if (out === "/") {
|
if (out === "/") {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The assetsDirPath must be a subdirectory of reactAppBuildDirPath`
|
`The assetsDirPath must be a subdirectory of projectBuildDirPath`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import { readThisNpmPackageVersion } from "./tools/readThisNpmPackageVersion";
|
|||||||
import * as child_process from "child_process";
|
import * as child_process from "child_process";
|
||||||
|
|
||||||
export type CliCommandOptions = {
|
export type CliCommandOptions = {
|
||||||
reactAppRootDirPath: string | undefined;
|
projectDirPath: string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const program = termost<CliCommandOptions>(
|
const program = termost<CliCommandOptions>(
|
||||||
@ -25,7 +25,7 @@ const program = termost<CliCommandOptions>(
|
|||||||
const optionsKeys: string[] = [];
|
const optionsKeys: string[] = [];
|
||||||
|
|
||||||
program.option({
|
program.option({
|
||||||
key: "reactAppRootDirPath",
|
key: "projectDirPath",
|
||||||
name: (() => {
|
name: (() => {
|
||||||
const long = "project";
|
const long = "project";
|
||||||
const short = "p";
|
const short = "p";
|
||||||
|
@ -18,8 +18,8 @@ export type BuildOptions = {
|
|||||||
groupId: string;
|
groupId: string;
|
||||||
artifactId: string;
|
artifactId: string;
|
||||||
loginThemeResourcesFromKeycloakVersion: string;
|
loginThemeResourcesFromKeycloakVersion: string;
|
||||||
reactAppRootDirPath: string;
|
projectDirPath: string;
|
||||||
reactAppBuildDirPath: string;
|
projectBuildDirPath: string;
|
||||||
/** Directory that keycloakify outputs to. Defaults to {cwd}/build_keycloak */
|
/** Directory that keycloakify outputs to. Defaults to {cwd}/build_keycloak */
|
||||||
keycloakifyBuildDirPath: string;
|
keycloakifyBuildDirPath: string;
|
||||||
publicDirPath: string;
|
publicDirPath: string;
|
||||||
@ -57,13 +57,13 @@ export function readBuildOptions(params: {
|
|||||||
}): BuildOptions {
|
}): BuildOptions {
|
||||||
const { cliCommandOptions } = params;
|
const { cliCommandOptions } = params;
|
||||||
|
|
||||||
const reactAppRootDirPath = (() => {
|
const projectDirPath = (() => {
|
||||||
if (cliCommandOptions.reactAppRootDirPath === undefined) {
|
if (cliCommandOptions.projectDirPath === undefined) {
|
||||||
return process.cwd();
|
return process.cwd();
|
||||||
}
|
}
|
||||||
|
|
||||||
return getAbsoluteAndInOsFormatPath({
|
return getAbsoluteAndInOsFormatPath({
|
||||||
pathIsh: cliCommandOptions.reactAppRootDirPath,
|
pathIsh: cliCommandOptions.projectDirPath,
|
||||||
cwd: process.cwd()
|
cwd: process.cwd()
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
@ -71,7 +71,7 @@ export function readBuildOptions(params: {
|
|||||||
const { resolvedViteConfig } = (() => {
|
const { resolvedViteConfig } = (() => {
|
||||||
if (
|
if (
|
||||||
fs
|
fs
|
||||||
.readdirSync(reactAppRootDirPath)
|
.readdirSync(projectDirPath)
|
||||||
.find(fileBasename => fileBasename.startsWith("vite.config")) ===
|
.find(fileBasename => fileBasename.startsWith("vite.config")) ===
|
||||||
undefined
|
undefined
|
||||||
) {
|
) {
|
||||||
@ -80,7 +80,7 @@ export function readBuildOptions(params: {
|
|||||||
|
|
||||||
const output = child_process
|
const output = child_process
|
||||||
.execSync("npx vite", {
|
.execSync("npx vite", {
|
||||||
cwd: reactAppRootDirPath,
|
cwd: projectDirPath,
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
[vitePluginSubScriptEnvNames.resolveViteConfig]: "true"
|
[vitePluginSubScriptEnvNames.resolveViteConfig]: "true"
|
||||||
@ -108,7 +108,7 @@ export function readBuildOptions(params: {
|
|||||||
version?: string;
|
version?: string;
|
||||||
homepage?: string;
|
homepage?: string;
|
||||||
keycloakify?: UserProvidedBuildOptions & {
|
keycloakify?: UserProvidedBuildOptions & {
|
||||||
reactAppBuildDirPath?: string;
|
projectBuildDirPath?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ export function readBuildOptions(params: {
|
|||||||
artifactId: z.string().optional(),
|
artifactId: z.string().optional(),
|
||||||
groupId: z.string().optional(),
|
groupId: z.string().optional(),
|
||||||
loginThemeResourcesFromKeycloakVersion: z.string().optional(),
|
loginThemeResourcesFromKeycloakVersion: z.string().optional(),
|
||||||
reactAppBuildDirPath: z.string().optional(),
|
projectBuildDirPath: z.string().optional(),
|
||||||
keycloakifyBuildDirPath: z.string().optional(),
|
keycloakifyBuildDirPath: z.string().optional(),
|
||||||
themeName: z.union([z.string(), z.array(z.string())]).optional()
|
themeName: z.union([z.string(), z.array(z.string())]).optional()
|
||||||
})
|
})
|
||||||
@ -138,9 +138,7 @@ export function readBuildOptions(params: {
|
|||||||
|
|
||||||
return zParsedPackageJson.parse(
|
return zParsedPackageJson.parse(
|
||||||
JSON.parse(
|
JSON.parse(
|
||||||
fs
|
fs.readFileSync(pathJoin(projectDirPath, "package.json")).toString("utf8")
|
||||||
.readFileSync(pathJoin(reactAppRootDirPath, "package.json"))
|
|
||||||
.toString("utf8")
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
@ -167,27 +165,27 @@ export function readBuildOptions(params: {
|
|||||||
return userProvidedBuildOptions.themeName;
|
return userProvidedBuildOptions.themeName;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const reactAppBuildDirPath = (() => {
|
const projectBuildDirPath = (() => {
|
||||||
webpack: {
|
webpack: {
|
||||||
if (resolvedViteConfig !== undefined) {
|
if (resolvedViteConfig !== undefined) {
|
||||||
break webpack;
|
break webpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedPackageJson.keycloakify?.reactAppBuildDirPath !== undefined) {
|
if (parsedPackageJson.keycloakify?.projectBuildDirPath !== undefined) {
|
||||||
return getAbsoluteAndInOsFormatPath({
|
return getAbsoluteAndInOsFormatPath({
|
||||||
pathIsh: parsedPackageJson.keycloakify.reactAppBuildDirPath,
|
pathIsh: parsedPackageJson.keycloakify.projectBuildDirPath,
|
||||||
cwd: reactAppRootDirPath
|
cwd: projectDirPath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathJoin(reactAppRootDirPath, "build");
|
return pathJoin(projectDirPath, "build");
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathJoin(reactAppRootDirPath, resolvedViteConfig.buildDir);
|
return pathJoin(projectDirPath, resolvedViteConfig.buildDir);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const { npmWorkspaceRootDirPath } = getNpmWorkspaceRootDirPath({
|
const { npmWorkspaceRootDirPath } = getNpmWorkspaceRootDirPath({
|
||||||
reactAppRootDirPath,
|
projectDirPath,
|
||||||
dependencyExpected: "keycloakify"
|
dependencyExpected: "keycloakify"
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -218,18 +216,18 @@ export function readBuildOptions(params: {
|
|||||||
`${themeNames[0]}-keycloak-theme`,
|
`${themeNames[0]}-keycloak-theme`,
|
||||||
loginThemeResourcesFromKeycloakVersion:
|
loginThemeResourcesFromKeycloakVersion:
|
||||||
userProvidedBuildOptions.loginThemeResourcesFromKeycloakVersion ?? "24.0.4",
|
userProvidedBuildOptions.loginThemeResourcesFromKeycloakVersion ?? "24.0.4",
|
||||||
reactAppRootDirPath,
|
projectDirPath,
|
||||||
reactAppBuildDirPath,
|
projectBuildDirPath,
|
||||||
keycloakifyBuildDirPath: (() => {
|
keycloakifyBuildDirPath: (() => {
|
||||||
if (userProvidedBuildOptions.keycloakifyBuildDirPath !== undefined) {
|
if (userProvidedBuildOptions.keycloakifyBuildDirPath !== undefined) {
|
||||||
return getAbsoluteAndInOsFormatPath({
|
return getAbsoluteAndInOsFormatPath({
|
||||||
pathIsh: userProvidedBuildOptions.keycloakifyBuildDirPath,
|
pathIsh: userProvidedBuildOptions.keycloakifyBuildDirPath,
|
||||||
cwd: reactAppRootDirPath
|
cwd: projectDirPath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathJoin(
|
return pathJoin(
|
||||||
reactAppRootDirPath,
|
projectDirPath,
|
||||||
resolvedViteConfig?.buildDir === undefined
|
resolvedViteConfig?.buildDir === undefined
|
||||||
? "build_keycloak"
|
? "build_keycloak"
|
||||||
: `${resolvedViteConfig.buildDir}_keycloak`
|
: `${resolvedViteConfig.buildDir}_keycloak`
|
||||||
@ -244,14 +242,14 @@ export function readBuildOptions(params: {
|
|||||||
if (process.env.PUBLIC_DIR_PATH !== undefined) {
|
if (process.env.PUBLIC_DIR_PATH !== undefined) {
|
||||||
return getAbsoluteAndInOsFormatPath({
|
return getAbsoluteAndInOsFormatPath({
|
||||||
pathIsh: process.env.PUBLIC_DIR_PATH,
|
pathIsh: process.env.PUBLIC_DIR_PATH,
|
||||||
cwd: reactAppRootDirPath
|
cwd: projectDirPath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathJoin(reactAppRootDirPath, "public");
|
return pathJoin(projectDirPath, "public");
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathJoin(reactAppRootDirPath, resolvedViteConfig.publicDir);
|
return pathJoin(projectDirPath, resolvedViteConfig.publicDir);
|
||||||
})(),
|
})(),
|
||||||
cacheDirPath: (() => {
|
cacheDirPath: (() => {
|
||||||
const cacheDirPath = pathJoin(
|
const cacheDirPath = pathJoin(
|
||||||
@ -300,10 +298,10 @@ export function readBuildOptions(params: {
|
|||||||
break webpack;
|
break webpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathJoin(reactAppBuildDirPath, "static");
|
return pathJoin(projectBuildDirPath, "static");
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathJoin(reactAppBuildDirPath, resolvedViteConfig.assetsDir);
|
return pathJoin(projectBuildDirPath, resolvedViteConfig.assetsDir);
|
||||||
})(),
|
})(),
|
||||||
npmWorkspaceRootDirPath,
|
npmWorkspaceRootDirPath,
|
||||||
kcContextExclusionsFtlCode: userProvidedBuildOptions.kcContextExclusionsFtlCode,
|
kcContextExclusionsFtlCode: userProvidedBuildOptions.kcContextExclusionsFtlCode,
|
||||||
|
@ -5,7 +5,7 @@ import * as fs from "fs/promises";
|
|||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
|
|
||||||
export type BuildOptionsLike = {
|
export type BuildOptionsLike = {
|
||||||
reactAppRootDirPath: string;
|
projectDirPath: string;
|
||||||
themeNames: string[];
|
themeNames: string[];
|
||||||
environmentVariables: { name: string; default: string }[];
|
environmentVariables: { name: string; default: string }[];
|
||||||
};
|
};
|
||||||
@ -18,7 +18,7 @@ export async function generateKcGenTs(params: {
|
|||||||
const { buildOptions } = params;
|
const { buildOptions } = params;
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({
|
const { themeSrcDirPath } = getThemeSrcDirPath({
|
||||||
reactAppRootDirPath: buildOptions.reactAppRootDirPath
|
projectDirPath: buildOptions.projectDirPath
|
||||||
});
|
});
|
||||||
|
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
|
@ -7,10 +7,10 @@ import { themeTypes } from "./constants";
|
|||||||
const themeSrcDirBasenames = ["keycloak-theme", "keycloak_theme"];
|
const themeSrcDirBasenames = ["keycloak-theme", "keycloak_theme"];
|
||||||
|
|
||||||
/** Can't catch error, if the directory isn't found, this function will just exit the process with an error message. */
|
/** Can't catch error, if the directory isn't found, this function will just exit the process with an error message. */
|
||||||
export function getThemeSrcDirPath(params: { reactAppRootDirPath: string }) {
|
export function getThemeSrcDirPath(params: { projectDirPath: string }) {
|
||||||
const { reactAppRootDirPath } = params;
|
const { projectDirPath } = params;
|
||||||
|
|
||||||
const srcDirPath = pathJoin(reactAppRootDirPath, "src");
|
const srcDirPath = pathJoin(projectDirPath, "src");
|
||||||
|
|
||||||
const themeSrcDirPath: string | undefined = crawl({
|
const themeSrcDirPath: string | undefined = crawl({
|
||||||
dirPath: srcDirPath,
|
dirPath: srcDirPath,
|
||||||
|
@ -7,11 +7,11 @@ import * as fs from "fs";
|
|||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
|
|
||||||
export type BuildOptionsLike = {
|
export type BuildOptionsLike = {
|
||||||
reactAppRootDirPath: string;
|
projectDirPath: string;
|
||||||
keycloakifyBuildDirPath: string;
|
keycloakifyBuildDirPath: string;
|
||||||
bundler: "vite" | "webpack";
|
bundler: "vite" | "webpack";
|
||||||
npmWorkspaceRootDirPath: string;
|
npmWorkspaceRootDirPath: string;
|
||||||
reactAppBuildDirPath: string;
|
projectBuildDirPath: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
||||||
@ -29,11 +29,11 @@ export async function appBuild(params: {
|
|||||||
return {
|
return {
|
||||||
command: "npx",
|
command: "npx",
|
||||||
args: ["vite", "build"],
|
args: ["vite", "build"],
|
||||||
cwd: buildOptions.reactAppRootDirPath
|
cwd: buildOptions.projectDirPath
|
||||||
};
|
};
|
||||||
case "webpack": {
|
case "webpack": {
|
||||||
for (const dirPath of [
|
for (const dirPath of [
|
||||||
buildOptions.reactAppRootDirPath,
|
buildOptions.projectDirPath,
|
||||||
buildOptions.npmWorkspaceRootDirPath
|
buildOptions.npmWorkspaceRootDirPath
|
||||||
]) {
|
]) {
|
||||||
try {
|
try {
|
||||||
|
@ -5,7 +5,7 @@ import { assert } from "tsafe/assert";
|
|||||||
import type { BuildOptions } from "../shared/buildOptions";
|
import type { BuildOptions } from "../shared/buildOptions";
|
||||||
|
|
||||||
export type BuildOptionsLike = {
|
export type BuildOptionsLike = {
|
||||||
reactAppRootDirPath: string;
|
projectDirPath: string;
|
||||||
keycloakifyBuildDirPath: string;
|
keycloakifyBuildDirPath: string;
|
||||||
bundler: "vite" | "webpack";
|
bundler: "vite" | "webpack";
|
||||||
npmWorkspaceRootDirPath: string;
|
npmWorkspaceRootDirPath: string;
|
||||||
@ -22,7 +22,7 @@ export async function keycloakifyBuild(params: {
|
|||||||
const dResult = new Deferred<{ isSuccess: boolean }>();
|
const dResult = new Deferred<{ isSuccess: boolean }>();
|
||||||
|
|
||||||
const child = child_process.spawn("npx", ["keycloakify", "build"], {
|
const child = child_process.spawn("npx", ["keycloakify", "build"], {
|
||||||
cwd: buildOptions.reactAppRootDirPath,
|
cwd: buildOptions.projectDirPath,
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
...(doSkipBuildJars ? { [skipBuildJarsEnvName]: "true" } : {})
|
...(doSkipBuildJars ? { [skipBuildJarsEnvName]: "true" } : {})
|
||||||
|
@ -26,7 +26,6 @@ export type CliCommandOptions = CliCommandOptions_common & {
|
|||||||
port: number;
|
port: number;
|
||||||
keycloakVersion: string | undefined;
|
keycloakVersion: string | undefined;
|
||||||
realmJsonFilePath: string | undefined;
|
realmJsonFilePath: string | undefined;
|
||||||
environmentVariables: { name: string; default: string }[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function command(params: { cliCommandOptions: CliCommandOptions }) {
|
export async function command(params: { cliCommandOptions: CliCommandOptions }) {
|
||||||
@ -398,7 +397,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
|
|
||||||
child.on("exit", process.exit);
|
child.on("exit", process.exit);
|
||||||
|
|
||||||
const srcDirPath = pathJoin(buildOptions.reactAppRootDirPath, "src");
|
const srcDirPath = pathJoin(buildOptions.projectDirPath, "src");
|
||||||
|
|
||||||
{
|
{
|
||||||
const handler = async (data: Buffer) => {
|
const handler = async (data: Buffer) => {
|
||||||
@ -430,7 +429,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
`- password: ${chalk.cyan.bold("password123")}`,
|
`- password: ${chalk.cyan.bold("password123")}`,
|
||||||
"",
|
"",
|
||||||
`Watching for changes in ${chalk.bold(
|
`Watching for changes in ${chalk.bold(
|
||||||
`.${pathSep}${pathRelative(process.cwd(), buildOptions.reactAppRootDirPath)}`
|
`.${pathSep}${pathRelative(process.cwd(), buildOptions.projectDirPath)}`
|
||||||
)}`
|
)}`
|
||||||
].join("\n")
|
].join("\n")
|
||||||
);
|
);
|
||||||
@ -472,10 +471,10 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
[
|
[
|
||||||
srcDirPath,
|
srcDirPath,
|
||||||
buildOptions.publicDirPath,
|
buildOptions.publicDirPath,
|
||||||
pathJoin(buildOptions.reactAppRootDirPath, "package.json"),
|
pathJoin(buildOptions.projectDirPath, "package.json"),
|
||||||
pathJoin(buildOptions.reactAppRootDirPath, "vite.config.ts"),
|
pathJoin(buildOptions.projectDirPath, "vite.config.ts"),
|
||||||
pathJoin(buildOptions.reactAppRootDirPath, "vite.config.js"),
|
pathJoin(buildOptions.projectDirPath, "vite.config.js"),
|
||||||
pathJoin(buildOptions.reactAppRootDirPath, "index.html"),
|
pathJoin(buildOptions.projectDirPath, "index.html"),
|
||||||
pathJoin(getThisCodebaseRootDirPath(), "src")
|
pathJoin(getThisCodebaseRootDirPath(), "src")
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
|
@ -4,14 +4,14 @@ import { assert } from "tsafe/assert";
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
|
||||||
export function getNpmWorkspaceRootDirPath(params: {
|
export function getNpmWorkspaceRootDirPath(params: {
|
||||||
reactAppRootDirPath: string;
|
projectDirPath: string;
|
||||||
dependencyExpected: string;
|
dependencyExpected: string;
|
||||||
}) {
|
}) {
|
||||||
const { reactAppRootDirPath, dependencyExpected } = params;
|
const { projectDirPath, dependencyExpected } = params;
|
||||||
|
|
||||||
const npmWorkspaceRootDirPath = (function callee(depth: number): string {
|
const npmWorkspaceRootDirPath = (function callee(depth: number): string {
|
||||||
const cwd = pathResolve(
|
const cwd = pathResolve(
|
||||||
pathJoin(...[reactAppRootDirPath, ...Array(depth).fill("..")])
|
pathJoin(...[projectDirPath, ...Array(depth).fill("..")])
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(cwd !== pathSep, "NPM workspace not found");
|
assert(cwd !== pathSep, "NPM workspace not found");
|
||||||
|
@ -26,7 +26,7 @@ export type Params = UserProvidedBuildOptions & {
|
|||||||
export function keycloakify(params?: Params) {
|
export function keycloakify(params?: Params) {
|
||||||
const { postBuild, ...userProvidedBuildOptions } = params ?? {};
|
const { postBuild, ...userProvidedBuildOptions } = params ?? {};
|
||||||
|
|
||||||
let reactAppRootDirPath: string | undefined = undefined;
|
let projectDirPath: string | undefined = undefined;
|
||||||
let urlPathname: string | undefined = undefined;
|
let urlPathname: string | undefined = undefined;
|
||||||
let buildDirPath: string | undefined = undefined;
|
let buildDirPath: string | undefined = undefined;
|
||||||
let command: "build" | "serve" | undefined = undefined;
|
let command: "build" | "serve" | undefined = undefined;
|
||||||
@ -54,7 +54,7 @@ export function keycloakify(params?: Params) {
|
|||||||
|
|
||||||
command = resolvedConfig.command;
|
command = resolvedConfig.command;
|
||||||
|
|
||||||
reactAppRootDirPath = resolvedConfig.root;
|
projectDirPath = resolvedConfig.root;
|
||||||
urlPathname = (() => {
|
urlPathname = (() => {
|
||||||
let out = resolvedConfig.env.BASE_URL;
|
let out = resolvedConfig.env.BASE_URL;
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ export function keycloakify(params?: Params) {
|
|||||||
return out;
|
return out;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
buildDirPath = pathJoin(reactAppRootDirPath, resolvedConfig.build.outDir);
|
buildDirPath = pathJoin(projectDirPath, resolvedConfig.build.outDir);
|
||||||
|
|
||||||
resolve_vite_config_case: {
|
resolve_vite_config_case: {
|
||||||
const envValue =
|
const envValue =
|
||||||
@ -102,7 +102,7 @@ export function keycloakify(params?: Params) {
|
|||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
id<ResolvedViteConfig>({
|
id<ResolvedViteConfig>({
|
||||||
publicDir: pathRelative(
|
publicDir: pathRelative(
|
||||||
reactAppRootDirPath,
|
projectDirPath,
|
||||||
resolvedConfig.publicDir
|
resolvedConfig.publicDir
|
||||||
),
|
),
|
||||||
assetsDir: resolvedConfig.build.assetsDir,
|
assetsDir: resolvedConfig.build.assetsDir,
|
||||||
@ -118,7 +118,7 @@ export function keycloakify(params?: Params) {
|
|||||||
|
|
||||||
const buildOptions = readBuildOptions({
|
const buildOptions = readBuildOptions({
|
||||||
cliCommandOptions: {
|
cliCommandOptions: {
|
||||||
reactAppRootDirPath
|
projectDirPath
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -139,11 +139,11 @@ export function keycloakify(params?: Params) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(reactAppRootDirPath !== undefined);
|
assert(projectDirPath !== undefined);
|
||||||
|
|
||||||
{
|
{
|
||||||
const isWithinSourceDirectory = id.startsWith(
|
const isWithinSourceDirectory = id.startsWith(
|
||||||
pathJoin(reactAppRootDirPath, "src") + pathSep
|
pathJoin(projectDirPath, "src") + pathSep
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isWithinSourceDirectory) {
|
if (!isWithinSourceDirectory) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user