forked from olivierlsc/swagger-express-ts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
executable file
·165 lines (153 loc) · 4.3 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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 prettierPlugin = require("gulp-prettier-plugin");
var path = {
built: "built",
dist: "dist",
src: "src",
reports: "reports",
app: {
src: "src/**/*.ts",
built: "built/**/*.ts"
}
};
gulp.task("clean", function() {
return gulp
.src([path.built, path.dist, path.src.concat("/**/*.js"), path.src.concat("/**/*.js.map")])
.pipe(clean({ force: true }));
});
gulp.task("prettier", function() {
return (
gulp
.src([path.app.src])
.pipe(prettierPlugin(undefined, { filter: true }))
// passing a function that returns base will write the files in-place
.pipe(
gulp.dest(function(file) {
return file.base;
})
)
);
});
gulp.task("copy:src", ["clean"], function() {
return gulp.src([path.app.src]).pipe(gulp.dest(path.built));
});
var tsProject = ts.createProject("tsconfig.json", { typescript: require("typescript") });
gulp.task("build:ts", ["prettier", "copy:src"], function() {
console.info("Compiling files .ts...");
return (
gulp
.src([path.app.src])
.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() {
return 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", ["set:node-env:test", "build:ts"], function() {
return (
gulp
.src([path.built + "/**/*.js", "!" + path.built + "/**/*.spec.js"], { base: path.built })
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire())
);
});
gulp.task("test:coverage", ["set:node-env:test", "build:ts", "pre-test"], function() {
return (
gulp
.src([path.built + "/**/*.spec.js"])
.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("set:node-env:test", function() {
return (process.env.NODE_ENV = "test");
});
gulp.task("test", ["set:node-env: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, ["prettier", "build"]);
});
gulp.task("build", ["clean", "copy:src", "build:ts"]);
gulp.task("dev", ["build", "watch"], function() {
nodemon({
script: "built/main.js",
ext: "js",
ignore: ["node_modules/", "config/", "src"]
})
.on("start", function() {
console.info("nodemon has started app");
})
.on("quit", function() {
console.info("nodedmon has quit");
process.exit();
})
.on("restart", function(files) {
console.info("App restarted due to: ", files);
});
});