logger.ts 739 B

123456789101112131415161718192021222324252627
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. import chalk from 'chalk'
  5. import ms from 'ms'
  6. let prevTime: number
  7. export default (banner: string, color: chalk.Chalk = chalk.green) => {
  8. return (msg?: string) => {
  9. const curr = +new Date()
  10. const diff = curr - (prevTime || curr)
  11. prevTime = curr
  12. if (msg) {
  13. console.log(
  14. // TODO: proper typings for color and banner
  15. // eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-call
  16. ` ${color(String(banner))} ${msg} ${chalk.green(`+${ms(diff)}`)}`
  17. )
  18. } else {
  19. console.log()
  20. }
  21. }
  22. }