mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-02 05:43:08 +00:00
* feat: create @waku/run package for local dev env * chore: add @waku/run to release please config * feat: test @waku/run with playwright * fix: don't run waku/run tests in CI * fix: cache images so docker-compose can work offline * feat: set nodekey and staticnode flags for each nwaku node * fix: use constants for node ids * chore: set directories for running via npx * fix: remove .env, support env vars for nwaku ports * fix: use separate db (same instance) for each node * feat: add command to test dev env * chore: use package version in container name * fix: replace hardcoded WS/REST ports with constants/env vars * chore: clean up README * fix: refactor config printing into own function * fix: add run package to release please manifest * fix: defer to root folder gitignore/cspell * fix: update node version and remove tsx * fix: remove browser tests and express dep * fix: replace magic values with constants * fix: move to root .gitignore * fix: move cspell to root
84 lines
2.3 KiB
JavaScript
Executable File
84 lines
2.3 KiB
JavaScript
Executable File
#!/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);
|
|
}
|
|
}
|