Feature -p or --project option for ease of use in monorepo setups #449

This commit is contained in:
Joseph Garrone
2024-02-08 00:56:33 +01:00
parent 3e336f4937
commit 5bf905723c
5 changed files with 28 additions and 22 deletions

View File

@ -7,10 +7,7 @@ import { themeTypes, keycloak_resources, lastKeycloakVersionWithAccountV1 } from
import * as fs from "fs"; import * as fs from "fs";
(async () => { (async () => {
const reactAppRootDirPath = process.cwd();
const buildOptions = readBuildOptions({ const buildOptions = readBuildOptions({
reactAppRootDirPath,
"processArgv": process.argv.slice(2) "processArgv": process.argv.slice(2)
}); });
@ -45,5 +42,5 @@ import * as fs from "fs";
fs.writeFileSync(pathJoin(buildOptions.publicDirPath, keycloak_resources, ".gitignore"), Buffer.from("*", "utf8")); fs.writeFileSync(pathJoin(buildOptions.publicDirPath, keycloak_resources, ".gitignore"), Buffer.from("*", "utf8"));
console.log(`${pathRelative(reactAppRootDirPath, reservedDirPath)} directory created.`); console.log(`${pathRelative(buildOptions.reactAppRootDirPath, reservedDirPath)} directory created.`);
})(); })();

View File

@ -226,7 +226,6 @@ export async function downloadBuiltinKeycloakTheme(params: { keycloakVersion: st
async function main() { async function main() {
const buildOptions = readBuildOptions({ const buildOptions = readBuildOptions({
"reactAppRootDirPath": process.cwd(),
"processArgv": process.argv.slice(2) "processArgv": process.argv.slice(2)
}); });

View File

@ -11,17 +11,14 @@ import { getThemeSrcDirPath } from "./getThemeSrcDirPath";
import { rmSync } from "./tools/fs.rmSync"; import { rmSync } from "./tools/fs.rmSync";
export async function main() { export async function main() {
const reactAppRootDirPath = process.cwd();
const buildOptions = readBuildOptions({ const buildOptions = readBuildOptions({
reactAppRootDirPath,
"processArgv": process.argv.slice(2) "processArgv": process.argv.slice(2)
}); });
const logger = getLogger({ "isSilent": buildOptions.isSilent }); const logger = getLogger({ "isSilent": buildOptions.isSilent });
const { themeSrcDirPath } = getThemeSrcDirPath({ const { themeSrcDirPath } = getThemeSrcDirPath({
reactAppRootDirPath "reactAppRootDirPath": buildOptions.reactAppRootDirPath
}); });
const emailThemeSrcDirPath = pathJoin(themeSrcDirPath, "email"); const emailThemeSrcDirPath = pathJoin(themeSrcDirPath, "email");

View File

@ -30,8 +30,23 @@ export type BuildOptions = {
doBuildRetrocompatAccountTheme: boolean; doBuildRetrocompatAccountTheme: boolean;
}; };
export function readBuildOptions(params: { reactAppRootDirPath: string; processArgv: string[] }): BuildOptions { export function readBuildOptions(params: { processArgv: string[] }): BuildOptions {
const { reactAppRootDirPath, processArgv } = params; const { processArgv } = params;
const argv = parseArgv(processArgv);
const reactAppRootDirPath = (() => {
const arg = argv["project"] ?? argv["p"];
if (typeof arg !== "string") {
return process.cwd();
}
return getAbsoluteAndInOsFormatPath({
"pathIsh": arg,
"cwd": process.cwd()
});
})();
const parsedPackageJson = readParsedPackageJson({ reactAppRootDirPath }); const parsedPackageJson = readParsedPackageJson({ reactAppRootDirPath });
@ -85,11 +100,7 @@ export function readBuildOptions(params: { reactAppRootDirPath: string; processA
return { return {
"bundler": resolvedViteConfig !== undefined ? "vite" : "webpack", "bundler": resolvedViteConfig !== undefined ? "vite" : "webpack",
"isSilent": (() => { "isSilent": typeof argv["silent"] === "boolean" ? argv["silent"] : false,
const argv = parseArgv(processArgv);
return typeof argv["silent"] === "boolean" ? argv["silent"] : false;
})(),
"themeVersion": process.env.KEYCLOAKIFY_THEME_VERSION ?? parsedPackageJson.version ?? "0.0.0", "themeVersion": process.env.KEYCLOAKIFY_THEME_VERSION ?? parsedPackageJson.version ?? "0.0.0",
themeNames, themeNames,
"extraThemeProperties": parsedPackageJson.keycloakify?.extraThemeProperties, "extraThemeProperties": parsedPackageJson.keycloakify?.extraThemeProperties,

View File

@ -11,10 +11,7 @@ import { getThemeSrcDirPath } from "../getThemeSrcDirPath";
import { getProjectRoot } from "../tools/getProjectRoot"; import { getProjectRoot } from "../tools/getProjectRoot";
export async function main() { export async function main() {
const reactAppRootDirPath = process.cwd();
const buildOptions = readBuildOptions({ const buildOptions = readBuildOptions({
reactAppRootDirPath,
"processArgv": process.argv.slice(2) "processArgv": process.argv.slice(2)
}); });
@ -23,7 +20,7 @@ export async function main() {
const keycloakifyDirPath = getProjectRoot(); const keycloakifyDirPath = getProjectRoot();
const { themeSrcDirPath } = getThemeSrcDirPath({ reactAppRootDirPath }); const { themeSrcDirPath } = getThemeSrcDirPath({ "reactAppRootDirPath": buildOptions.reactAppRootDirPath });
for (const themeName of buildOptions.themeNames) { for (const themeName of buildOptions.themeNames) {
await generateTheme({ await generateTheme({
@ -83,12 +80,17 @@ export async function main() {
"", "",
...(!buildOptions.doCreateJar ...(!buildOptions.doCreateJar
? [] ? []
: [`✅ Your keycloak theme has been generated and bundled into .${pathSep}${pathRelative(reactAppRootDirPath, jarFilePath)} 🚀`]), : [
`✅ Your keycloak theme has been generated and bundled into .${pathSep}${pathRelative(
buildOptions.reactAppRootDirPath,
jarFilePath
)} 🚀`
]),
"", "",
`To test your theme locally you can spin up a Keycloak ${containerKeycloakVersion} container image with the theme pre loaded by running:`, `To test your theme locally you can spin up a Keycloak ${containerKeycloakVersion} container image with the theme pre loaded by running:`,
"", "",
`👉 $ .${pathSep}${pathRelative( `👉 $ .${pathSep}${pathRelative(
reactAppRootDirPath, buildOptions.reactAppRootDirPath,
pathJoin(buildOptions.keycloakifyBuildDirPath, generateStartKeycloakTestingContainer.basename) pathJoin(buildOptions.keycloakifyBuildDirPath, generateStartKeycloakTestingContainer.basename)
)} 👈`, )} 👈`,
``, ``,