From 133b0c79532e76e2633021a2fcfff2657e17768a Mon Sep 17 00:00:00 2001 From: stanlou Date: Mon, 9 Mar 2026 12:45:11 -0300 Subject: [PATCH 1/4] feat(cli): add explorer stop command --- .../cli/src/commands/explorer/explorer.ts | 2 + .../cli/src/commands/explorer/explorerStop.ts | 17 +++++++++ packages/cli/src/scripts/explorer/start.ts | 12 +++++- packages/cli/src/scripts/explorer/stop.ts | 37 +++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 packages/cli/src/commands/explorer/explorerStop.ts create mode 100644 packages/cli/src/scripts/explorer/stop.ts diff --git a/packages/cli/src/commands/explorer/explorer.ts b/packages/cli/src/commands/explorer/explorer.ts index 037163de..4dd8c01f 100644 --- a/packages/cli/src/commands/explorer/explorer.ts +++ b/packages/cli/src/commands/explorer/explorer.ts @@ -5,9 +5,11 @@ export const explorerCommand: CommandModule = { describe: "Explorer commands", builder: async (yargs) => { const { explorerStartCommand } = await import("./explorerStart"); + const { explorerStopCommand } = await import("./explorerStop"); return yargs .command(explorerStartCommand) + .command(explorerStopCommand) .demandCommand( 1, "You must specify a subcommand. Use --help to see available options." diff --git a/packages/cli/src/commands/explorer/explorerStop.ts b/packages/cli/src/commands/explorer/explorerStop.ts new file mode 100644 index 00000000..3655e0cc --- /dev/null +++ b/packages/cli/src/commands/explorer/explorerStop.ts @@ -0,0 +1,17 @@ +import { CommandModule } from "yargs"; + +export const explorerStopCommand: CommandModule = { + command: "stop", + describe: "Stop the explorer UI", + handler: async () => { + try { + const { default: explorerStop } = + await import("../../scripts/explorer/stop"); + await explorerStop(); + process.exit(0); + } catch (error) { + console.error("Failed to stop explorer:", error); + process.exit(1); + } + }, +}; diff --git a/packages/cli/src/scripts/explorer/start.ts b/packages/cli/src/scripts/explorer/start.ts index b84105c9..d843d427 100644 --- a/packages/cli/src/scripts/explorer/start.ts +++ b/packages/cli/src/scripts/explorer/start.ts @@ -35,8 +35,16 @@ async function runDockerContainer(args: { const { port = 5003, explorerImage } = args; console.log(`\nExplorer is running at http://localhost:${port}\n`); - const dockerArgs = ["run", "--rm", "-p", `${port}:3000`]; - + const dockerArgs = [ + "run", + "-d", + "--rm", + "--name", + "protokit-explorer", + "-p", + `${port}:3000`, + ]; + if (args.indexerUrl !== undefined) { dockerArgs.push("-e", `NEXT_PUBLIC_INDEXER_URL=${args.indexerUrl}`); } diff --git a/packages/cli/src/scripts/explorer/stop.ts b/packages/cli/src/scripts/explorer/stop.ts new file mode 100644 index 00000000..cc0c46aa --- /dev/null +++ b/packages/cli/src/scripts/explorer/stop.ts @@ -0,0 +1,37 @@ +import { spawn } from "child_process"; + +const CONTAINER_NAME = "protokit-explorer"; + +async function stopDockerContainer(): Promise { + return await new Promise((resolve, reject) => { + console.log(`Stopping explorer container...`); + const child = spawn("docker", ["stop", CONTAINER_NAME], { + stdio: "inherit", + }); + + child.on("error", (error) => { + console.error("Failed to stop explorer container:", error); + reject(error); + }); + + child.on("exit", (code) => { + if (code !== null && code !== 0) { + reject( + new Error(`Failed to stop explorer container (exit code ${code})`) + ); + } else { + console.log("Explorer container stopped successfully"); + resolve(); + } + }); + }); +} + +export default async function (): Promise { + try { + await stopDockerContainer(); + } catch (error) { + console.error("Failed to stop explorer:", error); + throw error; + } +} From 6c4994e32fec650b24f145ea8466e3618cc65dd1 Mon Sep 17 00:00:00 2001 From: stanlou Date: Mon, 9 Mar 2026 13:14:05 -0300 Subject: [PATCH 2/4] fix lint --- packages/cli/src/scripts/explorer/start.ts | 2 +- packages/cli/src/scripts/explorer/stop.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/scripts/explorer/start.ts b/packages/cli/src/scripts/explorer/start.ts index d843d427..a9e129ef 100644 --- a/packages/cli/src/scripts/explorer/start.ts +++ b/packages/cli/src/scripts/explorer/start.ts @@ -44,7 +44,7 @@ async function runDockerContainer(args: { "-p", `${port}:3000`, ]; - + if (args.indexerUrl !== undefined) { dockerArgs.push("-e", `NEXT_PUBLIC_INDEXER_URL=${args.indexerUrl}`); } diff --git a/packages/cli/src/scripts/explorer/stop.ts b/packages/cli/src/scripts/explorer/stop.ts index cc0c46aa..db229407 100644 --- a/packages/cli/src/scripts/explorer/stop.ts +++ b/packages/cli/src/scripts/explorer/stop.ts @@ -4,7 +4,7 @@ const CONTAINER_NAME = "protokit-explorer"; async function stopDockerContainer(): Promise { return await new Promise((resolve, reject) => { - console.log(`Stopping explorer container...`); + console.log("Stopping explorer container..."); const child = spawn("docker", ["stop", CONTAINER_NAME], { stdio: "inherit", }); From cf11098ced7fe60f95dfeafe90d12483b4f6e24f Mon Sep 17 00:00:00 2001 From: stanlou Date: Wed, 11 Mar 2026 01:11:50 -0300 Subject: [PATCH 3/4] refactor(cli): centralize explorer Docker container name as exported constant --- packages/cli/src/scripts/explorer/start.ts | 3 ++- packages/cli/src/scripts/explorer/stop.ts | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/scripts/explorer/start.ts b/packages/cli/src/scripts/explorer/start.ts index a9e129ef..37f5941e 100644 --- a/packages/cli/src/scripts/explorer/start.ts +++ b/packages/cli/src/scripts/explorer/start.ts @@ -1,5 +1,6 @@ import { spawn } from "child_process"; +export const EXPLORER_CONTAINER_NAME = "protokit-explorer"; const DEFAULT_EXPLORER_IMAGE = "ghcr.io/proto-kit/explorer:latest"; async function pullDockerImage(image: string): Promise { @@ -40,7 +41,7 @@ async function runDockerContainer(args: { "-d", "--rm", "--name", - "protokit-explorer", + EXPLORER_CONTAINER_NAME, "-p", `${port}:3000`, ]; diff --git a/packages/cli/src/scripts/explorer/stop.ts b/packages/cli/src/scripts/explorer/stop.ts index db229407..133b33c3 100644 --- a/packages/cli/src/scripts/explorer/stop.ts +++ b/packages/cli/src/scripts/explorer/stop.ts @@ -1,11 +1,10 @@ import { spawn } from "child_process"; - -const CONTAINER_NAME = "protokit-explorer"; +import { EXPLORER_CONTAINER_NAME } from "./start"; async function stopDockerContainer(): Promise { return await new Promise((resolve, reject) => { console.log("Stopping explorer container..."); - const child = spawn("docker", ["stop", CONTAINER_NAME], { + const child = spawn("docker", ["stop", EXPLORER_CONTAINER_NAME], { stdio: "inherit", }); From 59e348773656b0eb2216caebcae93e9a5d96b848 Mon Sep 17 00:00:00 2001 From: stanlou Date: Wed, 11 Mar 2026 09:21:35 -0300 Subject: [PATCH 4/4] fix lint --- packages/cli/src/scripts/explorer/stop.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cli/src/scripts/explorer/stop.ts b/packages/cli/src/scripts/explorer/stop.ts index 133b33c3..7fd2d947 100644 --- a/packages/cli/src/scripts/explorer/stop.ts +++ b/packages/cli/src/scripts/explorer/stop.ts @@ -1,4 +1,5 @@ import { spawn } from "child_process"; + import { EXPLORER_CONTAINER_NAME } from "./start"; async function stopDockerContainer(): Promise {