Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
chore(build): fix version check in gulpfile (#3543)
Browse files Browse the repository at this point in the history
Previously, the version check would say that 5.2 was less than 4.3.
Fix by using semver.
  • Loading branch information
juliemr authored and cnishina committed Sep 13, 2016
1 parent ef280cb commit 9be4b75
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
18 changes: 5 additions & 13 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var spawnSync = require('child_process').spawnSync;
var fs = require('fs');
var path = require('path');
var glob = require('glob');
var semver = require('semver');

var runSpawn = function(done, task, opt_arg, opt_io) {
opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
Expand All @@ -35,25 +36,16 @@ var runSpawn = function(done, task, opt_arg, opt_io) {

// prevent contributors from using the wrong version of node
gulp.task('checkVersion', function(done) {
var version = spawnSync('node', ['--version']).stdout.toString();
var versionArray = version.replace('v', '').split('.');
var major = versionArray[0];
var minor = versionArray[1];

// read minimum node on package.json
var packageJson = JSON.parse(fs.readFileSync(path.resolve('package.json')));
var protractorVersion = packageJson.version;
var nodeVersion = packageJson.engines.node.replace('>=','');
var nodeVersionArray = nodeVersion.split('.');
var requiredMajor = nodeVersionArray[0];
var requiredMinor = nodeVersionArray[1];
var nodeVersion = packageJson.engines.node;

if (major >= requiredMajor && minor >= requiredMinor) {
if (semver.satisfies(process.version, nodeVersion)) {
done();
} else {
console.error('minimum node version for Protractor ' + protractorVersion +
' is node >= ' + nodeVersion);
return 1;
throw new Error('minimum node version for Protractor ' + protractorVersion +
' is node ' + nodeVersion);
}
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"mocha": "2.5.3",
"rimraf": "~2.5.3",
"run-sequence": "^1.1.5",
"semver": "^5.3.0",
"typescript": "^2.0.0"
},
"repository": {
Expand Down

0 comments on commit 9be4b75

Please sign in to comment.