diff --git a/package.json b/package.json index 308b313d..e297ff2f 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "@babel/parser": "^7.22.7", "@babel/types": "^7.22.5", "@octokit/rest": "^20.1.1", + "chalk": "4.1.2", "cheerio": "^1.0.0-rc.5", "cli-select": "^1.1.2", "evt": "^2.5.7", diff --git a/src/bin/start-keycloak-container.ts b/src/bin/start-keycloak-container.ts index 4e1b399e..daeb6d92 100644 --- a/src/bin/start-keycloak-container.ts +++ b/src/bin/start-keycloak-container.ts @@ -10,6 +10,7 @@ import { assert, type Equals } from "tsafe/assert"; import * as fs from "fs"; import { join as pathJoin, posix as pathPosix } from "path"; import * as child_process from "child_process"; +import chalk from "chalk"; export async function command(params: { cliCommandOptions: CliCommandOptions }) { const { cliCommandOptions } = params; @@ -120,11 +121,13 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) child_process.execSync(`docker rm ${containerName}`, { "stdio": "ignore" }); } catch {} + const externalPort = 8080; + const child = child_process.spawn( "docker", [ "run", - ...["-p", "8080:8080"], + ...["-p", `${externalPort}:8080`], ...["--name", containerName], ...["-e", "KEYCLOAK_ADMIN=admin"], ...["-e", "KEYCLOAK_ADMIN_PASSWORD=admin"], @@ -144,5 +147,29 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) child.stderr.on("data", data => process.stderr.write(data)); + { + const handler = async (data: Buffer) => { + if (!data.toString("utf8").includes("Listening on: http://0.0.0.0:8080")) { + return; + } + + child.stdout.off("data", handler); + + await new Promise(resolve => setTimeout(resolve, 1_000)); + + console.log( + [ + "", + "", + `${chalk.green("Your theme is accessible at:")}`, + `${chalk.green("➜")} ${chalk.cyan.bold("https://test.keycloakify.dev/")}`, + "" + ].join("\n") + ); + }; + + child.stdout.on("data", handler); + } + child.on("exit", process.exit); } diff --git a/yarn.lock b/yarn.lock index e1d28f6a..816d6d29 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4713,6 +4713,14 @@ chai@^4.3.7: pathval "^1.1.1" type-detect "^4.0.5" +chalk@4.1.2, chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + chalk@^2.0.0, chalk@^2.4.1: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" @@ -4722,14 +4730,6 @@ chalk@^2.0.0, chalk@^2.4.1: escape-string-regexp "^1.0.5" supports-color "^5.3.0" -chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2: - version "4.1.2" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" - integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== - dependencies: - ansi-styles "^4.1.0" - supports-color "^7.1.0" - character-entities-legacy@^1.0.0: version "1.1.4" resolved "https://registry.yarnpkg.com/character-entities-legacy/-/character-entities-legacy-1.1.4.tgz#94bc1845dce70a5bb9d2ecc748725661293d8fc1"