-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
111 lines (95 loc) · 2.71 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict'; // eslint-disable-line
require('babel-polyfill');
const gulp = require('gulp');
const gutil = require('gulp-util');
const sourcemaps = require('gulp-sourcemaps');
const mocha = require('gulp-mocha');
const babel = require('gulp-babel');
const eslint = require('gulp-eslint');
const tslint = require('gulp-tslint');
const ts = require('gulp-typescript');
const typescript = require('typescript');
const es = require('event-stream');
const runSequence = require('run-sequence');
const srcTsProject = ts.createProject('tsconfig.json', {
typescript,
declaration: true,
});
const testTsProject = ts.createProject('tsconfig.json', {
typescript,
});
gulp.task('lint:js', function () {
return gulp.src([
'gulpfile.js',
]).pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint:ts', function () {
return gulp.src([
'src/**/*.ts',
'test/**/*.ts',
]).pipe(tslint())
.pipe(tslint.report('verbose'));
});
gulp.task('lint', ['lint:js', 'lint:ts']);
gulp.task('build', function () {
let compileError = null;
const tsResult = gulp.src([
'typings/tsd.d.ts',
'src/**/*.ts',
]).pipe(sourcemaps.init())
.pipe(ts(srcTsProject, undefined, ts.reporter.longReporter()))
.on('error', err => compileError = err);
return es.merge([
// declaration files
tsResult.dts
.pipe(gulp.dest('lib')),
// js files
tsResult.js
.pipe(babel())
.pipe(sourcemaps.write())
.pipe(gulp.dest('lib')),
]).on('end', function () {
// Make gulp-typescript stop on compile error.
if (compileError) { this.emit('error', new gutil.PluginError('gulp-typescript', compileError.message)); }
});
});
gulp.task('build:test', ['build'], function () {
let compileError = null;
return gulp.src([
'typings/tsd.d.ts',
'test/**/*.ts',
]).pipe(sourcemaps.init())
.pipe(ts(testTsProject, undefined, ts.reporter.longReporter()))
.on('error', err => compileError = err)
.pipe(babel())
.pipe(sourcemaps.write())
.pipe(gulp.dest('.test'))
.on('end', function () {
// Make gulp-typescript stop on compile error.
if (compileError) { this.emit('error', new gutil.PluginError('gulp-typescript', compileError.message)); }
});
});
gulp.task('test:run', ['build:test'], function () {
return gulp.src([
'.test/**/*.js',
]).pipe(mocha({
timeout: 2000,
reporter: 'spec',
require: ['source-map-support/register'],
}));
});
gulp.task('test', function (done) {
runSequence('lint', 'test:run', done);
});
gulp.task('test:watch', function () {
runSequence('test');
gulp.watch([
'gulpfile.js',
'tslint.json',
'typings/tsd.d.ts',
'src/**/*.ts',
'test/**/*.ts',
], ['test']);
});