Geen omschrijving

check-versions.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var chalk = require('chalk')
  2. var semver = require('semver')
  3. var packageConfig = require('../package.json')
  4. var shell = require('shelljs')
  5. function exec (cmd) {
  6. return require('child_process').execSync(cmd).toString().trim()
  7. }
  8. var versionRequirements = [
  9. {
  10. name: 'node',
  11. currentVersion: semver.clean(process.version),
  12. versionRequirement: packageConfig.engines.node
  13. },
  14. ]
  15. if (shell.which('npm')) {
  16. versionRequirements.push({
  17. name: 'npm',
  18. currentVersion: exec('npm --version'),
  19. versionRequirement: packageConfig.engines.npm
  20. })
  21. }
  22. module.exports = function () {
  23. var warnings = []
  24. for (var i = 0; i < versionRequirements.length; i++) {
  25. var mod = versionRequirements[i]
  26. if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
  27. warnings.push(mod.name + ': ' +
  28. chalk.red(mod.currentVersion) + ' should be ' +
  29. chalk.green(mod.versionRequirement)
  30. )
  31. }
  32. }
  33. if (warnings.length) {
  34. console.log('')
  35. console.log(chalk.yellow('To use this template, you must update following to modules:'))
  36. console.log()
  37. for (var i = 0; i < warnings.length; i++) {
  38. var warning = warnings[i]
  39. console.log(' ' + warning)
  40. }
  41. console.log()
  42. process.exit(1)
  43. }
  44. }