Skip to content

Commit 6563149

Browse files
author
Ramon Brullo
committed
add color
1 parent 3252965 commit 6563149

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/cli/cmd-deps.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { SemanticVersion } from "../domain/semantic-version";
1616
import { isZod } from "../utils/zod-utils";
1717
import { stringifyDependencyGraph } from "./dependency-logging";
1818
import os from "os";
19+
import chalk from "chalk";
1920

2021
/**
2122
* Options passed to the deps command.
@@ -85,7 +86,8 @@ export function makeDepsCmd(
8586
const output = stringifyDependencyGraph(
8687
dependencyGraph,
8788
packageName,
88-
latestVersion
89+
latestVersion,
90+
chalk
8991
).join(os.EOL);
9092
log.notice("", output);
9193

src/cli/dependency-logging.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
VersionNotFoundError,
2222
} from "../domain/packument";
2323
import { PackumentNotFoundError } from "../common-errors";
24-
import { make } from "ts-brand";
24+
import { Chalk } from "chalk";
2525

2626
/**
2727
* Logs information about a resolved dependency to a logger.
@@ -73,15 +73,21 @@ export function logFailedDependency(
7373
* @param graph The graph.
7474
* @param rootPackage The name of the graphs root package.
7575
* @param rootVersion The version of the graphs root package.
76+
* @param chalk Used for coloring output. Omit if no color should be used.
7677
* @returns A string array representing the graph. Each string is a line.
7778
*/
7879
export function stringifyDependencyGraph(
7980
graph: DependencyGraph,
8081
rootPackage: DomainName,
81-
rootVersion: SemanticVersion
82+
rootVersion: SemanticVersion,
83+
chalk?: Chalk
8284
): readonly string[] {
8385
const printedRefs = new Set<PackageReference>();
8486

87+
function tryColor(chalk: Chalk | undefined, s: string) {
88+
return chalk !== undefined ? chalk(s) : s;
89+
}
90+
8591
function getNode(
8692
packageName: DomainName,
8793
version: SemanticVersion
@@ -109,7 +115,7 @@ export function stringifyDependencyGraph(
109115
}
110116

111117
function makeDuplicateLine(packageRef: PackageReference): string {
112-
return `${packageRef} ..`;
118+
return tryColor(chalk?.blueBright, `${packageRef} ..`);
113119
}
114120

115121
function makeErrorLines(errors: FailedNode["errors"]): readonly string[] {
@@ -174,7 +180,7 @@ export function stringifyDependencyGraph(
174180
- url2: package not found
175181
*/
176182
const errorLines = makeErrorLines(node.errors);
177-
return [packageRef, ...errorLines];
183+
return [tryColor(chalk?.red, packageRef), ...errorLines];
178184
}
179185

180186
// Resolved node

0 commit comments

Comments
 (0)