1 | 'use strict';
|
2 |
|
3 | var gulp = require('gulp');
|
4 | var clangFormat = require('clang-format');
|
5 | var gulpFormat = require('gulp-clang-format');
|
6 | var runSequence = require('run-sequence');
|
7 | var spawn = require('child_process').spawn;
|
8 | var spawnSync = require('child_process').spawnSync;
|
9 | var tslint = require('gulp-tslint');
|
10 | var fs = require('fs');
|
11 | var path = require('path');
|
12 | var glob = require('glob');
|
13 | var semver = require('semver');
|
14 |
|
15 | var runSpawn = function(done, task, opt_arg, opt_io) {
|
16 | opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
|
17 | var stdio = 'inherit';
|
18 | if (opt_io === 'ignore') {
|
19 | stdio = 'ignore';
|
20 | }
|
21 | var child = spawn(task, opt_arg, {stdio: stdio});
|
22 | var running = false;
|
23 | child.on('close', function() {
|
24 | if (!running) {
|
25 | running = true;
|
26 | done();
|
27 | }
|
28 | });
|
29 | child.on('error', function() {
|
30 | if (!running) {
|
31 | console.error('gulp encountered a child error');
|
32 | running = true;
|
33 | done();
|
34 | }
|
35 | });
|
36 | };
|
37 |
|
38 | gulp.task('tslint', function() {
|
39 | return gulp.src(['lib/**/*.ts', 'spec/**/*.ts', '!spec/install/**/*.ts'])
|
40 | .pipe(tslint()).pipe(tslint.report());
|
41 | });
|
42 |
|
43 | gulp.task('lint', function(done) {
|
44 | runSequence('tslint', 'jshint', 'format:enforce', done);
|
45 | });
|
46 |
|
47 |
|
48 | gulp.task('checkVersion', function(done) {
|
49 |
|
50 | var packageJson = JSON.parse(fs.readFileSync(path.resolve('package.json')));
|
51 | var protractorVersion = packageJson.version;
|
52 | var nodeVersion = packageJson.engines.node;
|
53 |
|
54 | if (semver.satisfies(process.version, nodeVersion)) {
|
55 | done();
|
56 | } else {
|
57 | throw new Error('minimum node version for Protractor ' +
|
58 | protractorVersion + ' is node ' + nodeVersion);
|
59 | }
|
60 | });
|
61 |
|
62 | gulp.task('built:copy', function(done) {
|
63 | return gulp.src(['lib/**/*.js'])
|
64 | .pipe(gulp.dest('built/'));
|
65 | done();
|
66 | });
|
67 |
|
68 | gulp.task('webdriver:update', function(done) {
|
69 | runSpawn(done, 'node', ['bin/webdriver-manager', 'update']);
|
70 | });
|
71 |
|
72 | gulp.task('jshint', function(done) {
|
73 | runSpawn(done, 'node', ['node_modules/jshint/bin/jshint', '-c',
|
74 | '.jshintrc', 'lib', 'spec', 'scripts',
|
75 | '--exclude=lib/selenium-webdriver/**/*.js,lib/webdriver-js-extender/**/*.js,' +
|
76 | 'spec/dependencyTest/*.js,spec/install/**/*.js']);
|
77 | });
|
78 |
|
79 | gulp.task('format:enforce', function() {
|
80 | var format = require('gulp-clang-format');
|
81 | var clangFormat = require('clang-format');
|
82 | return gulp.src(['lib/**/*.ts']).pipe(
|
83 | format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
|
84 | });
|
85 |
|
86 | gulp.task('format', function() {
|
87 | var format = require('gulp-clang-format');
|
88 | var clangFormat = require('clang-format');
|
89 | return gulp.src(['lib/**/*.ts'], { base: '.' }).pipe(
|
90 | format.format('file', clangFormat)).pipe(gulp.dest('.'));
|
91 | });
|
92 |
|
93 | gulp.task('tsc', function(done) {
|
94 | runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
|
95 | });
|
96 |
|
97 | gulp.task('tsc:spec', function(done) {
|
98 | runSpawn(done, 'node', ['node_modules/typescript/bin/tsc', '-p', 'ts_spec_config.json']);
|
99 | });
|
100 |
|
101 | gulp.task('tsc:es5', function(done) {
|
102 | runSpawn(done, './scripts/compile_to_es5.sh');
|
103 | });
|
104 |
|
105 | gulp.task('compile_to_es5', function(done) {
|
106 | runSequence('checkVersion', 'tsc:es5', 'built:copy', done);
|
107 | });
|
108 |
|
109 | gulp.task('prepublish', function(done) {
|
110 | runSequence('checkVersion', 'jshint', 'tsc', 'built:copy', done);
|
111 | });
|
112 |
|
113 | gulp.task('pretest', function(done) {
|
114 | runSequence('checkVersion',
|
115 | ['webdriver:update', 'jshint', 'tslint', 'format'], 'tsc', 'built:copy', 'tsc:spec', done);
|
116 | });
|
117 |
|
118 | gulp.task('default',['prepublish']);
|