From 983db6780af31227c726bfedc2f5441422a53c88 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Fri, 22 Nov 2024 06:16:15 +0100 Subject: [PATCH] #730 --- src/bin/main.ts | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/bin/main.ts b/src/bin/main.ts index 578079ab..54eaa5b7 100644 --- a/src/bin/main.ts +++ b/src/bin/main.ts @@ -5,6 +5,9 @@ import { readThisNpmPackageVersion } from "./tools/readThisNpmPackageVersion"; import * as child_process from "child_process"; import { assertNoPnpmDlx } from "./tools/assertNoPnpmDlx"; import { getBuildContext } from "./shared/buildContext"; +import { SemVer } from "./tools/SemVer"; +import { assert, is } from "tsafe/assert"; +import chalk from "chalk"; type CliCommandOptions = { projectDirPath: string | undefined; @@ -80,7 +83,7 @@ program program .command<{ port: number | undefined; - keycloakVersion: string | undefined; + keycloakVersion: string | number | undefined; realmJsonFilePath: string | undefined; }>({ name: "start-keycloak", @@ -134,9 +137,50 @@ program handler: async ({ projectDirPath, keycloakVersion, port, realmJsonFilePath }) => { const { command } = await import("./start-keycloak"); + validate_keycloak_version: { + if (keycloakVersion === undefined) { + break validate_keycloak_version; + } + + const isValidVersion = (() => { + if (typeof keycloakVersion === "number") { + return false; + } + + try { + SemVer.parse(keycloakVersion); + } catch { + return false; + } + + return; + })(); + + if (isValidVersion) { + break validate_keycloak_version; + } + + console.log( + chalk.red( + [ + `Invalid Keycloak version: ${keycloakVersion}`, + "It should be a valid semver version example: 26.0.4" + ].join(" ") + ) + ); + + process.exit(1); + } + + assert(is(keycloakVersion)); + await command({ buildContext: getBuildContext({ projectDirPath }), - cliCommandOptions: { keycloakVersion, port, realmJsonFilePath } + cliCommandOptions: { + keycloakVersion, + port, + realmJsonFilePath + } }); } });