Skip to content

Commit

Permalink
feat(handle-check-failure): extract as separate task (from process)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomastrajan committed Mar 18, 2023
1 parent 2f3d146 commit 1d1aa91
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
2 changes: 2 additions & 0 deletions lib/commands/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { saveProjectApiTask } from '../tasks/save-project-api.task';
import { saveProjectJsonTask } from '../tasks/save-project-json.task';
import { retrieveSettingsTask } from '../tasks/retrieve-settings.task';
import { prepareProjectDataTask } from '../tasks/prepare-project-data.task';
import { handledCheckFailureInfoTask } from '../tasks/handled-check-failure-info.tast';

const logger = createLogger('ANALYZE');

Expand Down Expand Up @@ -53,6 +54,7 @@ export const handler = async (argv: any) =>
prepareProjectDataTask,
saveProjectJsonTask,
saveProjectApiTask,
handledCheckFailureInfoTask,
],
argv,
logger
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/test-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { projectInfoTask } from '../tasks/project-info.task';
import { saveProjectJsonTask } from '../tasks/save-project-json.task';
import { prepareProjectDataTask } from '../tasks/prepare-project-data.task';
import { printProjectCliOutputTask } from '../tasks/print-project-cli-output.task';
import { handledCheckFailureInfoTask } from '../tasks/handled-check-failure-info.tast';

const logger = createLogger('TEST CHECK');

Expand Down Expand Up @@ -43,6 +44,7 @@ export const handler = async (argv: any) =>
prepareProjectDataTask,
saveProjectJsonTask,
printProjectCliOutputTask,
handledCheckFailureInfoTask,
],
argv,
logger
Expand Down
22 changes: 22 additions & 0 deletions lib/tasks/handled-check-failure-info.tast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import chalk from 'chalk';
import { ListrTask } from 'listr2';

import { Context } from '../interface';

export const handledCheckFailureInfoTask: ListrTask = {
title: 'Handled check failure info',
skip: (ctx: Context) => ctx.control.skipEverySubsequentTask,
task: (ctx: Context, task) => {
if (ctx.handledCheckFailures.length) {
const count = ctx.handledCheckFailures.length;
task.title = `${task.title} - ${count} handled check failure${
count > 1 ? 's' : ''
} occurred`;
ctx.handledCheckFailures.forEach((error) => {
task.title = `${task.title}\n${chalk.yellow.bold(
`⚠️ ${error.message}`
)}`;
});
}
},
};
12 changes: 1 addition & 11 deletions lib/utils/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,11 @@ export const runner = async (
};
await new Listr(tasks, {
rendererFallback: () => options?.verbose,
rendererOptions: { collapse: false, showTimer: true },
rendererOptions: { collapse: false, showTimer: true, formatOutput: 'wrap' },
renderer: options.silent ? 'silent' : 'default',
})
.run(context)
.then(() => {
if (context.handledCheckFailures.length) {
logger.warning(
`${context.handledCheckFailures.length} handled check failure${
context.handledCheckFailures.length > 1 ? 's' : ''
} occurred`
);
context.handledCheckFailures.forEach((error) => {
logger.warning(error.message);
});
}
const duration = new Date().getTime() - start;
logger.info(`Finished (${formatTime(duration)})`);
process.exit(0);
Expand Down

0 comments on commit 1d1aa91

Please sign in to comment.