aboutsummaryrefslogtreecommitdiff
path: root/tools/tasks/check.versions.ts
blob: 211d5edca826d5c75f67ce580b08c201660b8eba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {VERSION_NPM, VERSION_NODE} from '../config';

function reportError(message: string) {
  console.error(require('chalk').white.bgRed.bold(message));
  process.exit(1);
}

module.exports = function check(gulp, plugins) {
  return function () {
    let exec = require('child_process').exec;
    let semver = require('semver');

    exec('npm --version',
      function (error, stdout, stderr) {
        if (error !== null) {
          reportError('npm preinstall error: ' + error + stderr);
        }

        if (!semver.gte(stdout, VERSION_NPM)) {
          reportError('NPM is not in required version! Required is ' + VERSION_NPM + ' and you\'re using ' + stdout);
        }
      });

    exec('node --version',
      function (error, stdout, stderr) {
        if (error !== null) {
          reportError('npm preinstall error: ' + error + stderr);
        }

        if (!semver.gte(stdout, VERSION_NODE)) {
          reportError('NODE is not in required version! Required is ' + VERSION_NODE + ' and you\'re using ' + stdout);
        }
      });
  };
};