2019-12-24 15:40:03 +03:00
|
|
|
import chalk from 'chalk'
|
|
|
|
import ms from 'ms'
|
|
|
|
|
|
|
|
let prevTime: number
|
|
|
|
|
|
|
|
export default (banner: string, color: string = 'green') => {
|
|
|
|
return (msg?: string) => {
|
|
|
|
const curr = +new Date()
|
|
|
|
const diff = curr - (prevTime || curr)
|
|
|
|
|
|
|
|
prevTime = curr
|
|
|
|
|
|
|
|
if (msg) {
|
|
|
|
console.log(
|
|
|
|
// TODO: proper typings for color and banner
|
|
|
|
// @ts-ignore
|
2020-02-08 18:17:27 +03:00
|
|
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
2019-12-24 15:40:03 +03:00
|
|
|
` ${chalk[String(color)](String(banner))} ${msg} ${chalk.green(`+${ms(diff)}`)}`
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
console.log()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|