-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
101 lines (84 loc) · 2.76 KB
/
gulpfile.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
const gulp = require('gulp');
const format = require('gulp-clang-format');
const clangFormat = require('clang-format');
const spawn = require('child_process').spawn;
const tslint = require('gulp-tslint');
const fs = require('fs');
const path = require('path');
const semver = require('semver');
const runSpawn = (done, task, opt_arg, opt_io) => {
opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
const stdio = 'inherit';
if (opt_io === 'ignore') {
stdio = 'ignore';
}
const child = spawn(task, opt_arg, {stdio: stdio});
let running = false;
child.on('close', () => {
if (!running) {
running = true;
done();
}
});
child.on('error', () => {
if (!running) {
console.error('gulp encountered a child error');
running = true;
done();
}
});
};
gulp.task('tslint', () => {
return gulp.src(['lib/**/*.ts', 'spec/**/*.ts', '!spec/install/**/*.ts'])
.pipe(tslint())
.pipe(tslint.report());
});
gulp.task('format:enforce', () => {
return gulp.src(['lib/**/*.ts'])
.pipe(format.checkFormat('file', clangFormat,
{verbose: true, fail: true}));
});
gulp.task('lint', gulp.series('tslint', 'format:enforce'));
// prevent contributors from using the wrong version of node
gulp.task('checkVersion', (done) => {
// read minimum node on package.json
const packageJson = JSON.parse(fs.readFileSync(path.resolve('package.json')));
const protractorVersion = packageJson.version;
const nodeVersion = packageJson.engines.node;
if (semver.satisfies(process.version, nodeVersion)) {
done();
} else {
throw new Error('minimum node version for Protractor ' +
protractorVersion + ' is node ' + nodeVersion);
}
});
gulp.task('built:copy', () => {
return gulp.src(['lib/**/*.js'])
.pipe(gulp.dest('built/'));
});
gulp.task('built:copy:typings', () => {
return gulp.src(['lib/selenium-webdriver/**/*.d.ts'])
.pipe(gulp.dest('built/selenium-webdriver/'));
});
gulp.task('webdriver:update', (done) => {
runSpawn(done, 'node', ['bin/webdriver-manager', 'update',
'--versions.chrome=2.44']);
});
gulp.task('format', () => {
return gulp.src(['lib/**/*.ts'], { base: '.' })
.pipe(format.format('file', clangFormat))
.pipe(gulp.dest('.'));
});
gulp.task('tsc', (done) => {
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
});
gulp.task('tsc:spec', (done) => {
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc', '-p', 'ts_spec_config.json']);
});
gulp.task('prepublish', gulp.series('checkVersion', 'tsc', 'built:copy'));
gulp.task('pretest', gulp.series(
'checkVersion',
gulp.parallel('webdriver:update', 'tslint', 'format'),
'tsc', 'built:copy', 'built:copy:typings', 'tsc:spec'));
gulp.task('default', gulp.series('prepublish'));