Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cli/src/commands/explorer/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
17 changes: 17 additions & 0 deletions packages/cli/src/commands/explorer/explorerStop.ts
Original file line number Diff line number Diff line change
@@ -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);
}
},
};
10 changes: 9 additions & 1 deletion packages/cli/src/scripts/explorer/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ 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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse the constant you defined in stop here?

"-p",
`${port}:3000`,
];

if (args.indexerUrl !== undefined) {
dockerArgs.push("-e", `NEXT_PUBLIC_INDEXER_URL=${args.indexerUrl}`);
Expand Down
37 changes: 37 additions & 0 deletions packages/cli/src/scripts/explorer/stop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { spawn } from "child_process";

const CONTAINER_NAME = "protokit-explorer";

async function stopDockerContainer(): Promise<void> {
return await new Promise<void>((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<void> {
try {
await stopDockerContainer();
} catch (error) {
console.error("Failed to stop explorer:", error);
throw error;
}
}