UNPKG

3.18 kBJavaScriptView Raw
1'use strict';
2
3var gulp = require('gulp');
4var clangFormat = require('clang-format');
5var gulpFormat = require('gulp-clang-format');
6var runSequence = require('run-sequence');
7var spawn = require('child_process').spawn;
8var spawnSync = require('child_process').spawnSync;
9var tslint = require('gulp-tslint');
10var fs = require('fs');
11var path = require('path');
12var glob = require('glob');
13var semver = require('semver');
14
15var 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
38gulp.task('tslint', function() {
39 return gulp.src(['lib/**/*.ts', 'spec/**/*.ts', '!spec/install/**/*.ts'])
40 .pipe(tslint()).pipe(tslint.report());
41});
42
43gulp.task('lint', function(done) {
44 runSequence('tslint', 'jshint', 'format:enforce', done);
45});
46
47// prevent contributors from using the wrong version of node
48gulp.task('checkVersion', function(done) {
49 // read minimum node on package.json
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
62gulp.task('built:copy', function(done) {
63 return gulp.src(['lib/**/*.js'])
64 .pipe(gulp.dest('built/'));
65 done();
66});
67
68gulp.task('webdriver:update', function(done) {
69 runSpawn(done, 'node', ['bin/webdriver-manager', 'update']);
70});
71
72gulp.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
79gulp.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
86gulp.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
93gulp.task('tsc', function(done) {
94 runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
95});
96
97
98gulp.task('prepublish', function(done) {
99 runSequence('checkVersion', 'jshint', 'tsc', 'built:copy', done);
100});
101
102gulp.task('pretest', function(done) {
103 runSequence('checkVersion',
104 ['webdriver:update', 'jshint', 'tslint', 'format'], 'tsc', 'built:copy', done);
105});
106
107gulp.task('default',['prepublish']);