Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const semver = require('semver');
- const chalk = require('chalk');
- const packageConfig = require('./package.json');
- const exec = function (cmd) {
- return require('child_process')
- .execSync(cmd).toString().trim();
- };
- const versionRequirements = [
- {
- name: 'node',
- currentVersion: semver.clean(process.version),
- versionRequirement: packageConfig.engines.node
- },
- {
- name: 'npm',
- currentVersion: exec('npm --version'),
- versionRequirement: packageConfig.engines.npm
- }
- ];
- const warnings = [];
- for (var i = 0; i < versionRequirements.length; i++) {
- const mod = versionRequirements[i];
- if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
- warnings.push(`${mod.name}: ${
- chalk.red(mod.currentVersion)} should be ${
- chalk.green(mod.versionRequirement)}`
- );
- }
- }
- if (warnings.length) {
- console.log(chalk.white.bgRed.bold('******************************************************************'));
- console.log(chalk.white.bgRed.bold('To use this template, you must update the following modules: '));
- console.log();
- for (var i = 0; i < warnings.length; i++) {
- const warning = warnings[i];
- console.log(` ${warning}`);
- }
- console.log(chalk.white.bgRed.bold('******************************************************************'));
- console.log();
- process.exit(1);
- }
- else {
- console.log('');
- console.log(chalk.green('NPM and Node versions are all good!'));
- console.log();
- }
Add Comment
Please, Sign In to add comment