Skip to content

Commit

Permalink
In verbose mode: Output workspace success summary
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Apr 4, 2024
1 parent da770ca commit 66bb6a2
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import chalk from 'chalk';
import meow from 'meow';
import { messageWithCauses, stackWithCauses } from 'pony-cause';
import { installedCheck } from 'installed-check-core';
import { installedCheck, ROOT } from 'installed-check-core';

const EXIT_CODE_ERROR_RESULT = 1;
const EXIT_CODE_INVALID_INPUT = 2;
Expand Down Expand Up @@ -111,17 +111,38 @@ try {
const result = await installedCheck(checks, lookupOptions, checkOptions);

if (verbose && result.warnings.length) {
console.log('\n' + chalk.bgYellow('Warnings:') + '\n\n' + result.warnings.join('\n') + '\n');
console.log('\n' + chalk.bgYellow.black('Warnings:') + '\n\n' + result.warnings.join('\n') + '\n');
} else if (result.errors.length) {
console.log('');
}

if (result.errors.length) {
console.error(chalk.bgRed('Errors:') + '\n\n' + result.errors.join('\n') + '\n');
console.error(chalk.bgRed.black('Errors:') + '\n\n' + result.errors.join('\n') + '\n');
}

if (result.suggestions.length) {
console.error(chalk.bgCyanBright('Suggestions:') + '\n\n' + result.suggestions.join('\n') + '\n');
console.error(chalk.bgCyanBright.black('Suggestions:') + '\n\n' + result.suggestions.join('\n') + '\n');
}

const workspaceSuccess = /** @type {const} */ ([
...Object.entries(result.workspaceSuccess),
...(result.workspaceSuccess[ROOT] === undefined ? [] : /** @type {const} */ ([['root', result.workspaceSuccess[ROOT]]])),
]);

if (verbose && workspaceSuccess.length) {
if (result.errors.length === 0 && workspaceSuccess.length === 1 && result.workspaceSuccess[ROOT]) {
console.log(chalk.bgGreen.black('Successful!') + '\n');
} else {
const success = workspaceSuccess.filter(([, value]) => value);
const failure = workspaceSuccess.filter(([, value]) => !value);

if (success.length) {
console.log(chalk.bgGreen.black('Successful workspaces:') + ' ' + success.map(([key]) => key).join(', ') + '\n');
}
if (failure.length) {
console.log(chalk.bgRed.black('Unsuccessful workspaces:') + ' ' + failure.map(([key]) => key).join(', ') + '\n');
}
}
}

if (result.errors.length) {
Expand Down

0 comments on commit 66bb6a2

Please sign in to comment.