import path from 'path' ; import { colors , ColorType } from './utils/colors' ; interface Options { logLevel ? : number ; mock ? : boolean ; } export class Logger { options : Required < Options > ; lines : string [ ] ; constructor ( options ? ) { this . options = Object . assign ( { logLevel : 3 , mock : false , } , options ) ; this . lines = [ ] ; } setOptions ( options ) { Object . assign ( this . options , options ) ; } log ( ... args ) { if ( this . options . mock ) { this . lines . push ( args . join ( ' ' ) ) ; } else { console . log ( ... args ) ; } } debug ( ... args ) { if ( this . options . logLevel < 4 ) { return ; } this . status ( 'magenta' , 'debug' , ... args ) ; } warn ( ... args ) { if ( this . options . logLevel < 2 ) { return ; } this . log ( colors . yellow ( 'warning' ) , ... args ) ; } error ( ... args ) { if ( this . options . logLevel < 1 ) { return ; } process . exitCode = process . exitCode || 1 ; this . log ( colors . red ( 'error' ) , ... args ) ; } success ( ... args ) { this . status ( 'green' , 'success' , ... args ) ; } tip ( ... args ) { this . status ( 'blue' , 'tip' , ... args ) ; } info ( ... args ) { this . status ( 'cyan' , 'info' , ... args ) ; } status ( color , label , ... args ) { if ( this . options . logLevel < 3 ) { return ; } this . log ( colors [ color ] ( label ) , ... args ) ; } fileAction ( color , type , fp ) { if ( this . options . logLevel < 3 ) { return ; } this . info ( `${ colors [ color ] ( type ) } ${ colors . green ( path . relative ( process . cwd ( ) , fp ) ) }` ) ; } fileMoveAction ( from , to ) { if ( this . options . logLevel < 3 ) { return ; } this . info ( `${ colors . blue ( 'Moved' ) } ${ colors . green ( path . relative ( process . cwd ( ) , from ) ) } ${ colors . dim ( '->' ) } ${ colors . green ( path . relative ( process . cwd ( ) , to ) ) }` ) ; } } export const logger = new Logger ( ) ;