This commit is contained in:
Joseph Garrone
2024-05-18 03:12:07 +02:00
parent 87cd37c467
commit 22aa48e343

View File

@ -10,26 +10,53 @@ export type CliCommandOptions = {
const program = termost<CliCommandOptions>("Keycloak theme builder"); const program = termost<CliCommandOptions>("Keycloak theme builder");
const optionsKeys: string[] = [];
program program
.option({ .option({
"key": "reactAppRootDirPath", "key": "reactAppRootDirPath",
"name": { "long": "project", "short": "p" }, "name": (() => {
const long = "project";
const short = "p";
optionsKeys.push(long, short);
return { long, short };
})(),
"description": "https://docs.keycloakify.dev/build-options#project-or-p-cli-option", "description": "https://docs.keycloakify.dev/build-options#project-or-p-cli-option",
"defaultValue": undefined "defaultValue": undefined
}) })
.option({ .option({
"key": "isSilent", "key": "isSilent",
"name": "silent", "name": (() => {
const name = "silent";
optionsKeys.push(name);
return name;
})(),
"description": "https://docs.keycloakify.dev/build-options#silent", "description": "https://docs.keycloakify.dev/build-options#silent",
"defaultValue": false "defaultValue": false
}); });
function skip(_context: any, argv: { options: Record<string, unknown> }) {
const unrecognizedOptionKey = Object.keys(argv.options).find(key => !optionsKeys.includes(key));
if (unrecognizedOptionKey !== undefined) {
console.error(`keycloakify: Unrecognized option: ${unrecognizedOptionKey.length === 1 ? "-" : "--"}${unrecognizedOptionKey}`);
process.exit(1);
}
return false;
}
program program
.command({ .command({
"name": "build", "name": "build",
"description": "Build the theme (default subcommand)." "description": "Build the theme (default subcommand)."
}) })
.task({ .task({
skip,
"handler": async cliCommandOptions => { "handler": async cliCommandOptions => {
const { command } = await import("./keycloakify"); const { command } = await import("./keycloakify");
return command({ cliCommandOptions }); return command({ cliCommandOptions });
@ -42,6 +69,7 @@ program
"description": "Download the built-in Keycloak theme." "description": "Download the built-in Keycloak theme."
}) })
.task({ .task({
skip,
"handler": async cliCommandOptions => { "handler": async cliCommandOptions => {
const { command } = await import("./download-builtin-keycloak-theme"); const { command } = await import("./download-builtin-keycloak-theme");
return command({ cliCommandOptions }); return command({ cliCommandOptions });
@ -54,6 +82,7 @@ program
"description": "Eject a Keycloak page." "description": "Eject a Keycloak page."
}) })
.task({ .task({
skip,
"handler": async cliCommandOptions => { "handler": async cliCommandOptions => {
const { command } = await import("./eject-keycloak-page"); const { command } = await import("./eject-keycloak-page");
return command({ cliCommandOptions }); return command({ cliCommandOptions });
@ -66,6 +95,7 @@ program
"description": "Initialize an email theme." "description": "Initialize an email theme."
}) })
.task({ .task({
skip,
"handler": async cliCommandOptions => { "handler": async cliCommandOptions => {
const { command } = await import("./initialize-email-theme"); const { command } = await import("./initialize-email-theme");
return command({ cliCommandOptions }); return command({ cliCommandOptions });
@ -81,6 +111,7 @@ program
].join(" ") ].join(" ")
}) })
.task({ .task({
skip,
"handler": async cliCommandOptions => { "handler": async cliCommandOptions => {
const { command } = await import("./copy-keycloak-resources-to-public"); const { command } = await import("./copy-keycloak-resources-to-public");
return command({ cliCommandOptions }); return command({ cliCommandOptions });
@ -93,6 +124,7 @@ program
"description": "Spin up a Keycloak container with the theme preloaded and the realm pre configured." "description": "Spin up a Keycloak container with the theme preloaded and the realm pre configured."
}) })
.task({ .task({
skip,
"handler": async cliCommandOptions => { "handler": async cliCommandOptions => {
const { command } = await import("./start-keycloak-container"); const { command } = await import("./start-keycloak-container");
return command({ cliCommandOptions }); return command({ cliCommandOptions });
@ -103,9 +135,11 @@ program
{ {
const [, , ...rest] = process.argv; const [, , ...rest] = process.argv;
if (rest.length === 0 || !rest[0].startsWith("-")) { if (rest.length === 0 || (rest[0].startsWith("-") && rest[0] !== "--help" && rest[0] !== "-h")) {
child_process.spawnSync("npx", ["keycloakify", "build", ...rest], { const { status } = child_process.spawnSync("npx", ["keycloakify", "build", ...rest], {
"stdio": "inherit" "stdio": "inherit"
}); });
process.exit(status ?? 1);
} }
} }