-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
97 lines (81 loc) · 2.57 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
var gulp = require("gulp");
var babel = require("gulp-babel");
// var mocha = require('gulp-mocha');
var batch = require('gulp-batch');
var spawn = require("child_process").spawn;
var exec = require("child_process").exec;
var gulpexec = require('gulp-exec');
var node;
var lastTranspilationSuccessful;
gulp.task("server", ["babel"], function() {
if (lastTranspilationSuccessful) {
if (node) node.kill();
node = spawn("node", (["dist/httpServer.js"]).concat(process.argv.slice(2)), {stdio: "inherit"});
node.on("close", function (code) {
if (code === 8) {
gulp.log("Error detected, waiting for changes...");
}
});
}
});
gulp.task("babel", function () {
// don't end the watch task if the transpilation fails
var b = babel({
// es2015: false,
// stage2: false,
presets: [],
plugins: []
});
lastTranspilationSuccessful = true;
b.on("error", function (e) {
console.log(e.stack);
lastTranspilationSuccessful = false;
b.end();
});
return gulp.src("src/**/*.js")
.pipe(b)
.pipe(gulp.dest("dist"));
});
gulp.task("prod", function() {
gulp.run(["babel", "server"]);
});
gulp.task("watch", function() {
gulp.run(["babel", "server"]);
gulp.watch("src/**/*.js", ["babel", "server"]);
});
gulp.task("default", ["prod"]);
// gulp.task("mocha", function() {
// console.log("mocha")
// gulp.watch(['dist/**'], batch(function (events, cb) {
// return gulp.src(['dist/test*.js'])
// //.pipe(mocha({ reporter: 'list' }))
// .pipe(each(function(content, file, callback) {
// console.log("changed " + file)
// exec("echo " + file, (stdout) => {
// callback()
// })
// }))
// .on('error', function (err) {
// console.log(err.stack);
// });
// }));
// })
gulp.task('mocha', function() {
var options = {
continueOnError: true, // default = false, true means don't emit error event
pipeStdout: false, // default = false, true means stdout is written to file.contents
};
var reportOptions = {
err: true, // default = true, false means don't write err
stderr: true, // default = true, false means don't write stderr
stdout: true // default = true, false means don't write stdout
}
return gulp.src('./dist/test*js')
//.pipe(gulpexec('echo changed <%= file.path %>', options))
.pipe(gulpexec('./node_modules/mocha/bin/mocha <%= file.path %>', options))
.pipe(gulpexec.reporter(reportOptions));
});
gulp.task('test', function() {
gulp.watch("src/**/*.js", ["babel"]);
gulp.watch("dist/**/*.js", ["mocha"]);
})