gulpfile.js
3.04 KB
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
108
109
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
require('source-map-support').install();
var clangFormat = require('clang-format');
var formatter = require('gulp-clang-format');
var fs = require('fs');
var gulp = require('gulp');
var gutil = require('gulp-util');
var merge = require('merge2');
var mocha = require('gulp-mocha');
var sourcemaps = require('gulp-sourcemaps');
var ts = require('gulp-typescript');
var tslint = require('gulp-tslint');
var typescript = require('typescript');
var tsProject = ts.createProject('tsconfig.json', {
// Specify the TypeScript version we're using.
typescript: typescript,
});
const formatted = ['*.js', 'src/**/*.ts', 'test/**/*.ts'];
gulp.task('format', function() {
return gulp.src(formatted, {base: '.'})
.pipe(formatter.format('file', clangFormat))
.pipe(gulp.dest('.'));
});
gulp.task('test.check-format', function() {
return gulp.src(formatted)
.pipe(formatter.checkFormat('file', clangFormat, {verbose: true}))
.on('warning', onError);
});
gulp.task('test.check-lint', function() {
return gulp.src(['src/**/*.ts', 'test/**/*.ts'])
.pipe(tslint({formatter: 'verbose'}))
.pipe(tslint.report())
.on('warning', onError);
});
var hasError;
var failOnError = true;
var onError = function(err) {
hasError = true;
if (failOnError) {
process.exit(1);
}
};
gulp.task('compile', function() {
hasError = false;
var tsResult =
gulp.src(['src/**/*.ts']).pipe(sourcemaps.init()).pipe(tsProject()).on('error', onError);
return merge([
tsResult.dts.pipe(gulp.dest('build/definitions')),
// Write external sourcemap next to the js file
tsResult.js.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: '../../src'}))
.pipe(gulp.dest('build/src')),
tsResult.js.pipe(gulp.dest('build/src')),
]);
});
gulp.task('test.compile', ['compile'], function(done) {
if (hasError) {
done();
return;
}
return gulp.src(['test/*.ts'], {base: '.'})
.pipe(sourcemaps.init())
.pipe(tsProject())
.on('error', onError)
.js.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: '../..'}))
.pipe(gulp.dest('build/')); // '/test/' comes from base above.
});
gulp.task('test.unit', ['test.compile'], function(done) {
if (hasError) {
done();
return;
}
return gulp.src(['build/test/**/*.js', '!build/test/**/e2e*.js']).pipe(mocha({timeout: 1000}));
});
gulp.task('test.e2e', ['test.compile'], function(done) {
if (hasError) {
done();
return;
}
return gulp.src(['build/test/**/e2e*.js']).pipe(mocha({timeout: 25000}));
});
gulp.task('test', ['test.unit', 'test.e2e', 'test.check-format', 'test.check-lint']);
gulp.task('watch', function() {
failOnError = false;
gulp.start(['test.unit']); // Trigger initial build.
return gulp.watch(['src/**/*.ts', 'test/**/*.ts', 'test_files/**'], ['test.unit']);
});
gulp.task('default', ['compile']);