import chalk = require ( 'chalk' ) ; import * as upath from 'upath' ; import * as fse from 'fs-extra' ; import { prettyBytes } from './PrettyUnits' ; param x function padZeroToDoubleDigits ( x ) { let s = '' ; if ( x < 10 ) { s += '0' ; } s += x ; return s ; } /**
 * Returns the current time, formatted to HHMMSS string.
 */ function nowFormatted ( ) { const t = new Date ( ) ; return padZeroToDoubleDigits ( t . getHours ( ) ) + ':' + padZeroToDoubleDigits ( t . getMinutes ( ) ) + ':' + padZeroToDoubleDigits ( t . getSeconds ( ) ) ; } function concatenateTokens ( tokens ) { let message = '' ; for ( const token of tokens ) { if ( token instanceof Error ) { if ( token . stack ) { message += '\n' + chalk . redBright ( token . stack ) ; } else { message += '\n' + chalk . redBright ( token . toString ( ) ) ; } } else { message += ' ' + token ; } } return message ; } export const Shout = { timed : function ( ... tokens ) : void { const message = concatenateTokens ( tokens ) ; const output = `[${ chalk . grey ( nowFormatted ( ) ) }]` + message ; console . log ( output ) ; } , error : function ( ... tokens ) : void { const message = concatenateTokens ( tokens ) ; const output = '\n' + chalk . redBright ( 'ERROR' ) + message + '\n' ; console . error ( output ) ; } , fatal : function ( ... tokens ) : void { const message = concatenateTokens ( tokens ) ; const output = '\n' + chalk . redBright ( 'FATAL ERROR' ) + message + '\n' ; console . error ( output ) ; } , warning : function ( ... tokens ) : void { const message = concatenateTokens ( tokens ) ; const output = chalk . yellowBright ( 'WARNING' ) + message ; console . warn ( output ) ; } , typescript : function ( ... tokens ) : void { const message = concatenateTokens ( tokens ) ; const output = chalk . blueBright ( 'TypeScript' ) + message ; console . log ( output ) ; } , sass : function ( ... tokens ) : void { const message = concatenateTokens ( tokens ) ; const output = chalk . magentaBright ( 'Sass' ) + message ; console . log ( output ) ; } , param filePath param content fileOutput ( filePath , content ) { const bundle = Buffer . from ( content , 'utf8' ) ; const info = upath . parse ( filePath ) ; const size = prettyBytes ( bundle . byteLength ) ; Shout . timed ( chalk . blueBright ( info . base ) , chalk . magentaBright ( size ) , chalk . grey ( 'in ' + info . dir + '/' ) ) ; return fse . outputFile ( filePath , bundle ) ; } } ;