Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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: 0 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
"ntt": "src/index.ts"
},
"dependencies": {
"chalk": "^5.6.0",
"ora": "8.2.0",
"yargs": "18.0.0"
},
"overrides": {
Expand Down
24 changes: 24 additions & 0 deletions cli/src/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Simple ANSI color utilities */

const RESET = "\x1b[0m";

const useColors =
process.env.NO_COLOR === undefined &&
(process.env.FORCE_COLOR !== undefined || process.stdout.isTTY);

const c = (code: string) => (text: unknown) =>
useColors ? `${code}${text}${RESET}` : String(text);

export const colors = {
red: c("\x1b[31m"),
green: c("\x1b[32m"),
yellow: c("\x1b[33m"),
blue: c("\x1b[34m"),
cyan: c("\x1b[36m"),
white: c("\x1b[37m"),
gray: c("\x1b[90m"),
dim: c("\x1b[2m"),
reset: (text: unknown) => String(text),
};

export default colors;
8 changes: 4 additions & 4 deletions cli/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assertChain, chains, type Chain } from "@wormhole-foundation/sdk";
import * as yargs from "yargs";
import fs from "fs";
import { ensureNttRoot } from ".";
import chalk from "chalk";
import { colors } from "./colors.js";

// We support project-local and global configuration.
// The configuration is stored in JSON files in $HOME/.ntt-cli/config.json (global) and .ntt-cli/config.json (local).
Expand Down Expand Up @@ -189,13 +189,13 @@ export function get(
const varName = envVarName(chain, key);
const env = process.env[varName];
if (env) {
console.info(chalk.yellow(`Using ${varName} for ${chain} ${key}`));
console.info(colors.yellow(`Using ${varName} for ${chain} ${key}`));
return env;
}
const local = getChainConfig("local", chain, key);
if (local) {
console.info(
chalk.yellow(
colors.yellow(
`Using local configuration for ${chain} ${key} (in .ntt-cli/config.json)`
)
);
Expand All @@ -204,7 +204,7 @@ export function get(
const global = getChainConfig("global", chain, key);
if (global) {
console.info(
chalk.yellow(
colors.yellow(
`Using global configuration for ${chain} ${key} (in $HOME/.ntt-cli/config.json)`
)
);
Expand Down
8 changes: 4 additions & 4 deletions cli/src/diff.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from "chalk";
import { colors } from "./colors.js";

export type Diff<T> = {
push?: T;
Expand Down Expand Up @@ -94,9 +94,9 @@ export function colorizeDiff(diff: any, indent = 2): string {
if (push !== undefined && pull !== undefined) {
result += `${line}\n`;
} else if (push !== undefined) {
result += line.replace(trimmedLine, chalk.red(trimmedLine)) + "\n";
result += line.replace(trimmedLine, colors.red(trimmedLine)) + "\n";
} else if (pull !== undefined) {
result += line.replace(trimmedLine, chalk.green(trimmedLine)) + "\n";
result += line.replace(trimmedLine, colors.green(trimmedLine)) + "\n";
}
} else {
result += line + "\n";
Expand All @@ -105,7 +105,7 @@ export function colorizeDiff(diff: any, indent = 2): string {
trimmedLine.startsWith('"push"') ||
trimmedLine.startsWith('"pull"')
) {
const color = trimmedLine.startsWith('"push"') ? chalk.green : chalk.red;
const color = trimmedLine.startsWith('"push"') ? colors.green : colors.red;
result += line.replace(trimmedLine, color(trimmedLine)) + "\n";
} else {
result += line + "\n";
Expand Down
42 changes: 21 additions & 21 deletions cli/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from "chalk";
import { colors } from "./colors.js";
import type { Chain, Network } from "@wormhole-foundation/sdk";
import { chainToPlatform } from "@wormhole-foundation/sdk-base";

Expand Down Expand Up @@ -55,7 +55,7 @@ function handleSuiDeploymentError(error: any, rpc: string): boolean {
return false;
}

console.error(chalk.red("\nSui deployment failed\n"));
console.error(colors.red("\nSui deployment failed\n"));

let errorMessage = "";

Expand All @@ -82,7 +82,7 @@ function handleSuiDeploymentError(error: any, rpc: string): boolean {
errorMessage = error.message;
}

console.error(chalk.red(errorMessage || "Unknown deployment error"));
console.error(colors.red(errorMessage || "Unknown deployment error"));

return true;
}
Expand All @@ -106,27 +106,27 @@ function handleRpcConnectionError(

const errorMessage = error?.message || String(error);

console.error(chalk.red(`RPC connection error for ${chain} on ${network}\n`));
console.error(chalk.yellow("RPC endpoint:"), chalk.white(rpc));
console.error(chalk.yellow("Error:"), errorMessage);
console.error(colors.red(`RPC connection error for ${chain} on ${network}\n`));
console.error(colors.yellow("RPC endpoint:"), colors.white(rpc));
console.error(colors.yellow("Error:"), errorMessage);
console.error();
console.error(
chalk.yellow(
colors.yellow(
"This error usually means the RPC endpoint is missing, invalid, or unreachable."
)
);
console.error(
chalk.yellow(
colors.yellow(
"You can specify a private RPC endpoint by creating an overrides.json file.\n"
)
);
console.error(
chalk.cyan("Create a file named ") +
chalk.white("overrides.json") +
chalk.cyan(" in your project root:")
colors.cyan("Create a file named ") +
colors.white("overrides.json") +
colors.cyan(" in your project root:")
);
console.error(
chalk.white(`
colors.white(`
{
"chains": {
"${chain}": {
Expand All @@ -142,15 +142,15 @@ function handleRpcConnectionError(
const platform = chainToPlatform(chain as any);
if (platform === "Evm") {
console.error(
chalk.cyan(`Find RPC endpoints for ${chain}: https://chainlist.org`)
colors.cyan(`Find RPC endpoints for ${chain}: https://chainlist.org`)
);
}
} catch (e) {
// If chainToPlatform fails, just skip the platform-specific message
}

console.error(
chalk.cyan(
colors.cyan(
`For more information about overrides.json:\n` +
` • https://wormhole.com/docs/products/token-transfers/native-token-transfers/faqs/#how-can-i-specify-a-custom-rpc-for-ntt`
)
Expand All @@ -163,30 +163,30 @@ function handleRpcConnectionError(
* @param error - The error that occurred
*/
function handleGenericError(error: any): never {
console.error(chalk.red("\nDeployment failed\n"));
console.error(colors.red("\nDeployment failed\n"));

const errorMessage = error?.message || String(error);

// Show stdout if available
if (error.stdout) {
console.error(chalk.yellow("Output:"));
console.error(colors.yellow("Output:"));
console.error(error.stdout.toString());
}

// Show stderr if available
if (error.stderr) {
console.error(chalk.yellow("\nError output:"));
console.error(colors.yellow("\nError output:"));
console.error(error.stderr.toString());
}

// Show message if no stdout/stderr
if (!error.stdout && !error.stderr) {
console.error(chalk.yellow("Error:"), errorMessage);
console.error(colors.yellow("Error:"), errorMessage);

// Show stack trace for debugging if available
if (error.stack) {
console.error(chalk.dim("\nStack trace:"));
console.error(chalk.dim(error.stack));
console.error(colors.dim("\nStack trace:"));
console.error(colors.dim(error.stack));
}
}

Expand Down Expand Up @@ -223,6 +223,6 @@ export function logRpcError(
return;
}
const message = error instanceof Error ? error.message : String(error);
console.error(chalk.red(`RPC error for ${chain} on ${network}`));
console.error(colors.red(`RPC error for ${chain} on ${network}`));
console.error(message);
}
Loading
Loading