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

Commit 9d5edbe

Browse files
cnishinaheathkit
authored andcommitted
chore(node): require the minimum node version 4.2.x required by selenium-webdriver (#3534)
1 parent 70c6e70 commit 9d5edbe

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

gulpfile.js

+36-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var clangFormat = require('clang-format');
55
var gulpFormat = require('gulp-clang-format');
66
var runSequence = require('run-sequence');
77
var spawn = require('child_process').spawn;
8+
var spawnSync = require('child_process').spawnSync;
89
var fs = require('fs');
910
var path = require('path');
1011
var glob = require('glob');
@@ -32,6 +33,30 @@ var runSpawn = function(done, task, opt_arg, opt_io) {
3233
});
3334
};
3435

36+
// prevent contributors from using the wrong version of node
37+
gulp.task('checkVersion', function(done) {
38+
var version = spawnSync('node', ['--version']).stdout.toString();
39+
var versionArray = version.replace('v', '').split('.');
40+
var major = versionArray[0];
41+
var minor = versionArray[1];
42+
43+
// read minimum node on package.json
44+
var packageJson = JSON.parse(fs.readFileSync(path.resolve('package.json')));
45+
var protractorVersion = packageJson.version;
46+
var nodeVersion = packageJson.engines.node.replace('>=','');
47+
var nodeVersionArray = nodeVersion.split('.');
48+
var requiredMajor = nodeVersionArray[0];
49+
var requiredMinor = nodeVersionArray[1];
50+
51+
if (major >= requiredMajor && minor >= requiredMinor) {
52+
done();
53+
} else {
54+
console.error('minimum node version for Protractor ' + protractorVersion +
55+
' is node >= ' + nodeVersion);
56+
return 1;
57+
}
58+
});
59+
3560
gulp.task('built:copy', function() {
3661
return gulp.src(['lib/**/*','!lib/**/*.ts'])
3762
.pipe(gulp.dest('built/'));
@@ -47,16 +72,16 @@ gulp.task('jshint', function(done) {
4772
'spec/install/**/*.js']);
4873
});
4974

50-
gulp.task('format:enforce', () => {
51-
const format = require('gulp-clang-format');
52-
const clangFormat = require('clang-format');
75+
gulp.task('format:enforce', function() {
76+
var format = require('gulp-clang-format');
77+
var clangFormat = require('clang-format');
5378
return gulp.src(['lib/**/*.ts']).pipe(
5479
format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
5580
});
5681

57-
gulp.task('format', () => {
58-
const format = require('gulp-clang-format');
59-
const clangFormat = require('clang-format');
82+
gulp.task('format', function() {
83+
var format = require('gulp-clang-format');
84+
var clangFormat = require('clang-format');
6085
return gulp.src(['lib/**/*.ts'], { base: '.' }).pipe(
6186
format.format('file', clangFormat)).pipe(gulp.dest('.'));
6287
});
@@ -71,12 +96,12 @@ gulp.task('tsc:globals', function(done) {
7196
});
7297

7398
gulp.task('prepublish', function(done) {
74-
runSequence(['jshint', 'format'], 'tsc', 'tsc:globals', 'types',
99+
runSequence('checkVersion', ['jshint', 'format'], 'tsc', 'tsc:globals', 'types',
75100
'ambient', 'built:copy', done);
76101
});
77102

78103
gulp.task('pretest', function(done) {
79-
runSequence(
104+
runSequence('checkVersion',
80105
['webdriver:update', 'jshint', 'format'], 'tsc', 'tsc:globals',
81106
'types', 'ambient', 'built:copy', done);
82107
});
@@ -93,12 +118,12 @@ gulp.task('types', function(done) {
93118
contents += '/// <reference path="../../@types/jasmine/index.d.ts" />\n';
94119
contents += '/// <reference path="../typings/index.d.ts" />\n';
95120
contents += 'import {ActionSequence, By, WebDriver, WebElement, WebElementPromise, promise, promise as wdpromise, until} from \'selenium-webdriver\';\n';
96-
files.forEach(file => {
121+
files.forEach(function(file) {
97122
contents += parseTypingsFile(folder, file);
98123
});
99124

100125
// remove files with d.ts
101-
glob.sync(folder + '/**/*.d.ts').forEach(file => {
126+
glob.sync(folder + '/**/*.d.ts').forEach(function(file) {
102127
fs.unlinkSync(path.resolve(file));
103128
});
104129

@@ -111,7 +136,7 @@ var parseTypingsFile = function(folder, file) {
111136
var fileContents = fs.readFileSync(path.resolve(folder, file + '.d.ts')).toString();
112137
// Remove new lines inside types
113138
fileContents = fileContents.replace(
114-
/webdriver.promise.Promise<\{[a-zA-Z:,; \n]+\}>/g, (type) => {
139+
/webdriver.promise.Promise<\{[a-zA-Z:,; \n]+\}>/g, function(type) {
115140
return type.replace(/\n/g, '');
116141
}
117142
);

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,8 @@
6969
"tsc:w": "./node_modules/typescript/bin/tsc -w"
7070
},
7171
"license": "MIT",
72+
"engines": {
73+
"node": ">=4.2.x"
74+
},
7275
"version": "4.0.5"
7376
}

0 commit comments

Comments
 (0)