mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-03 22:33:07 +00:00
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
|
|
#!/usr/bin/env node
|
||
|
|
|
||
|
|
import { execSync } from "child_process";
|
||
|
|
import { dirname, join } from "path";
|
||
|
|
import { fileURLToPath } from "url";
|
||
|
|
|
||
|
|
import {
|
||
|
|
DEFAULT_CLUSTER_ID,
|
||
|
|
DEFAULT_NODE1_WS_PORT,
|
||
|
|
DEFAULT_NODE2_WS_PORT,
|
||
|
|
NODE1_PEER_ID,
|
||
|
|
NODE2_PEER_ID
|
||
|
|
} from "../src/constants.js";
|
||
|
|
import { getProjectName, printWakuConfig } from "../src/utils.js";
|
||
|
|
|
||
|
|
const __filename = fileURLToPath(import.meta.url);
|
||
|
|
const __dirname = dirname(__filename);
|
||
|
|
const packageRoot = __dirname.includes("dist")
|
||
|
|
? join(__dirname, "..", "..")
|
||
|
|
: join(__dirname, "..");
|
||
|
|
|
||
|
|
interface Colors {
|
||
|
|
reset: string;
|
||
|
|
cyan: string;
|
||
|
|
blue: string;
|
||
|
|
gray: string;
|
||
|
|
yellow: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ANSI color codes
|
||
|
|
const colors: Colors = {
|
||
|
|
reset: "\x1b[0m",
|
||
|
|
cyan: "\x1b[36m",
|
||
|
|
blue: "\x1b[34m",
|
||
|
|
gray: "\x1b[90m",
|
||
|
|
yellow: "\x1b[33m"
|
||
|
|
};
|
||
|
|
|
||
|
|
try {
|
||
|
|
// Check if containers are running
|
||
|
|
const projectName = getProjectName(packageRoot);
|
||
|
|
const output: string = execSync(
|
||
|
|
`docker compose --project-name ${projectName} ps --quiet`,
|
||
|
|
{
|
||
|
|
cwd: packageRoot,
|
||
|
|
encoding: "utf-8",
|
||
|
|
env: { ...process.env, COMPOSE_PROJECT_NAME: projectName }
|
||
|
|
}
|
||
|
|
).trim();
|
||
|
|
|
||
|
|
if (!output) {
|
||
|
|
process.stdout.write(
|
||
|
|
`${colors.gray}No nodes running. Start with: ${colors.cyan}npm run start${colors.reset}\n`
|
||
|
|
);
|
||
|
|
process.exit(0);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Get cluster config from env or defaults
|
||
|
|
const clusterId: string = process.env.CLUSTER_ID || DEFAULT_CLUSTER_ID;
|
||
|
|
const node1Port: string = process.env.NODE1_WS_PORT || DEFAULT_NODE1_WS_PORT;
|
||
|
|
const node2Port: string = process.env.NODE2_WS_PORT || DEFAULT_NODE2_WS_PORT;
|
||
|
|
|
||
|
|
// Static peer IDs from --nodekey configuration
|
||
|
|
// cspell:ignore nodekey
|
||
|
|
const peer1: string = NODE1_PEER_ID;
|
||
|
|
const peer2: string = NODE2_PEER_ID;
|
||
|
|
|
||
|
|
// Print TypeScript-style config
|
||
|
|
printWakuConfig(colors, node1Port, node2Port, peer1, peer2, clusterId);
|
||
|
|
} catch (error: unknown) {
|
||
|
|
const err = error as { cause?: { code?: string }; message?: string };
|
||
|
|
if (err.cause?.code === "ECONNREFUSED") {
|
||
|
|
process.stderr.write(
|
||
|
|
`${colors.yellow}⚠${colors.reset} Nodes are still starting. Try again in a few seconds.\n`
|
||
|
|
);
|
||
|
|
process.exit(1);
|
||
|
|
} else {
|
||
|
|
process.stderr.write(
|
||
|
|
`${colors.yellow}✗${colors.reset} Error: ${err.message || String(error)}\n`
|
||
|
|
);
|
||
|
|
process.exit(1);
|
||
|
|
}
|
||
|
|
}
|