-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.ts
84 lines (68 loc) · 2.32 KB
/
gulpfile.ts
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
import * as del from 'del';
const gulp = require('gulp');
import * as mocha from 'gulp-mocha';
import * as sourcemaps from 'gulp-sourcemaps';
import { createProject as createTypescriptProject } from 'gulp-typescript';
import * as merge2 from 'merge2';
import { install as installSourceMapSupport } from 'source-map-support';
installSourceMapSupport();
gulp.task('clean', clean);
gulp.task('build', gulp.series(buildES5, buildES6));
gulp.task('test', test);
gulp.task('watch', gulp.series(clean, buildES5, test, watch));
const es5project = createTypescriptProject('tsconfig.es5.json', {
typescript: require('typescript')
});
const es6project = createTypescriptProject('tsconfig.es6.json', {
typescript: require('typescript')
});
function clean() {
return del(['es5/**', '!es5', 'es6/**', '!es6', 'declarations/**', '!declarations']);
}
function buildES5() {
return buildTypescript(es5project, 'es5');
}
function buildES6() {
return buildTypescript(es6project, 'es6');
}
function buildTypescript(tsProject: any, destination: string) {
const tsResult = gulp
.src(['src/**/*.ts', '!src/**/*.spec.*'])
.pipe(sourcemaps.init())
.pipe(tsProject());
return merge2(
tsResult.dts
.pipe(gulp.dest('declarations')),
tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(destination))
);
}
function watch() {
gulp.watch(['src/**', '!src/**/*.spec.ts'], gulp.series(test, buildES5, buildES6));
gulp.watch(['src/**/*.spec.ts'], gulp.series(test));
}
function test() {
const watching = process.argv.some(arg => arg === 'watch');
process.exitCode = 0;
Error.stackTraceLimit = 50;
return gulp.src(['src/**/*.spec.ts'])
.pipe(mocha({
reporter: watching ? 'min' : 'spec',
require: ["ts-node/register"]
}))
.on('error', function (error: Error) {
if (error.name === 'TSError') {
console.error(error.message);
} else if (!/^\s*\d+ tests? failed./.test(error.message)) {
console.error(error.toString());
}
process.exitCode = 1;
this.emit('end');
});
}
gulp.task('default', gulp.series(clean, buildES5, buildES6, test));
process.on('SIGINT', () => {
process.exit();
process.kill(process.pid);
});