跳板机管理web端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

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