Improve login

This commit is contained in:
Joseph Garrone 2024-05-18 10:24:55 +02:00
parent 2c5473da27
commit af829e9ac9
7 changed files with 20 additions and 52 deletions

View File

@ -3,7 +3,6 @@ import { promptKeycloakVersion } from "./shared/promptKeycloakVersion";
import { readBuildOptions } from "./shared/buildOptions"; import { readBuildOptions } from "./shared/buildOptions";
import { downloadBuiltinKeycloakTheme } from "./shared/downloadBuiltinKeycloakTheme"; import { downloadBuiltinKeycloakTheme } from "./shared/downloadBuiltinKeycloakTheme";
import type { CliCommandOptions } from "./main"; import type { CliCommandOptions } from "./main";
import { getLogger } from "./tools/logger";
export async function command(params: { cliCommandOptions: CliCommandOptions }) { export async function command(params: { cliCommandOptions: CliCommandOptions }) {
const { cliCommandOptions } = params; const { cliCommandOptions } = params;
@ -12,8 +11,6 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
cliCommandOptions cliCommandOptions
}); });
const { log } = getLogger({ "isSilent": buildOptions.isSilent });
console.log("Select the Keycloak version from which you want to download the builtins theme:"); console.log("Select the Keycloak version from which you want to download the builtins theme:");
const { keycloakVersion } = await promptKeycloakVersion({ const { keycloakVersion } = await promptKeycloakVersion({
@ -23,7 +20,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
const destDirPath = pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources", "theme"); const destDirPath = pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources", "theme");
log(`Downloading builtins theme of Keycloak ${keycloakVersion} here ${destDirPath}`); console.log(`Downloading builtins theme of Keycloak ${keycloakVersion} here ${destDirPath}`);
await downloadBuiltinKeycloakTheme({ await downloadBuiltinKeycloakTheme({
keycloakVersion, keycloakVersion,

View File

@ -4,7 +4,6 @@ import { transformCodebase } from "./tools/transformCodebase";
import { promptKeycloakVersion } from "./shared/promptKeycloakVersion"; import { promptKeycloakVersion } from "./shared/promptKeycloakVersion";
import { readBuildOptions } from "./shared/buildOptions"; import { readBuildOptions } from "./shared/buildOptions";
import * as fs from "fs"; import * as fs from "fs";
import { getLogger } from "./tools/logger";
import { getThemeSrcDirPath } from "./shared/getThemeSrcDirPath"; import { getThemeSrcDirPath } from "./shared/getThemeSrcDirPath";
import { rmSync } from "./tools/fs.rmSync"; import { rmSync } from "./tools/fs.rmSync";
import type { CliCommandOptions } from "./main"; import type { CliCommandOptions } from "./main";
@ -14,8 +13,6 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
const buildOptions = readBuildOptions({ cliCommandOptions }); const buildOptions = readBuildOptions({ cliCommandOptions });
const logger = getLogger({ "isSilent": buildOptions.isSilent });
const { themeSrcDirPath } = getThemeSrcDirPath({ const { themeSrcDirPath } = getThemeSrcDirPath({
"reactAppRootDirPath": buildOptions.reactAppRootDirPath "reactAppRootDirPath": buildOptions.reactAppRootDirPath
}); });
@ -23,7 +20,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
const emailThemeSrcDirPath = pathJoin(themeSrcDirPath, "email"); const emailThemeSrcDirPath = pathJoin(themeSrcDirPath, "email");
if (fs.existsSync(emailThemeSrcDirPath)) { if (fs.existsSync(emailThemeSrcDirPath)) {
logger.warn(`There is already a ${pathRelative(process.cwd(), emailThemeSrcDirPath)} directory in your project. Aborting.`); console.warn(`There is already a ${pathRelative(process.cwd(), emailThemeSrcDirPath)} directory in your project. Aborting.`);
process.exit(-1); process.exit(-1);
} }
@ -57,8 +54,8 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
fs.writeFileSync(themePropertyFilePath, Buffer.from(`parent=base\n${fs.readFileSync(themePropertyFilePath).toString("utf8")}`, "utf8")); fs.writeFileSync(themePropertyFilePath, Buffer.from(`parent=base\n${fs.readFileSync(themePropertyFilePath).toString("utf8")}`, "utf8"));
} }
logger.log(`The \`${pathJoin(".", pathRelative(process.cwd(), emailThemeSrcDirPath))}\` directory have been created.`); console.log(`The \`${pathJoin(".", pathRelative(process.cwd(), emailThemeSrcDirPath))}\` directory have been created.`);
logger.log("You can delete any file you don't modify."); console.log("You can delete any file you don't modify.");
rmSync(builtinKeycloakThemeTmpDirPath, { "recursive": true }); rmSync(builtinKeycloakThemeTmpDirPath, { "recursive": true });
} }

View File

@ -22,7 +22,7 @@ import { generateMessageProperties } from "./generateMessageProperties";
import { bringInAccountV1 } from "./bringInAccountV1"; import { bringInAccountV1 } from "./bringInAccountV1";
import { getThemeSrcDirPath } from "../../shared/getThemeSrcDirPath"; import { getThemeSrcDirPath } from "../../shared/getThemeSrcDirPath";
import { rmSync } from "../../tools/fs.rmSync"; import { rmSync } from "../../tools/fs.rmSync";
import { readThisNpmProjectVersion } from "../../tools/readThisNpmProjectVersion"; import { readThisNpmPackageVersion } from "../../tools/readThisNpmPackageVersion";
import { writeMetaInfKeycloakThemes, type MetaInfKeycloakTheme } from "../../shared/metaInfKeycloakThemes"; import { writeMetaInfKeycloakThemes, type MetaInfKeycloakTheme } from "../../shared/metaInfKeycloakThemes";
import { objectEntries } from "tsafe/objectEntries"; import { objectEntries } from "tsafe/objectEntries";
@ -138,7 +138,7 @@ export async function generateSrcMainResourcesForMainTheme(params: { themeName:
"indexHtmlCode": fs.readFileSync(pathJoin(buildOptions.reactAppBuildDirPath, "index.html")).toString("utf8"), "indexHtmlCode": fs.readFileSync(pathJoin(buildOptions.reactAppBuildDirPath, "index.html")).toString("utf8"),
cssGlobalsToDefine, cssGlobalsToDefine,
buildOptions, buildOptions,
"keycloakifyVersion": readThisNpmProjectVersion(), "keycloakifyVersion": readThisNpmPackageVersion(),
themeType, themeType,
"fieldNames": readFieldNameUsage({ "fieldNames": readFieldNameUsage({
themeSrcDirPath, themeSrcDirPath,

View File

@ -3,19 +3,25 @@ import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path
import * as child_process from "child_process"; import * as child_process from "child_process";
import * as fs from "fs"; import * as fs from "fs";
import { readBuildOptions } from "../shared/buildOptions"; import { readBuildOptions } from "../shared/buildOptions";
import { getLogger } from "../tools/logger";
import { vitePluginSubScriptEnvNames } from "../shared/constants"; import { vitePluginSubScriptEnvNames } from "../shared/constants";
import { buildJars } from "./buildJars"; import { buildJars } from "./buildJars";
import type { CliCommandOptions } from "../main"; import type { CliCommandOptions } from "../main";
import chalk from "chalk";
import { readThisNpmPackageVersion } from "../tools/readThisNpmPackageVersion";
export async function command(params: { cliCommandOptions: CliCommandOptions }) { export async function command(params: { cliCommandOptions: CliCommandOptions }) {
const { cliCommandOptions } = params; const { cliCommandOptions } = params;
const buildOptions = readBuildOptions({ cliCommandOptions }); const buildOptions = readBuildOptions({ cliCommandOptions });
const logger = getLogger({ "isSilent": buildOptions.isSilent }); console.log(
[
chalk.cyan(`keycloakify v${readThisNpmPackageVersion()}`),
chalk.green(`Building the keycloak theme in .${pathSep}${pathRelative(process.cwd(), buildOptions.keycloakifyBuildDirPath)} ...`)
].join(" ")
);
logger.log("🔏 Building the keycloak theme...⌚"); const startTime = Date.now();
{ {
if (!fs.existsSync(buildOptions.keycloakifyBuildDirPath)) { if (!fs.existsSync(buildOptions.keycloakifyBuildDirPath)) {
@ -43,10 +49,5 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
await buildJars({ buildOptions }); await buildJars({ buildOptions });
logger.log( console.log(chalk.green(`✓ built in ${((Date.now() - startTime) / 1000).toFixed(2)}s`));
`✅ Your keycloak theme has been generated and bundled into .${pathSep}${pathJoin(
pathRelative(process.cwd(), buildOptions.keycloakifyBuildDirPath),
"keycloak-theme-for-kc-*.jar"
)}`
);
} }

View File

@ -4,7 +4,7 @@ import {
} from "./downloadKeycloakStaticResources"; } from "./downloadKeycloakStaticResources";
import { join as pathJoin, relative as pathRelative } from "path"; import { join as pathJoin, relative as pathRelative } from "path";
import { themeTypes, keycloak_resources, lastKeycloakVersionWithAccountV1 } from "../shared/constants"; import { themeTypes, keycloak_resources, lastKeycloakVersionWithAccountV1 } from "../shared/constants";
import { readThisNpmProjectVersion } from "../tools/readThisNpmProjectVersion"; import { readThisNpmPackageVersion } from "../tools/readThisNpmPackageVersion";
import { assert } from "tsafe/assert"; import { assert } from "tsafe/assert";
import * as fs from "fs"; import * as fs from "fs";
import { rmSync } from "../tools/fs.rmSync"; import { rmSync } from "../tools/fs.rmSync";
@ -27,9 +27,9 @@ export async function copyKeycloakResourcesToPublic(params: { buildOptions: Buil
const keycloakifyBuildinfoRaw = JSON.stringify( const keycloakifyBuildinfoRaw = JSON.stringify(
{ {
destDirPath, destDirPath,
"keycloakifyVersion": readThisNpmProjectVersion(), "keycloakifyVersion": readThisNpmPackageVersion(),
"buildOptions": { "buildOptions": {
"loginThemeResourcesFromKeycloakVersion": readThisNpmProjectVersion(), "loginThemeResourcesFromKeycloakVersion": readThisNpmPackageVersion(),
"cacheDirPath": pathRelative(destDirPath, buildOptions.cacheDirPath), "cacheDirPath": pathRelative(destDirPath, buildOptions.cacheDirPath),
"npmWorkspaceRootDirPath": pathRelative(destDirPath, buildOptions.npmWorkspaceRootDirPath) "npmWorkspaceRootDirPath": pathRelative(destDirPath, buildOptions.npmWorkspaceRootDirPath)
} }

View File

@ -1,27 +0,0 @@
type LoggerOpts = {
force?: boolean;
};
type Logger = {
log: (message: string, opts?: LoggerOpts) => void;
warn: (message: string) => void;
error: (message: string) => void;
};
export const getLogger = ({ isSilent }: { isSilent?: boolean } = {}): Logger => {
return {
log: (message, { force } = {}) => {
if (isSilent && !force) {
return;
}
console.log(message);
},
warn: message => {
console.warn(message);
},
error: message => {
console.error(message);
}
};
};

View File

@ -3,7 +3,7 @@ import { assert } from "tsafe/assert";
import * as fs from "fs"; import * as fs from "fs";
import { join as pathJoin } from "path"; import { join as pathJoin } from "path";
export function readThisNpmProjectVersion(): string { export function readThisNpmPackageVersion(): string {
const version = JSON.parse(fs.readFileSync(pathJoin(getThisCodebaseRootDirPath(), "package.json")).toString("utf8"))["version"]; const version = JSON.parse(fs.readFileSync(pathJoin(getThisCodebaseRootDirPath(), "package.json")).toString("utf8"))["version"];
assert(typeof version === "string"); assert(typeof version === "string");