This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
76 lines (66 loc) · 2.09 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
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 merge = require('merge2');
var sourcemaps = require('gulp-sourcemaps');
var ts = require('gulp-typescript');
var typescript = require('typescript');
var mocha = require('gulp-mocha');
gulp.task('check-format', function() {
return gulp.src(['*.js', 'lib/**/*.ts', 'test/**/*.ts', '!test/fixtures/**/*.ts'])
.pipe(formatter.checkFormat('file', clangFormat))
.on('warning', onError);
});
var hasError;
var failOnError = false;
var onError = function(err) {
hasError = true;
if (failOnError) {
process.exit(1);
}
};
var tsProject =
ts.createProject('tsconfig.json', {noEmit: false, declaration: true, typescript: typescript});
gulp.task('compile', function() {
hasError = false;
var tsResult =
gulp.src(['lib/**/*.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', ['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())
.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').pipe(mocha({
timeout: 4000 // Needed by the type-based tests :-(
}))
});
gulp.task('watch', ['test.unit'], 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', ['compile']);