index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env node
  2. 'use strict'
  3. const checker = require('../lib/checkSystem.js')
  4. const colors = require('colors')
  5. // set color theme
  6. colors.setTheme({
  7. success: 'green',
  8. info: 'grey',
  9. warn: 'yellow',
  10. error: 'red',
  11. boldWarn: ['bold', 'yellow'],
  12. boldUnderlineSuccess: ['bold', 'underline', 'green'],
  13. boldUnderlineError: ['bold', 'underline', 'red']
  14. })
  15. console.log('Checking versions...'.info, '\n')
  16. checker(process.argv[2]).then((result) => {
  17. // check if the process should exit prematurely
  18. if (result.status != 0) {
  19. console.log(colors[result.message.type](result.message.text))
  20. process.exit(result.status)
  21. }
  22. // print out results for each package
  23. result.packages.forEach((p) => {
  24. if (p.type === 'success') {
  25. console.log(('✔ ' + colors.bold(p.name) + ' was validated with ' + p.expectedVersion + '.').success)
  26. } else if (p.type === 'warn') {
  27. console.log((colors.bold(p.name) + ' was expected, but no validator found!').warn)
  28. } else if (p.type === 'error' && p.commandError) {
  29. console.log(('✘ Error validating ' + colors.bold(p.name) + ': ' + p.commandError).error)
  30. } else if (p.type === 'error' && !p.commandError) {
  31. console.log((
  32. '✘ ' + colors.bold(p.name) +
  33. ' version is incorrect! Expected ' +
  34. p.expectedVersion + ' but was ' + p.foundVersion + '.'
  35. ).error)
  36. }
  37. })
  38. // print out a summary message
  39. if (result.message.type === 'success') {
  40. console.log('\n', result.message.text.boldUnderlineSuccess)
  41. } else {
  42. console.log('\n', result.message.text.boldUnderlineError)
  43. process.exit(1)
  44. }
  45. })