UNPKG

2.82 kBJavaScriptView Raw
1'use strict';
2
3const gulp = require('gulp');
4const format = require('gulp-clang-format');
5const clangFormat = require('clang-format');
6const spawn = require('child_process').spawn;
7const tslint = require('gulp-tslint');
8const fs = require('fs');
9const path = require('path');
10const semver = require('semver');
11
12const runSpawn = (done, task, opt_arg, opt_io) => {
13 opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
14 const stdio = 'inherit';
15 if (opt_io === 'ignore') {
16 stdio = 'ignore';
17 }
18 const child = spawn(task, opt_arg, {stdio: stdio});
19 let running = false;
20 child.on('close', () => {
21 if (!running) {
22 running = true;
23 done();
24 }
25 });
26 child.on('error', () => {
27 if (!running) {
28 console.error('gulp encountered a child error');
29 running = true;
30 done();
31 }
32 });
33};
34
35gulp.task('tslint', () => {
36 return gulp.src(['lib/**/*.ts', 'spec/**/*.ts', '!spec/install/**/*.ts'])
37 .pipe(tslint())
38 .pipe(tslint.report());
39});
40
41gulp.task('format:enforce', () => {
42 return gulp.src(['lib/**/*.ts'])
43 .pipe(format.checkFormat('file', clangFormat,
44 {verbose: true, fail: true}));
45});
46
47gulp.task('lint', gulp.series('tslint', 'format:enforce'));
48
49// prevent contributors from using the wrong version of node
50gulp.task('checkVersion', (done) => {
51 // read minimum node on package.json
52 const packageJson = JSON.parse(fs.readFileSync(path.resolve('package.json')));
53 const protractorVersion = packageJson.version;
54 const nodeVersion = packageJson.engines.node;
55
56 if (semver.satisfies(process.version, nodeVersion)) {
57 done();
58 } else {
59 throw new Error('minimum node version for Protractor ' +
60 protractorVersion + ' is node ' + nodeVersion);
61 }
62});
63
64gulp.task('built:copy', () => {
65 return gulp.src(['lib/**/*.js'])
66 .pipe(gulp.dest('built/'));
67});
68
69gulp.task('built:copy:typings', () => {
70 return gulp.src(['lib/selenium-webdriver/**/*.d.ts'])
71 .pipe(gulp.dest('built/selenium-webdriver/'));
72});
73
74gulp.task('webdriver:update', (done) => {
75 runSpawn(done, 'node', ['bin/webdriver-manager', 'update',
76 '--versions.chrome=2.44']);
77});
78
79gulp.task('format', () => {
80 return gulp.src(['lib/**/*.ts'], { base: '.' })
81 .pipe(format.format('file', clangFormat))
82 .pipe(gulp.dest('.'));
83});
84
85gulp.task('tsc', (done) => {
86 runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
87});
88
89gulp.task('tsc:spec', (done) => {
90 runSpawn(done, 'node', ['node_modules/typescript/bin/tsc', '-p', 'ts_spec_config.json']);
91});
92
93gulp.task('prepublish', gulp.series('checkVersion', 'tsc', 'built:copy'));
94
95gulp.task('pretest', gulp.series(
96 'checkVersion',
97 gulp.parallel('webdriver:update', 'tslint', 'format'),
98 'tsc', 'built:copy', 'built:copy:typings', 'tsc:spec'));
99
100gulp.task('default', gulp.series('prepublish'));
101