-
Notifications
You must be signed in to change notification settings - Fork 42
/
gulpfile.js
144 lines (121 loc) · 3.36 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* Created by Ab on 9-4-2015.
*/
var gulp = require('gulp');
var del = require('del');
var rename = require('gulp-rename');
var merge = require('merge2');
var addsrc = require('gulp-add-src');
var ts = require('gulp-typescript');
var tslint = require('gulp-tslint');
var sourcemaps = require('gulp-sourcemaps');
var mocha = require('gulp-mocha');
// swallow errors in watch
function swallowError (error) {
//If you want details of the error in the console
console.log(error.toString());
this.emit('end');
}
//define typescript project
var tsProject = ts.createProject({
module: 'commonjs',
target: 'ES5',
declaration: true
});
gulp.task('copy-to-lib', gulp.series(compile), function () {
return gulp.src('transpiled/amqp-ts.js')
.pipe(gulp.dest('lib'));
});
gulp.task('clean:all', function () {
del([
'coverage',
'transpiled',
'node_modules'
]);
});
function clean(cb) {
del.sync([
'coverage',
'transpiled'
]);
cb();
}
function compile() {
// compile typescript
var tsResult = gulp.src('src/**/*.ts')
.pipe(tslint({
formatter: 'prose',
configuration: 'tools/tslint/tslint-node.json'
}))
.pipe(tslint.report({
emitError: false
}))
// .pipe(addsrc.prepend('typings*/**/*.d.ts'))
.pipe (sourcemaps.init())
.pipe (tsProject());
return merge([
tsResult.js
.pipe(sourcemaps.write('.', {
includeContent: false,
sourceRoot: '../src/'
}))
.pipe(gulp.dest('transpiled')),
tsResult.dts.pipe(gulp.dest('transpiled'))
]);
}
gulp.task('lint', function () {
return gulp.src('src/**/*.ts')
.pipe(tslint({
formatter: 'full',
configuration: 'tools/tslint/tslint-node.json'
}))
.pipe(tslint.report());
});
// unit tests, more a fast integration test because at the moment it uses an external AMQP server
gulp.task('test', gulp.series('copy-to-lib'), function () {
return gulp.src('transpiled/**/*.spec.js', {
read: false
})
.pipe(mocha({
r: 'tools/mocha/setup.js',
reporter: 'spec' // 'spec', 'dot'
}))
.on('error', swallowError);
});
// unit tests, more a fast integration test because at the moment it uses an external AMQP server
gulp.task('test:dot', gulp.series('copy-to-lib'), function () {
return gulp.src('transpiled/**/*.spec.js', {
read: false
})
.pipe(mocha({
r: 'tools/mocha/setup.js',
reporter: 'dot' // 'spec', 'dot'
}))
.on('error', swallowError);
});
// integration tests, at the moment more an extended version of the unit tests
gulp.task('test:integration', gulp.series('copy-to-lib'), function () {
return gulp.src('transpiled/**/*.spec-i.js', {
read: false
})
.pipe(mocha({
reporter: 'dot' // 'spec', 'dot'
}))
.on('error', swallowError);
});
gulp.task('test:coverage', gulp.series('copy-to-lib'), function () {
return gulp.src('transpiled/**/*.spec.js', {
read: false
})
.pipe(mocha({
reporter: 'spec', // 'spec', 'dot'
istanbul: true
}));
});
// quick fix for gulp 4, migrating from gulp 3, fixing 'task never defined' errors
gulp.task('build', gulp.series(compile, 'copy-to-lib', 'test:dot'));
gulp.task('build:clean', gulp.series(clean, compile, 'test:dot'));
gulp.task('default', gulp.series('build:clean'));
gulp.task('watch', gulp.series(clean, 'build'), function () {
gulp.watch('server/**/*.ts', ['build']);
});