forked from angular/protractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
107 lines (92 loc) · 3.12 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
101
102
103
104
105
106
107
'use strict';
var gulp = require('gulp');
var clangFormat = require('clang-format');
var gulpFormat = require('gulp-clang-format');
var runSequence = require('run-sequence');
var spawn = require('child_process').spawn;
var spawnSync = require('child_process').spawnSync;
var tslint = require('gulp-tslint');
var fs = require('fs');
var path = require('path');
var glob = require('glob');
var semver = require('semver');
var runSpawn = function(done, task, opt_arg, opt_io) {
opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
var stdio = 'inherit';
if (opt_io === 'ignore') {
stdio = 'ignore';
}
var child = spawn(task, opt_arg, {stdio: stdio});
var running = false;
child.on('close', function() {
if (!running) {
running = true;
done();
}
});
child.on('error', function() {
if (!running) {
console.error('gulp encountered a child error');
running = true;
done();
}
});
};
gulp.task('tslint', function() {
return gulp.src(['lib/**/*.ts', 'spec/**/*.ts', '!spec/install/**/*.ts'])
.pipe(tslint()).pipe(tslint.report());
});
gulp.task('lint', function(done) {
runSequence('tslint', 'jshint', 'format:enforce', done);
});
// prevent contributors from using the wrong version of node
gulp.task('checkVersion', function(done) {
// read minimum node on package.json
var packageJson = JSON.parse(fs.readFileSync(path.resolve('package.json')));
var protractorVersion = packageJson.version;
var 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', function(done) {
return gulp.src(['lib/**/*.js','lib/index.d.ts'])
.pipe(gulp.dest('built/'));
done();
});
gulp.task('webdriver:update', function(done) {
runSpawn(done, 'node', ['bin/webdriver-manager', 'update']);
});
gulp.task('jshint', function(done) {
runSpawn(done, 'node', ['node_modules/jshint/bin/jshint', '-c',
'.jshintrc', 'lib', 'spec', 'scripts',
'--exclude=lib/selenium-webdriver/**/*.js,lib/webdriver-js-extender/**/*.js,' +
'spec/dependencyTest/*.js,spec/install/**/*.js']);
});
gulp.task('format:enforce', function() {
var format = require('gulp-clang-format');
var clangFormat = require('clang-format');
return gulp.src(['lib/**/*.ts']).pipe(
format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
});
gulp.task('format', function() {
var format = require('gulp-clang-format');
var clangFormat = require('clang-format');
return gulp.src(['lib/**/*.ts'], { base: '.' }).pipe(
format.format('file', clangFormat)).pipe(gulp.dest('.'));
});
gulp.task('tsc', function(done) {
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
});
gulp.task('prepublish', function(done) {
runSequence('checkVersion', 'jshint', 'tsc',
'built:copy', done);
});
gulp.task('pretest', function(done) {
runSequence('checkVersion',
['webdriver:update', 'jshint', 'tslint', 'format'], 'tsc', 'built:copy', done);
});
gulp.task('default',['prepublish']);