Guest User

Untitled

a guest
May 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. const semver = require('semver');
  2. const chalk = require('chalk');
  3. const packageConfig = require('./package.json');
  4. const exec = function (cmd) {
  5. return require('child_process')
  6. .execSync(cmd).toString().trim();
  7. };
  8.  
  9. const versionRequirements = [
  10. {
  11. name: 'node',
  12. currentVersion: semver.clean(process.version),
  13. versionRequirement: packageConfig.engines.node
  14. },
  15. {
  16. name: 'npm',
  17. currentVersion: exec('npm --version'),
  18. versionRequirement: packageConfig.engines.npm
  19. }
  20. ];
  21.  
  22. const warnings = [];
  23. for (var i = 0; i < versionRequirements.length; i++) {
  24. const mod = versionRequirements[i];
  25. if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
  26. warnings.push(`${mod.name}: ${
  27. chalk.red(mod.currentVersion)} should be ${
  28. chalk.green(mod.versionRequirement)}`
  29. );
  30. }
  31. }
  32.  
  33. if (warnings.length) {
  34. console.log(chalk.white.bgRed.bold('******************************************************************'));
  35. console.log(chalk.white.bgRed.bold('To use this template, you must update the following modules: '));
  36. console.log();
  37. for (var i = 0; i < warnings.length; i++) {
  38. const warning = warnings[i];
  39. console.log(` ${warning}`);
  40. }
  41. console.log(chalk.white.bgRed.bold('******************************************************************'));
  42. console.log();
  43. process.exit(1);
  44. }
  45. else {
  46. console.log('');
  47. console.log(chalk.green('NPM and Node versions are all good!'));
  48. console.log();
  49. }
Add Comment
Please, Sign In to add comment