Joseph Garrone
2024-05-19 04:26:01 +02:00
parent 59f8119047
commit 10da0cab47

View File

@ -8,11 +8,19 @@ export type CliCommandOptions = {
reactAppRootDirPath: string | undefined; reactAppRootDirPath: string | undefined;
}; };
const program = termost<CliCommandOptions>({ const program = termost<CliCommandOptions>(
{
"name": "keycloakify", "name": "keycloakify",
"description": "Keycloakify CLI", "description": "Keycloakify CLI",
"version": readThisNpmPackageVersion() "version": readThisNpmPackageVersion()
}); },
{
"onException": error => {
console.error(error);
process.exit(1);
}
}
);
const optionsKeys: string[] = []; const optionsKeys: string[] = [];
@ -45,15 +53,6 @@ function skip(_context: any, argv: { options: Record<string, unknown> }) {
return false; return false;
} }
async function runAndLogErrors(fn: () => Promise<void>) {
try {
await fn();
} catch (error) {
console.error(error);
process.exit(1);
}
}
program program
.command({ .command({
"name": "build", "name": "build",
@ -61,12 +60,11 @@ program
}) })
.task({ .task({
skip, skip,
"handler": cliCommandOptions => "handler": async cliCommandOptions => {
runAndLogErrors(async () => { const { command } = await import("./keycloakify");
const { command } = await import("./keycloakify/index");
await runAndLogErrors(() => command({ cliCommandOptions })); await command({ cliCommandOptions });
}) }
}); });
program program
@ -100,12 +98,11 @@ program
}) })
.task({ .task({
skip, skip,
"handler": cliCommandOptions => "handler": async cliCommandOptions => {
runAndLogErrors(async () => {
const { command } = await import("./start-keycloak"); const { command } = await import("./start-keycloak");
await runAndLogErrors(() => command({ cliCommandOptions })); await command({ cliCommandOptions });
}) }
}); });
program program
@ -115,12 +112,11 @@ program
}) })
.task({ .task({
skip, skip,
"handler": cliCommandOptions => "handler": async cliCommandOptions => {
runAndLogErrors(async () => {
const { command } = await import("./download-builtin-keycloak-theme"); const { command } = await import("./download-builtin-keycloak-theme");
await runAndLogErrors(() => command({ cliCommandOptions })); await command({ cliCommandOptions });
}) }
}); });
program program
@ -130,12 +126,11 @@ program
}) })
.task({ .task({
skip, skip,
"handler": cliCommandOptions => "handler": async cliCommandOptions => {
runAndLogErrors(async () => {
const { command } = await import("./eject-keycloak-page"); const { command } = await import("./eject-keycloak-page");
await runAndLogErrors(() => command({ cliCommandOptions })); await command({ cliCommandOptions });
}) }
}); });
program program
@ -145,12 +140,11 @@ program
}) })
.task({ .task({
skip, skip,
"handler": cliCommandOptions => "handler": async cliCommandOptions => {
runAndLogErrors(async () => {
const { command } = await import("./initialize-email-theme"); const { command } = await import("./initialize-email-theme");
await runAndLogErrors(() => command({ cliCommandOptions })); await command({ cliCommandOptions });
}) }
}); });
program program
@ -160,12 +154,11 @@ program
}) })
.task({ .task({
skip, skip,
"handler": cliCommandOptions => "handler": async cliCommandOptions => {
runAndLogErrors(async () => {
const { command } = await import("./copy-keycloak-resources-to-public"); const { command } = await import("./copy-keycloak-resources-to-public");
await runAndLogErrors(() => command({ cliCommandOptions })); await command({ cliCommandOptions });
}) }
}); });
// Fallback to build command if no command is provided // Fallback to build command if no command is provided