-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
98 lines (74 loc) · 2.58 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/// <reference path="./typings/node/node.d.ts"/>
/// <reference path="./typings/gulp/gulp.d.ts"/>
/// <reference path="./typings/gulp-istanbul/gulp-istanbul.d.ts"/>
/// <reference path="./typings/gulp-mocha/gulp-mocha.d.ts"/>
/// <reference path="./typings/gulp-tslint/gulp-tslint.d.ts"/>
/// <reference path="./typings/gulp-typescript/gulp-typescript.d.ts"/>
'use strict';
/* Import dependencies */
import gulp = require('gulp')
import istanbul = require('gulp-istanbul')
import mocha = require('gulp-mocha')
import path = require('path')
import tslint = require('gulp-tslint')
import typescript = require('gulp-typescript')
/* Constant definitions */
var tsconfig = require('./tsconfig.json')
var compilerOptions = tsconfig.compilerOptions
var filesGlob = tsconfig.filesGlob
var outDir = compilerOptions.outDir
var srcDir = path.normalize('src')
var testDir = path.normalize('test')
var srcOutDir = path.join(outDir, srcDir)
var testOutDir = path.join(outDir, testDir)
var srcTsFiles = path.join(srcDir, '**', '*.ts')
var srcJsFiles = path.join(srcOutDir, '**', '*.js')
var testTsFiles = path.join(testDir, '**', '*.ts')
var testJsFiles = path.join(testOutDir, '**', '*.js')
/* Compile targets */
// Compiles the specified typescript files, writing to the given destination
function compile(files: string, destination: string): NodeJS.ReadWriteStream {
'use strict';
return gulp.src(files, { base: './' })
.pipe(typescript(compilerOptions))
.js.pipe(gulp.dest(outDir))
}
gulp.task('compile', () => {
return compile(srcTsFiles, srcOutDir)
})
gulp.task('compile-test', () => {
return compile(testTsFiles, testOutDir)
})
/* Static Analysis targets */
gulp.task('lint', () => {
return gulp.src(filesGlob)
.pipe(tslint())
.pipe(tslint.report('prose'))
})
/* Test targets */
// Test the specified files using mocha
function test(files): NodeJS.ReadWriteStream {
'use strict';
return gulp.src(testJsFiles, { read: false })
.pipe(mocha({ reporter: 'spec' }))
}
gulp.task('test', ['compile', 'compile-test'], () => {
return test(testJsFiles)
});
gulp.task('coverage', ['compile', 'compile-test'], (cb) => {
return gulp.src(srcJsFiles)
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('finish', () => {
test(testJsFiles)
.pipe(istanbul.writeReports())
.on('end', () => { })
})
})
/* Watch target */
gulp.task('watch', () => {
gulp.watch(srcTsFiles, ['default'])
})
/* Common targets */
gulp.task('all', ['lint', 'compile', 'coverage'])
gulp.task('default', ['lint', 'compile'])