-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
107 lines (82 loc) · 1.98 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
var gulp = require('gulp');
var ts = require('gulp-typescript');
var env = process.env.ENV || 'dev';
var paths = {
server: {
src: 'server/**/*.ts',
out: 'server'
},
tests: {
src: 'tests/**/*.ts',
out: 'tests',
mocha: 'tests/server/unit/**/*.js'
}
}
var server, mocha, exec, files;
if (env === 'dev') {
files = [paths.server.src, paths.tests.src];
server = require('gulp-develop-server');
mocha = require('gulp-mocha');
} else {
files = [paths.server.src];
exec = require('child_process').exec;
}
// ** Default ** //
gulp.task('default', ['run']);
if (env === 'dev') {
// ** Start server ** //
gulp.task('start', ['test'], function () {
server.listen({path: 'bin/www'});
});
// ** Restart server ** //
gulp.task('restart', ['test'], function () {
server.restart();
});
// ** Testing ** //
gulp.task('test', ['buildTests'], function (cb) {
gulp
.src(paths.tests.mocha)
.pipe(mocha())
.once('error', handleError)
.once('end', cb);
});
// ** Compile tests ** //
gulp.task('buildTests', ['build'], function (cb) {
compile(paths.tests.src, paths.tests.out, cb);
});
// ** Running ** //
gulp.task('run', ['start'], function () {
gulp.watch(files, ['restart']);
});
} else {
// ** Running ** //
gulp.task('run', function (cb) {
exec('node bin/www', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
}
// ** Compilation ** //
gulp.task('build', function (cb) {
compile(paths.server.src, paths.server.out, cb);
});
function compile(src, out, cb) {
var tsProject = ts.createProject('tsconfig.json');
var tsResult = gulp
.src(src)
.pipe(ts(tsProject))
.once('error', handleError)
.js
.pipe(gulp.dest(out))
.once('end', cb);
return tsResult;
}
function handleError(err) {
if (env === 'dev') {
gulp.watch(files, ['restart']);
} else {
throw err;
}
}