log.ts 587 B

1234567891011121314151617181920212223
  1. import chalk from 'chalk'
  2. const timeFormat = new Intl.DateTimeFormat('en', {
  3. timeStyle: 'medium',
  4. })
  5. export function pkgLog(pkgName: string, message: string) {
  6. log(message, chalk.green(pkgName.replace(/^@[^/]*\//, '')))
  7. }
  8. export function log(message: string, label?: string) {
  9. const now = Date.now()
  10. const nowStr = timeFormat.format(now)
  11. const prefix = `[${chalk.grey(nowStr)}]`
  12. const subprefix = label ? `${label}: ` : ''
  13. const lines = message.trimEnd().split('\n')
  14. for (const line of lines) {
  15. console.log(`${prefix} ${subprefix}${line}`)
  16. }
  17. console.log()
  18. }