forked from olivierlsc/swagger-express-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·117 lines (108 loc) · 3.42 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
var gulp = require ('gulp');
var clean = require ('gulp-clean');
var ts = require ('gulp-typescript');
var nodemon = require ('gulp-nodemon');
var sourcemaps = require ('gulp-sourcemaps');
var mocha = require ('gulp-mocha');
var istanbul = require ('gulp-istanbul');
require ('mocha-jenkins-reporter');
var tslint = require ("gulp-tslint");
var tslintReporter = require ('gulp-tslint-jenkins-reporter');
var path = {
built: "built",
dist: "dist",
reports: "reports",
app: {
src: "src/**/*.ts"
}
};
gulp.task ('clean', function () {
return gulp.src ([
path.built,
path.dist,
path.reports,
"src/**/*.js"
]).pipe (clean ({force: true}));
});
var tsProject = ts.createProject ('tsconfig.json', {typescript: require ("typescript")});
gulp.task ('build:ts', ['clean'], function () {
console.info ('Compiling files .ts...');
return gulp.src ([
"src/**/*.ts"
])
.pipe (sourcemaps.init ({loadMaps: true}))
.pipe (tsProject ())
.on ("error", function (err) {
process.exit (1);
})
.js
.pipe (sourcemaps.write ("../".concat(path.built)))
.pipe (gulp.dest (path.built));
});
gulp.task ("tslint", function () {
gulp.src (path.app.src)
.pipe (tslint ({
formatter: "verbose"
}))
.pipe (tslint.report ())
.pipe (tslintReporter ({
sort: true,
filename: 'reports/checkstyle/results.xml',
severity: 'error'
}));
});
gulp.task ('pre-test', ['build:ts'], function () {
return gulp.src ([path.built + '/**/*.spec.js'])
// Covering files
.pipe (istanbul ())
// Force `require` to return covered files
.pipe (istanbul.hookRequire ());
});
gulp.task ('test:coverage', ['pre-test'], function () {
return gulp.src ([path.built])
.pipe (mocha ({
reporter: "mocha-jenkins-reporter",
reporterOptions: {
"junit_report_name": "Tests",
"junit_report_path": "reports/junit/results.xml",
"junit_report_stack": 1
}
}))
// Creating the reports after tests ran
.pipe (istanbul.writeReports ({
dir: './coverage',
reporters: ['text', 'text-summary', 'cobertura', 'html'],
reportOpts: {dir: './reports/coverage'}
}))
// Enforce a coverage of at least 90%
.pipe (istanbul.enforceThresholds ({thresholds: {global: {lines: 80}, each: {lines: 80}}}));
});
gulp.task ('test', ['build:ts'], function () {
return gulp.src (path.built + '/**/*.spec.js', {read: false})
// gulp-mocha needs filepaths so you can't have any plugins before it
.pipe (mocha ({
reporter: "mocha-jenkins-reporter",
reporterOptions: {
"junit_report_name": "Tests",
"junit_report_path": "reports/junit/results.xml",
"junit_report_stack": 1
}
}));
});
gulp.task ('watch', function () {
gulp.watch (path.app.src, ['build', 'test']);
});
gulp.task ('build', ['clean', 'build:ts']);
gulp.task ('dev', ['build', 'watch'], function () {
return nodemon ({
script: 'built/main.js',
ext: 'js',
ignore: [
'node_modules/',
'config/',
'src'
]
}).on ('restart', function () {
console.log ('restarted!')
});
});