diff --git a/src/bin/add-story.ts b/src/bin/add-story.ts index 8709cc6d..d8a776d7 100644 --- a/src/bin/add-story.ts +++ b/src/bin/add-story.ts @@ -54,7 +54,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) console.log(`→ ${pageId}`); const { themeSrcDirPath } = getThemeSrcDirPath({ - reactAppRootDirPath: buildOptions.reactAppRootDirPath + projectDirPath: buildOptions.projectDirPath }); const componentBasename = capitalize(kebabCaseToCamelCase(pageId)).replace( diff --git a/src/bin/eject-page.ts b/src/bin/eject-page.ts index 64e6276b..c3119973 100644 --- a/src/bin/eject-page.ts +++ b/src/bin/eject-page.ts @@ -69,7 +69,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) console.log(`→ ${pageIdOrComponent}`); const { themeSrcDirPath } = getThemeSrcDirPath({ - reactAppRootDirPath: buildOptions.reactAppRootDirPath + projectDirPath: buildOptions.projectDirPath }); const componentBasename = (() => { diff --git a/src/bin/initialize-email-theme.ts b/src/bin/initialize-email-theme.ts index fb681958..3080f0a9 100644 --- a/src/bin/initialize-email-theme.ts +++ b/src/bin/initialize-email-theme.ts @@ -13,7 +13,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) const buildOptions = readBuildOptions({ cliCommandOptions }); const { themeSrcDirPath } = getThemeSrcDirPath({ - reactAppRootDirPath: buildOptions.reactAppRootDirPath + projectDirPath: buildOptions.projectDirPath }); const emailThemeSrcDirPath = pathJoin(themeSrcDirPath, "email"); diff --git a/src/bin/keycloakify/generateFtl/generateFtl.ts b/src/bin/keycloakify/generateFtl/generateFtl.ts index f153d323..8aa81d68 100644 --- a/src/bin/keycloakify/generateFtl/generateFtl.ts +++ b/src/bin/keycloakify/generateFtl/generateFtl.ts @@ -19,7 +19,7 @@ export type BuildOptionsLike = { bundler: "vite" | "webpack"; themeVersion: string; urlPathname: string | undefined; - reactAppBuildDirPath: string; + projectBuildDirPath: string; assetsDirPath: string; kcContextExclusionsFtlCode: string | undefined; }; diff --git a/src/bin/keycloakify/generateSrcMainResources/generateSrcMainResourcesForMainTheme.ts b/src/bin/keycloakify/generateSrcMainResources/generateSrcMainResourcesForMainTheme.ts index a0ea2ec3..4a2e66c3 100644 --- a/src/bin/keycloakify/generateSrcMainResources/generateSrcMainResourcesForMainTheme.ts +++ b/src/bin/keycloakify/generateSrcMainResources/generateSrcMainResourcesForMainTheme.ts @@ -46,10 +46,10 @@ export type BuildOptionsLike = BuildOptionsLike_kcContextExclusionsFtlCode & bundler: "vite" | "webpack"; extraThemeProperties: string[] | undefined; loginThemeResourcesFromKeycloakVersion: string; - reactAppBuildDirPath: string; + projectBuildDirPath: string; assetsDirPath: string; urlPathname: string | undefined; - reactAppRootDirPath: string; + projectDirPath: string; keycloakifyBuildDirPath: string; environmentVariables: { name: string; default: string }[]; }; @@ -63,7 +63,7 @@ export async function generateSrcMainResourcesForMainTheme(params: { const { themeName, buildOptions } = params; const { themeSrcDirPath } = getThemeSrcDirPath({ - reactAppRootDirPath: buildOptions.reactAppRootDirPath + projectDirPath: buildOptions.projectDirPath }); const getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => { @@ -124,7 +124,7 @@ export async function generateSrcMainResourcesForMainTheme(params: { } transformCodebase({ - srcDirPath: buildOptions.reactAppBuildDirPath, + srcDirPath: buildOptions.projectBuildDirPath, destDirPath, transformSourceCode: ({ filePath, sourceCode }) => { //NOTE: Prevent cycles, excludes the folder we generated for debug in public/ @@ -132,7 +132,7 @@ export async function generateSrcMainResourcesForMainTheme(params: { if ( isInside({ dirPath: pathJoin( - buildOptions.reactAppBuildDirPath, + buildOptions.projectBuildDirPath, keycloak_resources ), filePath @@ -179,7 +179,7 @@ export async function generateSrcMainResourcesForMainTheme(params: { const { generateFtlFilesCode } = generateFtlFilesCodeFactory({ themeName, indexHtmlCode: fs - .readFileSync(pathJoin(buildOptions.reactAppBuildDirPath, "index.html")) + .readFileSync(pathJoin(buildOptions.projectBuildDirPath, "index.html")) .toString("utf8"), cssGlobalsToDefine, buildOptions, diff --git a/src/bin/keycloakify/keycloakify.ts b/src/bin/keycloakify/keycloakify.ts index 524d71cd..759886ab 100644 --- a/src/bin/keycloakify/keycloakify.ts +++ b/src/bin/keycloakify/keycloakify.ts @@ -84,7 +84,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) } child_process.execSync("npx vite", { - cwd: buildOptions.reactAppRootDirPath, + cwd: buildOptions.projectDirPath, env: { ...process.env, [vitePluginSubScriptEnvNames.runPostBuildScript]: diff --git a/src/bin/keycloakify/replacers/replaceImportsInJsCode/replaceImportsInJsCode.ts b/src/bin/keycloakify/replacers/replaceImportsInJsCode/replaceImportsInJsCode.ts index bfff6d76..3bb7603f 100644 --- a/src/bin/keycloakify/replacers/replaceImportsInJsCode/replaceImportsInJsCode.ts +++ b/src/bin/keycloakify/replacers/replaceImportsInJsCode/replaceImportsInJsCode.ts @@ -5,7 +5,7 @@ import { replaceImportsInJsCode_webpack } from "./webpack"; import * as fs from "fs"; export type BuildOptionsLike = { - reactAppBuildDirPath: string; + projectBuildDirPath: string; assetsDirPath: string; urlPathname: string | undefined; bundler: "vite" | "webpack"; diff --git a/src/bin/keycloakify/replacers/replaceImportsInJsCode/vite.ts b/src/bin/keycloakify/replacers/replaceImportsInJsCode/vite.ts index e55a6bdb..008a9958 100644 --- a/src/bin/keycloakify/replacers/replaceImportsInJsCode/vite.ts +++ b/src/bin/keycloakify/replacers/replaceImportsInJsCode/vite.ts @@ -8,7 +8,7 @@ import * as nodePath from "path"; import { replaceAll } from "../../../tools/String.prototype.replaceAll"; export type BuildOptionsLike = { - reactAppBuildDirPath: string; + projectBuildDirPath: string; assetsDirPath: string; urlPathname: string | undefined; }; @@ -62,7 +62,7 @@ export function replaceImportsInJsCode_vite(params: { // Example: "assets/ or "foo/bar/" const staticDir = (() => { let out = pathRelative( - buildOptions.reactAppBuildDirPath, + buildOptions.projectBuildDirPath, buildOptions.assetsDirPath ); @@ -70,7 +70,7 @@ export function replaceImportsInJsCode_vite(params: { if (out === "/") { throw new Error( - `The assetsDirPath must be a subdirectory of reactAppBuildDirPath` + `The assetsDirPath must be a subdirectory of projectBuildDirPath` ); } diff --git a/src/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.ts b/src/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.ts index 5a334c75..55c6e16a 100644 --- a/src/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.ts +++ b/src/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.ts @@ -8,7 +8,7 @@ import * as nodePath from "path"; import { replaceAll } from "../../../tools/String.prototype.replaceAll"; export type BuildOptionsLike = { - reactAppBuildDirPath: string; + projectBuildDirPath: string; assetsDirPath: string; urlPathname: string | undefined; }; @@ -50,7 +50,7 @@ export function replaceImportsInJsCode_webpack(params: { // Example: "static/ or "foo/bar/" const staticDir = (() => { let out = pathRelative( - buildOptions.reactAppBuildDirPath, + buildOptions.projectBuildDirPath, buildOptions.assetsDirPath ); @@ -58,7 +58,7 @@ export function replaceImportsInJsCode_webpack(params: { if (out === "/") { throw new Error( - `The assetsDirPath must be a subdirectory of reactAppBuildDirPath` + `The assetsDirPath must be a subdirectory of projectBuildDirPath` ); } diff --git a/src/bin/main.ts b/src/bin/main.ts index d7d95a45..354b121b 100644 --- a/src/bin/main.ts +++ b/src/bin/main.ts @@ -5,7 +5,7 @@ import { readThisNpmPackageVersion } from "./tools/readThisNpmPackageVersion"; import * as child_process from "child_process"; export type CliCommandOptions = { - reactAppRootDirPath: string | undefined; + projectDirPath: string | undefined; }; const program = termost( @@ -25,7 +25,7 @@ const program = termost( const optionsKeys: string[] = []; program.option({ - key: "reactAppRootDirPath", + key: "projectDirPath", name: (() => { const long = "project"; const short = "p"; diff --git a/src/bin/shared/buildOptions.ts b/src/bin/shared/buildOptions.ts index baf24dde..e7545524 100644 --- a/src/bin/shared/buildOptions.ts +++ b/src/bin/shared/buildOptions.ts @@ -18,8 +18,8 @@ export type BuildOptions = { groupId: string; artifactId: string; loginThemeResourcesFromKeycloakVersion: string; - reactAppRootDirPath: string; - reactAppBuildDirPath: string; + projectDirPath: string; + projectBuildDirPath: string; /** Directory that keycloakify outputs to. Defaults to {cwd}/build_keycloak */ keycloakifyBuildDirPath: string; publicDirPath: string; @@ -57,13 +57,13 @@ export function readBuildOptions(params: { }): BuildOptions { const { cliCommandOptions } = params; - const reactAppRootDirPath = (() => { - if (cliCommandOptions.reactAppRootDirPath === undefined) { + const projectDirPath = (() => { + if (cliCommandOptions.projectDirPath === undefined) { return process.cwd(); } return getAbsoluteAndInOsFormatPath({ - pathIsh: cliCommandOptions.reactAppRootDirPath, + pathIsh: cliCommandOptions.projectDirPath, cwd: process.cwd() }); })(); @@ -71,7 +71,7 @@ export function readBuildOptions(params: { const { resolvedViteConfig } = (() => { if ( fs - .readdirSync(reactAppRootDirPath) + .readdirSync(projectDirPath) .find(fileBasename => fileBasename.startsWith("vite.config")) === undefined ) { @@ -80,7 +80,7 @@ export function readBuildOptions(params: { const output = child_process .execSync("npx vite", { - cwd: reactAppRootDirPath, + cwd: projectDirPath, env: { ...process.env, [vitePluginSubScriptEnvNames.resolveViteConfig]: "true" @@ -108,7 +108,7 @@ export function readBuildOptions(params: { version?: string; homepage?: string; keycloakify?: UserProvidedBuildOptions & { - reactAppBuildDirPath?: string; + projectBuildDirPath?: string; }; }; @@ -122,7 +122,7 @@ export function readBuildOptions(params: { artifactId: z.string().optional(), groupId: z.string().optional(), loginThemeResourcesFromKeycloakVersion: z.string().optional(), - reactAppBuildDirPath: z.string().optional(), + projectBuildDirPath: z.string().optional(), keycloakifyBuildDirPath: z.string().optional(), themeName: z.union([z.string(), z.array(z.string())]).optional() }) @@ -138,9 +138,7 @@ export function readBuildOptions(params: { return zParsedPackageJson.parse( JSON.parse( - fs - .readFileSync(pathJoin(reactAppRootDirPath, "package.json")) - .toString("utf8") + fs.readFileSync(pathJoin(projectDirPath, "package.json")).toString("utf8") ) ); })(); @@ -167,27 +165,27 @@ export function readBuildOptions(params: { return userProvidedBuildOptions.themeName; })(); - const reactAppBuildDirPath = (() => { + const projectBuildDirPath = (() => { webpack: { if (resolvedViteConfig !== undefined) { break webpack; } - if (parsedPackageJson.keycloakify?.reactAppBuildDirPath !== undefined) { + if (parsedPackageJson.keycloakify?.projectBuildDirPath !== undefined) { return getAbsoluteAndInOsFormatPath({ - pathIsh: parsedPackageJson.keycloakify.reactAppBuildDirPath, - cwd: reactAppRootDirPath + pathIsh: parsedPackageJson.keycloakify.projectBuildDirPath, + cwd: projectDirPath }); } - return pathJoin(reactAppRootDirPath, "build"); + return pathJoin(projectDirPath, "build"); } - return pathJoin(reactAppRootDirPath, resolvedViteConfig.buildDir); + return pathJoin(projectDirPath, resolvedViteConfig.buildDir); })(); const { npmWorkspaceRootDirPath } = getNpmWorkspaceRootDirPath({ - reactAppRootDirPath, + projectDirPath, dependencyExpected: "keycloakify" }); @@ -218,18 +216,18 @@ export function readBuildOptions(params: { `${themeNames[0]}-keycloak-theme`, loginThemeResourcesFromKeycloakVersion: userProvidedBuildOptions.loginThemeResourcesFromKeycloakVersion ?? "24.0.4", - reactAppRootDirPath, - reactAppBuildDirPath, + projectDirPath, + projectBuildDirPath, keycloakifyBuildDirPath: (() => { if (userProvidedBuildOptions.keycloakifyBuildDirPath !== undefined) { return getAbsoluteAndInOsFormatPath({ pathIsh: userProvidedBuildOptions.keycloakifyBuildDirPath, - cwd: reactAppRootDirPath + cwd: projectDirPath }); } return pathJoin( - reactAppRootDirPath, + projectDirPath, resolvedViteConfig?.buildDir === undefined ? "build_keycloak" : `${resolvedViteConfig.buildDir}_keycloak` @@ -244,14 +242,14 @@ export function readBuildOptions(params: { if (process.env.PUBLIC_DIR_PATH !== undefined) { return getAbsoluteAndInOsFormatPath({ 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: (() => { const cacheDirPath = pathJoin( @@ -300,10 +298,10 @@ export function readBuildOptions(params: { break webpack; } - return pathJoin(reactAppBuildDirPath, "static"); + return pathJoin(projectBuildDirPath, "static"); } - return pathJoin(reactAppBuildDirPath, resolvedViteConfig.assetsDir); + return pathJoin(projectBuildDirPath, resolvedViteConfig.assetsDir); })(), npmWorkspaceRootDirPath, kcContextExclusionsFtlCode: userProvidedBuildOptions.kcContextExclusionsFtlCode, diff --git a/src/bin/shared/generateKcGenTs.ts b/src/bin/shared/generateKcGenTs.ts index 8b9a4c68..a64a7abc 100644 --- a/src/bin/shared/generateKcGenTs.ts +++ b/src/bin/shared/generateKcGenTs.ts @@ -5,7 +5,7 @@ import * as fs from "fs/promises"; import { join as pathJoin } from "path"; export type BuildOptionsLike = { - reactAppRootDirPath: string; + projectDirPath: string; themeNames: string[]; environmentVariables: { name: string; default: string }[]; }; @@ -18,7 +18,7 @@ export async function generateKcGenTs(params: { const { buildOptions } = params; const { themeSrcDirPath } = getThemeSrcDirPath({ - reactAppRootDirPath: buildOptions.reactAppRootDirPath + projectDirPath: buildOptions.projectDirPath }); await fs.writeFile( diff --git a/src/bin/shared/getThemeSrcDirPath.ts b/src/bin/shared/getThemeSrcDirPath.ts index e9644e12..a692bb60 100644 --- a/src/bin/shared/getThemeSrcDirPath.ts +++ b/src/bin/shared/getThemeSrcDirPath.ts @@ -7,10 +7,10 @@ import { themeTypes } from "./constants"; 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. */ -export function getThemeSrcDirPath(params: { reactAppRootDirPath: string }) { - const { reactAppRootDirPath } = params; +export function getThemeSrcDirPath(params: { projectDirPath: string }) { + const { projectDirPath } = params; - const srcDirPath = pathJoin(reactAppRootDirPath, "src"); + const srcDirPath = pathJoin(projectDirPath, "src"); const themeSrcDirPath: string | undefined = crawl({ dirPath: srcDirPath, diff --git a/src/bin/start-keycloak/appBuild.ts b/src/bin/start-keycloak/appBuild.ts index e0e7b903..8986ae99 100644 --- a/src/bin/start-keycloak/appBuild.ts +++ b/src/bin/start-keycloak/appBuild.ts @@ -7,11 +7,11 @@ import * as fs from "fs"; import { join as pathJoin } from "path"; export type BuildOptionsLike = { - reactAppRootDirPath: string; + projectDirPath: string; keycloakifyBuildDirPath: string; bundler: "vite" | "webpack"; npmWorkspaceRootDirPath: string; - reactAppBuildDirPath: string; + projectBuildDirPath: string; }; assert(); @@ -29,11 +29,11 @@ export async function appBuild(params: { return { command: "npx", args: ["vite", "build"], - cwd: buildOptions.reactAppRootDirPath + cwd: buildOptions.projectDirPath }; case "webpack": { for (const dirPath of [ - buildOptions.reactAppRootDirPath, + buildOptions.projectDirPath, buildOptions.npmWorkspaceRootDirPath ]) { try { diff --git a/src/bin/start-keycloak/keycloakifyBuild.ts b/src/bin/start-keycloak/keycloakifyBuild.ts index 38973d81..884170a3 100644 --- a/src/bin/start-keycloak/keycloakifyBuild.ts +++ b/src/bin/start-keycloak/keycloakifyBuild.ts @@ -5,7 +5,7 @@ import { assert } from "tsafe/assert"; import type { BuildOptions } from "../shared/buildOptions"; export type BuildOptionsLike = { - reactAppRootDirPath: string; + projectDirPath: string; keycloakifyBuildDirPath: string; bundler: "vite" | "webpack"; npmWorkspaceRootDirPath: string; @@ -22,7 +22,7 @@ export async function keycloakifyBuild(params: { const dResult = new Deferred<{ isSuccess: boolean }>(); const child = child_process.spawn("npx", ["keycloakify", "build"], { - cwd: buildOptions.reactAppRootDirPath, + cwd: buildOptions.projectDirPath, env: { ...process.env, ...(doSkipBuildJars ? { [skipBuildJarsEnvName]: "true" } : {}) diff --git a/src/bin/start-keycloak/start-keycloak.ts b/src/bin/start-keycloak/start-keycloak.ts index 82d96bf5..5b041eca 100644 --- a/src/bin/start-keycloak/start-keycloak.ts +++ b/src/bin/start-keycloak/start-keycloak.ts @@ -26,7 +26,6 @@ export type CliCommandOptions = CliCommandOptions_common & { port: number; keycloakVersion: string | undefined; realmJsonFilePath: string | undefined; - environmentVariables: { name: string; default: string }[]; }; export async function command(params: { cliCommandOptions: CliCommandOptions }) { @@ -398,7 +397,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) child.on("exit", process.exit); - const srcDirPath = pathJoin(buildOptions.reactAppRootDirPath, "src"); + const srcDirPath = pathJoin(buildOptions.projectDirPath, "src"); { const handler = async (data: Buffer) => { @@ -430,7 +429,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) `- password: ${chalk.cyan.bold("password123")}`, "", `Watching for changes in ${chalk.bold( - `.${pathSep}${pathRelative(process.cwd(), buildOptions.reactAppRootDirPath)}` + `.${pathSep}${pathRelative(process.cwd(), buildOptions.projectDirPath)}` )}` ].join("\n") ); @@ -472,10 +471,10 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) [ srcDirPath, buildOptions.publicDirPath, - pathJoin(buildOptions.reactAppRootDirPath, "package.json"), - pathJoin(buildOptions.reactAppRootDirPath, "vite.config.ts"), - pathJoin(buildOptions.reactAppRootDirPath, "vite.config.js"), - pathJoin(buildOptions.reactAppRootDirPath, "index.html"), + pathJoin(buildOptions.projectDirPath, "package.json"), + pathJoin(buildOptions.projectDirPath, "vite.config.ts"), + pathJoin(buildOptions.projectDirPath, "vite.config.js"), + pathJoin(buildOptions.projectDirPath, "index.html"), pathJoin(getThisCodebaseRootDirPath(), "src") ], { diff --git a/src/bin/tools/getNpmWorkspaceRootDirPath.ts b/src/bin/tools/getNpmWorkspaceRootDirPath.ts index d3863f4d..87a610c7 100644 --- a/src/bin/tools/getNpmWorkspaceRootDirPath.ts +++ b/src/bin/tools/getNpmWorkspaceRootDirPath.ts @@ -4,14 +4,14 @@ import { assert } from "tsafe/assert"; import * as fs from "fs"; export function getNpmWorkspaceRootDirPath(params: { - reactAppRootDirPath: string; + projectDirPath: string; dependencyExpected: string; }) { - const { reactAppRootDirPath, dependencyExpected } = params; + const { projectDirPath, dependencyExpected } = params; const npmWorkspaceRootDirPath = (function callee(depth: number): string { const cwd = pathResolve( - pathJoin(...[reactAppRootDirPath, ...Array(depth).fill("..")]) + pathJoin(...[projectDirPath, ...Array(depth).fill("..")]) ); assert(cwd !== pathSep, "NPM workspace not found"); diff --git a/src/vite-plugin/vite-plugin.ts b/src/vite-plugin/vite-plugin.ts index d5d3e9bb..cc98f11f 100644 --- a/src/vite-plugin/vite-plugin.ts +++ b/src/vite-plugin/vite-plugin.ts @@ -26,7 +26,7 @@ export type Params = UserProvidedBuildOptions & { export function keycloakify(params?: Params) { const { postBuild, ...userProvidedBuildOptions } = params ?? {}; - let reactAppRootDirPath: string | undefined = undefined; + let projectDirPath: string | undefined = undefined; let urlPathname: string | undefined = undefined; let buildDirPath: string | undefined = undefined; let command: "build" | "serve" | undefined = undefined; @@ -54,7 +54,7 @@ export function keycloakify(params?: Params) { command = resolvedConfig.command; - reactAppRootDirPath = resolvedConfig.root; + projectDirPath = resolvedConfig.root; urlPathname = (() => { let out = resolvedConfig.env.BASE_URL; @@ -86,7 +86,7 @@ export function keycloakify(params?: Params) { return out; })(); - buildDirPath = pathJoin(reactAppRootDirPath, resolvedConfig.build.outDir); + buildDirPath = pathJoin(projectDirPath, resolvedConfig.build.outDir); resolve_vite_config_case: { const envValue = @@ -102,7 +102,7 @@ export function keycloakify(params?: Params) { JSON.stringify( id({ publicDir: pathRelative( - reactAppRootDirPath, + projectDirPath, resolvedConfig.publicDir ), assetsDir: resolvedConfig.build.assetsDir, @@ -118,7 +118,7 @@ export function keycloakify(params?: Params) { const buildOptions = readBuildOptions({ cliCommandOptions: { - reactAppRootDirPath + projectDirPath } }); @@ -139,11 +139,11 @@ export function keycloakify(params?: Params) { return; } - assert(reactAppRootDirPath !== undefined); + assert(projectDirPath !== undefined); { const isWithinSourceDirectory = id.startsWith( - pathJoin(reactAppRootDirPath, "src") + pathSep + pathJoin(projectDirPath, "src") + pathSep ); if (!isWithinSourceDirectory) {