-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
60 lines (47 loc) · 1.72 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
var gulp = require('gulp');
var ts = require('gulp-typescript');
var concat = require('gulp-concat');
var replace = require('gulp-replace');
var merge = require('merge2');
var fs = require('fs');
var mocha = require('gulp-spawn-mocha');
var tsProjectJs = ts.createProject('tsconfig.json', { sortOutput: true });
//if use same project exception thrown on task
var tsProjectDts = ts.createProject('tsconfig.json', { sortOutput: true });
var REF_REGEXP = /^\/\/\/\s*<reference\s+path=['"].*['"]\s*\/>\s*$/gm;
var IMPORT_REGEXP = /^import\s+.*\;$/gm;
var EXPORT_DECLARE_REGEXP = /^export\s+declare\s+/gm;
gulp.task('build', function() {
//build conactinated version of source
//no module and node exports
var tsResultJs = tsProjectJs.src()
.pipe(ts(tsProjectJs));
var tsResultDts = gulp.src("src/trader-net.ts")
.pipe(ts(tsProjectDts));
return merge([
tsResultJs.js
.pipe(replace(REF_REGEXP, ''))
.pipe(gulp.dest('dist')),
tsResultDts.dts
.pipe(replace(REF_REGEXP, ''))
.pipe(replace(IMPORT_REGEXP, ''))
.pipe(concat('trader-net.d.ts'))
.pipe(gulp.dest('tmp'))
]);
});
gulp.task('build:module', ['build'], function() {
//build module version from `conactinated` version
var build = fs.readFileSync("tmp/trader-net.d.ts", "utf-8");
gulp.src("src/index.tmpl.d.ts")
.pipe(replace('//', build))
.pipe(replace(EXPORT_DECLARE_REGEXP, 'export '))
.pipe(concat('index.d.ts'))
.pipe(gulp.dest('dist'));
})
gulp.task('default', ['build:module'], function() {
gulp.watch("src/**.ts", ['build:module']);
});
gulp.task('test', function () {
return gulp.src('test/**.js')
.pipe(mocha());
});