Arseniy Klempner 0df18b2a75
feat: create @waku/run package for local dev env (#2678)
* 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
2025-10-22 21:38:28 -07:00

64 lines
2.1 KiB
TypeScript

import { readFileSync } from "fs";
import { join } from "path";
import { DEFAULT_NUM_SHARDS_IN_CLUSTER } from "./constants.js";
export function getProjectName(packageRoot: string): string {
const packageJsonPath = join(packageRoot, "package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
// Docker Compose project names must consist only of lowercase alphanumeric characters, hyphens, and underscores
const name = packageJson.name.replace("@", "").replace("/", "-");
const version = packageJson.version.replace(/\./g, "-");
return `${name}-${version}`;
}
interface Colors {
reset: string;
cyan: string;
blue: string;
yellow: string;
}
export function printWakuConfig(
colors: Colors,
node1Port: string,
node2Port: string,
peer1: string,
peer2: string,
clusterId: string
): void {
process.stdout.write(
`${colors.blue}import${colors.reset} { createLightNode } ${colors.blue}from${colors.reset} ${colors.yellow}"@waku/sdk"${colors.reset};\n`
);
process.stdout.write(`\n`);
process.stdout.write(
`${colors.blue}const${colors.reset} waku = ${colors.blue}await${colors.reset} createLightNode({\n`
);
process.stdout.write(
` defaultBootstrap: ${colors.cyan}false${colors.reset},\n`
);
process.stdout.write(` bootstrapPeers: [\n`);
process.stdout.write(
` ${colors.yellow}"/ip4/127.0.0.1/tcp/${node1Port}/ws/p2p/${peer1}"${colors.reset},\n`
);
process.stdout.write(
` ${colors.yellow}"/ip4/127.0.0.1/tcp/${node2Port}/ws/p2p/${peer2}"${colors.reset}\n`
);
process.stdout.write(` ],\n`);
process.stdout.write(` numPeersToUse: ${colors.cyan}2${colors.reset},\n`);
process.stdout.write(` libp2p: {\n`);
process.stdout.write(
` filterMultiaddrs: ${colors.cyan}false${colors.reset}\n`
);
process.stdout.write(` },\n`);
process.stdout.write(` networkConfig: {\n`);
process.stdout.write(
` clusterId: ${colors.cyan}${clusterId}${colors.reset},\n`
);
process.stdout.write(
` numShardsInCluster: ${colors.cyan}${DEFAULT_NUM_SHARDS_IN_CLUSTER}${colors.reset}\n`
);
process.stdout.write(` }\n`);
process.stdout.write(`});\n`);
}