-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
116 lines (101 loc) · 3.39 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
var gulp = require("gulp");
var ts = require("gulp-typescript");
var mocha = require("gulp-mocha");
var istanbul = require("gulp-istanbul");
var nodemon = require("gulp-nodemon");
var browserSync = require("browser-sync").create();
var sass = require("gulp-sass");
var KarmaServer = require("karma").Server;
var config = {
back: {
build: "back:build",
test: "back:test",
watch: "back:watch",
tsFiles: "back/src/**/*.ts",
outDir: "back/dist",
testFiles: "back/dist/**/*.test.js",
tsConfig: {target: "es5", module: "commonjs"},
testConfig: {}
},
front: {
build: "front:build",
test: "front:test",
watch: "front:watch",
tsFiles: "front/src/**/*.ts",
outDir: "front/dist",
tsConfig: {target: "es5", module: "commonjs"}
}
};
gulp.task(config.back.build, function () {
return gulp.src(config.back.tsFiles)
.pipe(ts(config.back.tsConfig))
.pipe(gulp.dest(config.back.outDir));
});
gulp.task(config.front.build, ["build:html", "build:scss"], function () {
return gulp.src(config.front.tsFiles)
.pipe(ts(config.front.tsConfig))
.pipe(gulp.dest(config.front.outDir));
});
gulp.task("pre-test", [config.back.build], function () {
return gulp.src(["back/dist/**/*.js"])
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});
gulp.task(config.back.test, ["pre-test"], function () {
return gulp.src(config.back.testFiles, {read: false})
.pipe(mocha(config.back.testConfig))
.pipe(istanbul.writeReports())
.on("error", handleError);
});
// error handler for watching with gulp-mocha
function handleError(err) {
// report error
console.error(err.toString());
// emit end to make gulp.watch work
this.emit("end");
}
gulp.task(config.back.watch, [config.back.build], function () {
gulp.watch(config.back.tsFiles, [config.back.build]);
});
gulp.task("build:html", function() {
gulp.src("front/src/**/*.html")
.pipe(gulp.dest("front/dist"))
});
gulp.task("build:scss", function() {
return gulp.src("front/src/**/*.scss")
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest("front/dist"));
});
gulp.task(config.front.watch, [config.front.build], function () {
gulp.watch(config.front.tsFiles, [config.front.build, function() { browserSync.reload();}]);
gulp.watch("front/src/**/*.html", ["build:html", function() { browserSync.reload(); }]);
gulp.watch("front/src/**/*.scss", ["build:scss", function() { browserSync.reload(); }]);
});
gulp.task("watch", [config.back.watch, config.front.watch], function() {
nodemon({
script: "back/dist/main",
watch: "back/dist/**/*.js"
});
});
gulp.task(config.front.test, [config.back.test, config.front.build], function(done) {
new KarmaServer({
configFile: __dirname + "/karma.conf.js"
}, done).start();
});
gulp.task("front:dev", [config.front.watch], function(done) {
new KarmaServer({
configFile: __dirname + "/karma.conf.js",
singleRun: false
}, done).start();
});
gulp.task("serve", ["watch"], function() {
setTimeout(function() {
browserSync.init({
proxy: "localhost:3000",
port: 4000
});
}, 1000);
});
gulp.task("default", [config.back.test, config.front.test]);