chore: set directories for running via npx

This commit is contained in:
Arseniy Klempner 2025-10-10 13:55:05 -07:00
parent 3ea83f800d
commit 5944c83a33
No known key found for this signature in database
GPG Key ID: 51653F18863BD24B
5 changed files with 77 additions and 1 deletions

View File

@ -1,9 +1,19 @@
#!/usr/bin/env node
import { execSync } from "child_process";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
import { NODE1_PEER_ID, NODE2_PEER_ID } from "../src/constants.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// In development: scripts are in packages/run/scripts
// In published package: scripts are in node_modules/@waku/run/dist/scripts
const packageRoot = __dirname.includes("dist")
? join(__dirname, "..", "..")
: join(__dirname, "..");
interface Colors {
reset: string;
cyan: string;
@ -24,6 +34,7 @@ const colors: Colors = {
try {
// Check if containers are running
const output: string = execSync("docker compose ps --quiet", {
cwd: packageRoot,
encoding: "utf-8"
}).trim();

View File

@ -0,0 +1,24 @@
#!/usr/bin/env node
import { execSync } from "child_process";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// In development: scripts are in packages/run/scripts
// In published package: scripts are in node_modules/@waku/run/dist/scripts
const packageRoot = __dirname.includes("dist")
? join(__dirname, "..", "..")
: join(__dirname, "..");
try {
execSync("docker compose logs -f", {
cwd: packageRoot,
stdio: "inherit"
});
} catch (error: unknown) {
const err = error as { message?: string };
process.stderr.write(`Error viewing logs: ${err.message || String(error)}\n`);
process.exit(1);
}

View File

@ -1,9 +1,19 @@
#!/usr/bin/env node
import { execSync } from "child_process";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
import { NODE1_PEER_ID, NODE2_PEER_ID } from "../src/constants.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// In development: scripts are in packages/run/scripts
// In published package: scripts are in node_modules/@waku/run/dist/scripts
const packageRoot = __dirname.includes("dist")
? join(__dirname, "..", "..")
: join(__dirname, "..");
interface Colors {
reset: string;
cyan: string;
@ -91,6 +101,7 @@ try {
// Start docker compose quietly
execSync("docker compose up -d", {
cwd: packageRoot,
stdio: ["ignore", "ignore", "pipe"],
encoding: "utf-8"
});

View File

@ -0,0 +1,26 @@
#!/usr/bin/env node
import { execSync } from "child_process";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// In development: scripts are in packages/run/scripts
// In published package: scripts are in node_modules/@waku/run/dist/scripts
const packageRoot = __dirname.includes("dist")
? join(__dirname, "..", "..")
: join(__dirname, "..");
try {
execSync("docker compose down", {
cwd: packageRoot,
stdio: "inherit"
});
} catch (error: unknown) {
const err = error as { message?: string };
process.stderr.write(
`Error stopping network: ${err.message || String(error)}\n`
);
process.exit(1);
}

View File

@ -11,7 +11,9 @@ const command = process.argv[2];
const scriptMap: Record<string, string> = {
start: join(__dirname, "..", "scripts", "start.js"),
info: join(__dirname, "..", "scripts", "info.js")
stop: join(__dirname, "..", "scripts", "stop.js"),
info: join(__dirname, "..", "scripts", "info.js"),
logs: join(__dirname, "..", "scripts", "logs.js")
};
if (!command || !scriptMap[command]) {
@ -19,7 +21,9 @@ if (!command || !scriptMap[command]) {
process.stderr.write("\n");
process.stderr.write("Commands:\n");
process.stderr.write(" start Start the local Waku network\n");
process.stderr.write(" stop Stop the local Waku network\n");
process.stderr.write(" info Show connection info for running network\n");
process.stderr.write(" logs View logs from running network\n");
process.exit(1);
}