logger.js 839 B

123456789101112131415161718192021222324252627282930
  1. const { chalk } = require('@vue/cli-shared-utils')
  2. exports.log = (...args) => {
  3. if (!process.env.VUE_APP_CLI_UI_DEBUG) return
  4. const date = new Date()
  5. const timestamp = `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}.${date.getSeconds().toString().padStart(2, '0')}`
  6. const first = args.shift()
  7. console.log(`${chalk.blue('UI')} ${chalk.dim(timestamp)}`, chalk.bold(first), ...args)
  8. }
  9. const simpleTypes = [
  10. 'string',
  11. 'number',
  12. 'boolean'
  13. ]
  14. exports.dumpObject = (obj) => {
  15. if (!process.env.VUE_APP_CLI_UI_DEBUG) return
  16. const result = {}
  17. Object.keys(obj).forEach(key => {
  18. const value = obj[key]
  19. const type = typeof value
  20. if (simpleTypes.includes(type)) {
  21. result[key] = value
  22. } else {
  23. result[key] = type
  24. }
  25. })
  26. return result.toString()
  27. }