-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
42 lines (34 loc) · 1.18 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
var gulp = require('gulp');
var ts = require('gulp-typescript');
var replace = require('gulp-replace');
var merge = require('merge2');
var mocha = require('gulp-spawn-mocha');
var concat = require('gulp-concat');
var insert = require('gulp-insert');
var filter = require('gulp-filter');
var tsProject = ts.createProject('tsconfig.json', {sortOutput: true });
var REF_REGEXP = /^\/\/\/\s*<reference\s+path=['"].*['"]\s*\/>\s*$/gm;
var IMPORT_REGEXP = /^import\s+.*\;$/gm;
gulp.task('build', function() {
var tsResult = tsProject.src()
.pipe(ts(tsProject));
return merge([
tsResult.js
.pipe(replace(REF_REGEXP, ''))
.pipe(gulp.dest('dist')),
tsResult.dts
.pipe(replace(REF_REGEXP, ''))
.pipe(replace(IMPORT_REGEXP, ''))
.pipe(filter(['*', '!index.d.ts']))
.pipe(concat('index.d.ts'))
.pipe(insert.prepend("import Promise = require('bluebird');\n"))
.pipe(gulp.dest('dist'))
]);
});
gulp.task('default', ['build'], function() {
gulp.watch("src/**.ts", ['build']);
});
gulp.task('test', function () {
return gulp.src('test/**.js')
.pipe(mocha());
});