1 | 'use strict';
|
2 |
|
3 | const gulp = require('gulp');
|
4 | const format = require('gulp-clang-format');
|
5 | const clangFormat = require('clang-format');
|
6 | const spawn = require('child_process').spawn;
|
7 | const tslint = require('gulp-tslint');
|
8 | const fs = require('fs');
|
9 | const path = require('path');
|
10 | const semver = require('semver');
|
11 |
|
12 | const 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 |
|
35 | gulp.task('tslint', () => {
|
36 | return gulp.src(['lib/**/*.ts', 'spec/**/*.ts', '!spec/install/**/*.ts'])
|
37 | .pipe(tslint())
|
38 | .pipe(tslint.report());
|
39 | });
|
40 |
|
41 | gulp.task('format:enforce', () => {
|
42 | return gulp.src(['lib/**/*.ts'])
|
43 | .pipe(format.checkFormat('file', clangFormat,
|
44 | {verbose: true, fail: true}));
|
45 | });
|
46 |
|
47 | gulp.task('lint', gulp.series('tslint', 'format:enforce'));
|
48 |
|
49 |
|
50 | gulp.task('checkVersion', (done) => {
|
51 |
|
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 |
|
64 | gulp.task('built:copy', () => {
|
65 | return gulp.src(['lib/**/*.js'])
|
66 | .pipe(gulp.dest('built/'));
|
67 | });
|
68 |
|
69 | gulp.task('built:copy:typings', () => {
|
70 | return gulp.src(['lib/selenium-webdriver/**/*.d.ts'])
|
71 | .pipe(gulp.dest('built/selenium-webdriver/'));
|
72 | });
|
73 |
|
74 | gulp.task('webdriver:update', (done) => {
|
75 | runSpawn(done, 'node', ['bin/webdriver-manager', 'update',
|
76 | '--versions.chrome=2.44']);
|
77 | });
|
78 |
|
79 | gulp.task('format', () => {
|
80 | return gulp.src(['lib/**/*.ts'], { base: '.' })
|
81 | .pipe(format.format('file', clangFormat))
|
82 | .pipe(gulp.dest('.'));
|
83 | });
|
84 |
|
85 | gulp.task('tsc', (done) => {
|
86 | runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
|
87 | });
|
88 |
|
89 | gulp.task('tsc:spec', (done) => {
|
90 | runSpawn(done, 'node', ['node_modules/typescript/bin/tsc', '-p', 'ts_spec_config.json']);
|
91 | });
|
92 |
|
93 | gulp.task('prepublish', gulp.series('checkVersion', 'tsc', 'built:copy'));
|
94 |
|
95 | gulp.task('pretest', gulp.series(
|
96 | 'checkVersion',
|
97 | gulp.parallel('webdriver:update', 'tslint', 'format'),
|
98 | 'tsc', 'built:copy', 'built:copy:typings', 'tsc:spec'));
|
99 |
|
100 | gulp.task('default', gulp.series('prepublish'));
|