diff --git a/gulpfile.js b/gulpfile.js index d08694a24..49c3956a8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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 : []; @@ -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); } }); diff --git a/package.json b/package.json index 4cfa3d955..765485aba 100644 --- a/package.json +++ b/package.json @@ -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": {