-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
65 lines (51 loc) · 1.96 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
import { spawn } from 'child_process';
import * as del from 'del';
import * as gulp from 'gulp';
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(callback: (err?: Error) => void) {
process.exitCode = 0;
const mocha = __dirname + '/node_modules/.bin/mocha' + (process.platform === 'win32' ? '.cmd' : '');
const args = ['--require', 'ts-node/register', '--require', 'source-map-support/register', 'src/**/*.spec.ts'];
return spawn(mocha, args, { cwd: __dirname, stdio: 'inherit' });
}
gulp.task('default', gulp.series(clean, buildES5, buildES6, test));