print.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * @Description:
  3. * @Author: zcf
  4. * @Date: 2021-12-14 18:03:17
  5. * @LastEditTime: 2021-12-15 17:53:20
  6. * @LastEditors: zcf
  7. */
  8. const CFonts = require('cfonts')
  9. const chalk = require('chalk')
  10. const semver = require('semver')
  11. /**
  12. * @description 打印LOGO
  13. * @author zcf
  14. * @date 2021-12-14 18:10:27
  15. */
  16. const printLoGo = (logo) => {
  17. CFonts.say(logo, {
  18. font: 'simple3d',
  19. align: 'left',
  20. background: 'transparent',
  21. letterSpacing: 1,
  22. lineHeight: 1,
  23. space: true,
  24. maxLength: 0,
  25. gradient: ['blue', 'magenta'],
  26. independentGradient: false,
  27. transitionGradient: false,
  28. env: 'node'
  29. })
  30. }
  31. /**
  32. * @description node版本是否满足最低要求
  33. * @author zcf
  34. * @date 2021-12-15 15:54:50
  35. */
  36. const printNodeVersionWarn = (version, safeVersion) => {
  37. // node环境是否满足最低要求
  38. const nodeVersionIsSatisfy = semver.gte(version, safeVersion)
  39. if (!nodeVersionIsSatisfy) {
  40. console.warn(`
  41. \n${chalk.bold.red('❌ 当前node版本过低,请升级node版本,node版本应 >= v14.0.0')}
  42. `)
  43. process.exit(1)
  44. }
  45. }
  46. /**
  47. * @description 包管理器是否是pnpm
  48. * @author zcf
  49. * @date 2021-12-15 15:59:46
  50. */
  51. const printPnpmWarn = () => {
  52. if (!/pnpm/.test(process.env.npm_execpath || '')) {
  53. console.warn(`
  54. \n${chalk.bold.yellow('❌ 当前vue3.x 项目需要使用pnpm作为包管理器脚本才能正常工作,请执行')}
  55. \n${chalk.bold.cyan('🍀 npm install -g pnpm')}
  56. \n${chalk.bold.cyan('🍀 pnpm install')}
  57. \n${chalk.bold.cyan('🍀 pnpm run serve')}\n
  58. `)
  59. process.exit(1)
  60. }
  61. }
  62. module.exports = {
  63. printLoGo,
  64. printNodeVersionWarn,
  65. printPnpmWarn
  66. }