import * as chalk from 'chalk' ; export declare type DiagnosticHandlingStrategy = 'error' | 'warning' | 'ignore' ; /**
 * This class is used to collect and then report warnings and errors that occur during the execution
 * of the tools.
 */ export class Diagnostics { readonly messages = [ ] ; get hasErrors ( ) { return this . messages . some ( ( m ) => m . type === 'error' ) ; } add ( type , message ) { if ( type !== 'ignore' ) { this . messages . push ( { type , message } ) ; } } merge ( other ) { this . messages . push ( ... other . messages ) ; } log ( message ) { this . messages . push ( { type : '' , message } ) ; } warn ( message ) { this . messages . push ( { type : 'warning' , message } ) ; } error ( message ) { this . messages . push ( { type : 'error' , message } ) ; } formatDiagnostics ( message ) { const errors = this . messages ! . filter ( ( d ) => d . type === 'error' ) . map ( ( d ) => ' - ' + d . message ) ; const warnings = this . messages ! . filter ( ( d ) => d . type === 'warning' ) . map ( ( d ) => ' - ' + d . message ) ; if ( errors . length ) { message += '\nERRORS:\n' + errors . join ( '\n' ) ; } if ( warnings . length ) { message += '\nWARNINGS:\n' + warnings . join ( '\n' ) ; } return message ; } logMessages ( ) { while ( this . messages . length ) { const m = this . messages . shift ( ) ; switch ( m . type ) { case 'warning' : console . warn ( chalk . yellow ( `Warning: ${ m . message }` ) ) ; break ; case 'error' : console . error ( chalk . red ( `Error: ${ m . message }` ) ) ; break ; default : console . log ( chalk . blue ( `${ m . message }` ) ) ; } } } }