|
| 1 | +import { output } from '../../utils/output'; |
| 2 | +import { TaskStatus } from '../tasks-runner'; |
| 3 | +import { getPrintableCommandArgsForTask } from '../utils'; |
| 4 | +import type { LifeCycle } from '../life-cycle'; |
| 5 | +import { Task } from '../../config/task-graph'; |
| 6 | +import { formatFlags, formatTargetsAndProjects } from './formatting-utils'; |
| 7 | + |
| 8 | +export class InvokeRunnerTerminalOutputLifeCycle implements LifeCycle { |
| 9 | + failedTasks = [] as Task[]; |
| 10 | + cachedTasks = [] as Task[]; |
| 11 | + |
| 12 | + constructor(private readonly tasks: Task[]) {} |
| 13 | + |
| 14 | + startCommand(): void { |
| 15 | + output.log({ |
| 16 | + color: 'cyan', |
| 17 | + title: `Running ${this.tasks.length} tasks:`, |
| 18 | + bodyLines: this.tasks.map( |
| 19 | + (task) => |
| 20 | + `- Task ${task.id} ${ |
| 21 | + task.overrides.__overrides_unparsed__ |
| 22 | + ? `Overrides: ${task.overrides.__overrides_unparsed__}` |
| 23 | + : '' |
| 24 | + }` |
| 25 | + ), |
| 26 | + }); |
| 27 | + |
| 28 | + output.addVerticalSeparatorWithoutNewLines('cyan'); |
| 29 | + } |
| 30 | + |
| 31 | + endCommand(): void { |
| 32 | + output.addNewline(); |
| 33 | + const taskIds = this.tasks.map((task) => { |
| 34 | + const cached = this.cachedTasks.indexOf(task) !== -1; |
| 35 | + const failed = this.failedTasks.indexOf(task) !== -1; |
| 36 | + return `- Task ${task.id} ${ |
| 37 | + task.overrides.__overrides_unparsed__ |
| 38 | + ? `Overrides: ${task.overrides.__overrides_unparsed__}` |
| 39 | + : '' |
| 40 | + } ${cached ? 'CACHED' : ''} ${failed ? 'FAILED' : ''}`; |
| 41 | + }); |
| 42 | + if (this.failedTasks.length === 0) { |
| 43 | + output.addVerticalSeparatorWithoutNewLines('green'); |
| 44 | + output.success({ |
| 45 | + title: `Successfully ran ${this.tasks.length} tasks:`, |
| 46 | + bodyLines: taskIds, |
| 47 | + }); |
| 48 | + } else { |
| 49 | + output.addVerticalSeparatorWithoutNewLines('red'); |
| 50 | + output.error({ |
| 51 | + title: `Ran ${this.tasks.length} tasks:`, |
| 52 | + bodyLines: taskIds, |
| 53 | + }); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + endTasks( |
| 58 | + taskResults: { task: Task; status: TaskStatus; code: number }[] |
| 59 | + ): void { |
| 60 | + for (let t of taskResults) { |
| 61 | + if (t.status === 'failure') { |
| 62 | + this.failedTasks.push(t.task); |
| 63 | + } else if (t.status === 'local-cache') { |
| 64 | + this.cachedTasks.push(t.task); |
| 65 | + } else if (t.status === 'local-cache-kept-existing') { |
| 66 | + this.cachedTasks.push(t.task); |
| 67 | + } else if (t.status === 'remote-cache') { |
| 68 | + this.cachedTasks.push(t.task); |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + printTaskTerminalOutput( |
| 74 | + task: Task, |
| 75 | + cacheStatus: TaskStatus, |
| 76 | + terminalOutput: string |
| 77 | + ) { |
| 78 | + const args = getPrintableCommandArgsForTask(task); |
| 79 | + output.logCommand(args.join(' '), cacheStatus); |
| 80 | + output.addNewline(); |
| 81 | + process.stdout.write(terminalOutput); |
| 82 | + } |
| 83 | +} |
0 commit comments