Colors in the terminal

This commit is contained in:
Joseph Garrone 2024-05-18 10:02:14 +02:00
parent e248a58201
commit 2c5473da27
3 changed files with 37 additions and 9 deletions

View File

@ -108,6 +108,7 @@
"@babel/parser": "^7.22.7", "@babel/parser": "^7.22.7",
"@babel/types": "^7.22.5", "@babel/types": "^7.22.5",
"@octokit/rest": "^20.1.1", "@octokit/rest": "^20.1.1",
"chalk": "4.1.2",
"cheerio": "^1.0.0-rc.5", "cheerio": "^1.0.0-rc.5",
"cli-select": "^1.1.2", "cli-select": "^1.1.2",
"evt": "^2.5.7", "evt": "^2.5.7",

View File

@ -10,6 +10,7 @@ import { assert, type Equals } from "tsafe/assert";
import * as fs from "fs"; import * as fs from "fs";
import { join as pathJoin, posix as pathPosix } from "path"; import { join as pathJoin, posix as pathPosix } from "path";
import * as child_process from "child_process"; import * as child_process from "child_process";
import chalk from "chalk";
export async function command(params: { cliCommandOptions: CliCommandOptions }) { export async function command(params: { cliCommandOptions: CliCommandOptions }) {
const { cliCommandOptions } = params; const { cliCommandOptions } = params;
@ -120,11 +121,13 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
child_process.execSync(`docker rm ${containerName}`, { "stdio": "ignore" }); child_process.execSync(`docker rm ${containerName}`, { "stdio": "ignore" });
} catch {} } catch {}
const externalPort = 8080;
const child = child_process.spawn( const child = child_process.spawn(
"docker", "docker",
[ [
"run", "run",
...["-p", "8080:8080"], ...["-p", `${externalPort}:8080`],
...["--name", containerName], ...["--name", containerName],
...["-e", "KEYCLOAK_ADMIN=admin"], ...["-e", "KEYCLOAK_ADMIN=admin"],
...["-e", "KEYCLOAK_ADMIN_PASSWORD=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)); 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); child.on("exit", process.exit);
} }

View File

@ -4713,6 +4713,14 @@ chai@^4.3.7:
pathval "^1.1.1" pathval "^1.1.1"
type-detect "^4.0.5" 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: chalk@^2.0.0, chalk@^2.4.1:
version "2.4.2" version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" 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" escape-string-regexp "^1.0.5"
supports-color "^5.3.0" 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: character-entities-legacy@^1.0.0:
version "1.1.4" version "1.1.4"
resolved "https://registry.yarnpkg.com/character-entities-legacy/-/character-entities-legacy-1.1.4.tgz#94bc1845dce70a5bb9d2ecc748725661293d8fc1" resolved "https://registry.yarnpkg.com/character-entities-legacy/-/character-entities-legacy-1.1.4.tgz#94bc1845dce70a5bb9d2ecc748725661293d8fc1"