Skip to content

Commit

Permalink
tree command should output to the stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Feb 27, 2024
1 parent c2455db commit ab97cee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
26 changes: 13 additions & 13 deletions lib/cli/commands/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ tree.handler = async function(argv) {
if (project.isFrameworkProject()) {
name = chalk.blue(name);
}
process.stderr.write(
process.stdout.write(
`${baseString}${connectorString} ${name} ` +
`${project.getNamespace() ? chalk.inverse(project.getNamespace()) + " " : ""}` +
chalk.dim(`(${project.getVersion()}, ${project.getType()}) `) +
chalk.dim.italic(`${project.getRootPath()}`)
);
process.stderr.write("\n");
process.stdout.write("\n");

const lastIdx = dependencies.length - 1;
const newConnectorIndices = [...connectorIndices];
Expand All @@ -110,8 +110,8 @@ tree.handler = async function(argv) {
newConnectorIndices.forEach((idx) => {
nextBaseString = `${nextBaseString.slice(0, idx)}${nextBaseString.slice(idx + 1)}`;
});
process.stderr.write(`${nextBaseString}╰─ ${msg}`);
process.stderr.write("\n");
process.stdout.write(`${nextBaseString}╰─ ${msg}`);
process.stdout.write("\n");
return;
}
if (renderDeps) {
Expand All @@ -123,8 +123,8 @@ tree.handler = async function(argv) {
});
});

process.stderr.write(chalk.bold.underline(`Dependencies (${projects.size}):`));
process.stderr.write("\n");
process.stdout.write(chalk.bold.underline(`Dependencies (${projects.size}):`));
process.stdout.write("\n");
if (argv.flat) {
// Iterate over list of projects, rendering each individually
// We need to transform the map into an array in order to know the index
Expand All @@ -136,26 +136,26 @@ tree.handler = async function(argv) {
// Recursively render the tree, starting with the first entry of the map
projects.values().next().value.render(0, [], true);
}
process.stderr.write("\n");
process.stdout.write("\n");

const extensionNames = graph.getExtensionNames();
const extensionCount = extensionNames.length;
process.stderr.write(chalk.bold.underline(`Extensions (${extensionCount}):`));
process.stderr.write("\n");
process.stdout.write(chalk.bold.underline(`Extensions (${extensionCount}):`));
process.stdout.write("\n");
if (extensionCount) {
const lastIdx = extensionCount - 1;
extensionNames.forEach((extensionName, idx) => {
const extension = graph.getExtension(extensionName);
const connectorString = idx === lastIdx ? "╰─" : "├─";
process.stderr.write(
process.stdout.write(
`${connectorString} ${extensionName} ` +
chalk.dim(`(${extension.getVersion()}, ${extension.getType()}) `) +
chalk.dim.italic(`${extension.getRootPath()}`));
process.stderr.write("\n");
process.stdout.write("\n");
});
} else {
process.stderr.write(chalk.italic(`None`));
process.stderr.write("\n");
process.stdout.write(chalk.italic(`None`));
process.stdout.write("\n");
}
if (argv.perf) {
process.stderr.write("\n");
Expand Down
4 changes: 3 additions & 1 deletion test/lib/cli/commands/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ test.beforeEach(async (t) => {

t.context.consoleOutput = "";
t.context.processStderrWrite = sinon.stub(process.stderr, "write").callsFake((message) => {
// NOTE: This fake impl only supports one string arg passed to console.log
t.context.consoleOutput += message;
});
t.context.processStdoutWrite = sinon.stub(process.stdout, "write").callsFake((message) => {
t.context.consoleOutput += message;
});

Expand Down

0 comments on commit ab97cee

Please sign in to comment.