This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
gulpfile.js
90 lines (78 loc) · 2.64 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
require('source-map-support').install();
var clangFormat = require('clang-format');
var formatter = require('gulp-clang-format');
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 typescript = require('typescript');
var tslint = require('gulp-tslint');
function checkFormat() {
return gulp.src(['*.js', 'lib/**/*.ts', 'test/**/*.ts'])
.pipe(formatter.checkFormat('file', clangFormat))
.on('warning', onError);
}
exports['test.check-format'] = checkFormat;
function checkLint() {
return gulp.src(['lib/**/*.ts', 'test/**/*.ts'])
.pipe(tslint({formatter: 'verbose'}))
.pipe(tslint.report())
.on('warning', onError);
}
exports['test.check-lint'] = checkLint;
var hasError;
var failOnError = true;
var onError = function(err) {
hasError = true;
gutil.log(err.message);
if (failOnError) {
process.exit(1);
}
};
var tsProject =
ts.createProject('tsconfig.json', {noEmit: false, declaration: true, typescript: typescript});
gulp.task('compile', () => {
hasError = false;
var tsResult = gulp.src(['lib/**/*.ts', 'node_modules/typescript/lib/typescript.d.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('.')).pipe(gulp.dest('build/lib')),
tsResult.js.pipe(gulp.dest('build/lib')),
]);
});
gulp.task('test.compile', gulp.series('compile', function(done) {
if (hasError) {
done();
return;
}
return gulp.src(['test/**/*.ts', 'node_modules/dart-style/dart-style.d.ts'], {base: '.'})
.pipe(sourcemaps.init())
.pipe(tsProject())
.on('error', onError)
.js.pipe(sourcemaps.write())
.pipe(gulp.dest('build/')); // '/test/' comes from base above.
}));
unitTests = gulp.series('test.compile', function(done) {
if (hasError) {
done();
return;
}
return gulp.src('build/test/**/*.js').pipe(mocha({
timeout: 4000, // Needed by the type-based tests :-(
fullTrace: true,
}));
});
exports['test.unit'] = unitTests;
gulp.task('test', gulp.series(checkFormat, checkLint, unitTests));
gulp.task('watch', gulp.series(unitTests, function() {
failOnError = false;
// Avoid watching generated .d.ts in the build (aka output) directory.
return gulp.watch(['lib/**/*.ts', 'test/**/*.ts'], {ignoreInitial: true}, ['test.unit']);
}));
gulp.task('default', gulp.series('compile'));