-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
108 lines (95 loc) · 2.64 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
const apidoc = require('gulp-apidoc');
const babel = require('gulp-babel');
const env = require('gulp-env');
const envFile = require('node-env-file');
const fs = require('fs');
const gulp = require('gulp');
const nodemon = require('gulp-nodemon');
const install = require('gulp-install');
const istanbul = require('gulp-istanbul');
const jscs = require('gulp-jscs');
const mocha = require('gulp-mocha');
const runSequence = require('run-sequence');
const sourcemaps = require('gulp-sourcemaps');
gulp.task('default', () => {
runSequence(['build', 'jscs', 'apidoc'], 'server:development');
});
gulp.task('prod', () => {
runSequence(['build', 'apidoc'], 'server:production');
});
gulp.task('test', ['pre-test'], () => {
if (fs.existsSync('./env.test.list')) {
envFile('./env.test.list');
}
return gulp.src([
'dist-test/test/utils.js',
'dist-test/test/controllers/users.controller.test.js',
'dist-test/test/controllers/survey.controller.test.js',
'dist-test/test/controllers/tournament.controller.test.js',
'dist-test/test/controllers/match.controller.test.js',
'dist-test/test/controllers/users.signout.test.js',])
.pipe(mocha())
.pipe(istanbul.writeReports())
.pipe(istanbul.enforceThresholds({ thresholds: { global: 40 } }))
.once('end', () => {
process.exit();
});
});
gulp.task('build', () => {
return gulp.src('./src/server/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['es2015'],
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist-server'));
});
gulp.task('build:test', () => {
const envs = env.set({
NODE_ENV: 'test',
});
return gulp.src('./src/**/*.js')
.pipe(envs)
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['es2015'],
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist-test'));
});
gulp.task('server:development', () => {
envFile('./env.dev.list');
nodemon({
script: 'server.js',
env: { NODE_ENV: 'development' },
watch: 'src',
tasks: ['build'],
});
});
gulp.task('server:production', () => {
envFile('./env.prod.list');
nodemon({
script: 'server.js',
env: { NODE_ENV: 'production' },
});
});
gulp.task('pre-test', ['build:test'], () => {
return gulp.src(['dist-test/server/**/*.js'])
.pipe(istanbul())
.pipe(istanbul.hookRequire());
});
gulp.task('install', () => {
gulp.src('./package.json')
.pipe(install());
});
gulp.task('jscs', () => {
return gulp.src('./src/**/*.js')
.pipe(jscs({ fix: true, }))
.pipe(gulp.dest('src'));
});
gulp.task('apidoc', (done) => {
apidoc({
src: 'src',
dest: 'dist-server/apidoc/',
}, done);
});