-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
107 lines (96 loc) · 2.76 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
99
100
101
102
103
104
105
106
107
const concat = require('gulp-concat');
const gulp = require('gulp');
const istanbul = require('gulp-istanbul');
const jasmineTest = require('gulp-jasmine');
const remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul');
const replace = require('gulp-replace');
const reporters = require('jasmine-reporters');
const sourcemaps = require('gulp-sourcemaps');
const ts = require('gulp-typescript');
const yaml = require('gulp-yaml');
const tsProject = ts.createProject('tsconfig.json');
const paths = {
api: 'api/swagger/swagger.yaml',
bin: 'bin',
conf: () => ['src/**/*.json', paths.templates + '/*.json'],
coverage: 'coverage',
src: 'src/**/!(*.spec).ts',
specs: 'src/*.spec.ts',
templates: 'templates',
};
let watching = false;
let failed = false;
gulp.task('watch', () => {
watching = true;
gulp.watch(paths.api, ['test']);
gulp.watch(paths.conf(), ['test']);
gulp.watch(paths.src, ['test']);
gulp.watch(paths.specs, ['test']);
});
const handleError = function(error: Error) {
error.stack && console.error(error.stack);
failed = true;
watching || process.exit(1);
this.emit('end');
};
gulp.task('compile', () => {
failed = false;
gulp
.src(paths.conf())
.pipe(gulp.dest(paths.bin));
gulp
.src(paths.api)
.pipe(yaml({
replacer: (key: string, value: any) =>
key.startsWith('x-amazon') || key === 'options' ? undefined : value,
}))
.pipe(gulp.dest(paths.bin));
return tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.on('error', handleError)
.js
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.bin));
});
const remapCoverageFiles = () => {
const reports: { [key: string]: string } = {
'html': paths.coverage,
'lcovonly': paths.coverage + '/lcov.info',
};
watching || (reports['text-summary'] = null);
return failed || gulp
.src(paths.coverage + '/coverage-final.json')
.pipe(remapIstanbul({
reports,
}));
};
let coverageVariable: string;
gulp.task('coverage', ['compile'], () => {
coverageVariable = '$$cov_' + new Date().getTime() + '$$';
return failed || gulp
.src(paths.bin + '/!(*.spec).js')
.pipe(istanbul({
coverageVariable: coverageVariable,
}))
.pipe(istanbul.hookRequire());
});
gulp.task('test', ['coverage'], () => {
const silent = watching && !process.env['LOG_LEVEL'];
return failed || gulp
.src(paths.bin + '/*.spec.js')
.pipe(jasmineTest(silent ? {} : {
reporter: new reporters.TerminalReporter({
verbosity: 3,
color: true,
}),
}))
.on('error', handleError)
.pipe(istanbul.writeReports({
dir: paths.coverage,
reporters: ['json'],
coverageVariable: coverageVariable,
}))
.on('end', remapCoverageFiles);
});
gulp.task('default', ['watch', 'test']);