-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
89 lines (77 loc) · 2.33 KB
/
gulpfile.babel.js
File metadata and controls
89 lines (77 loc) · 2.33 KB
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
import gulp from 'gulp';
import babel from 'gulp-babel';
import sourcemaps from 'gulp-sourcemaps';
import clean from 'gulp-clean';
import istanbul from 'gulp-istanbul';
import mocha from 'gulp-mocha';
import runSequence from 'run-sequence';
import remapIstanbul from 'remap-istanbul/lib/gulpRemapIstanbul';
import nodemon from 'nodemon';
import cached from 'gulp-cached';
const BUILD_DIR = 'build';
const SOURCE_GLOB = 'src/**/*.js';
gulp.task('clean', () => {
return gulp.src(BUILD_DIR, {read: false, allowEmpty: true})
.pipe(clean({force: true}));
});
gulp.task('compile', () => {
return gulp.src(SOURCE_GLOB)
.pipe(cached('js'))
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write({includeContent: false, sourceRoot: '/app/src'}))
.pipe(gulp.dest(BUILD_DIR));
});
gulp.task('build', (callback) => {
runSequence('clean', 'compile', callback);
});
gulp.task('watch', ['build'], () => {
nodemon({script: 'build/main.js'});
gulp.watch(SOURCE_GLOB, ['restart-server']);
});
gulp.task('restart-server', ['compile'], () => {
nodemon.emit('restart');
})
gulp.task('clean-coverage', function () {
return gulp.src('coverage', {read: false, allowEmpty: true})
.pipe(clean({force: true}));
});
gulp.task('pre-test', () => {
return gulp.src('build/**/*.js')
// Covering files
.pipe(istanbul({includeUntested: true}))
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});
gulp.task('test-inner', () => {
return gulp.src('test/**/*.js')
.pipe(babel())
.pipe(mocha({
reporter: 'list'
}))
// Creating the reports after tests ran
.pipe(istanbul.writeReports({
reporters: ['json', 'html'],
reportOpts: {
html: {dir: 'coverage/build/html'},
json: {dir: 'coverage/build/json', file: 'coverage.json'}
}
}));
});
gulp.task('remap-istanbul', function () {
return gulp.src('coverage/build/json/coverage.json')
.pipe(remapIstanbul({
reports: {
'json': 'coverage/src/json/coverage.json',
'html': 'coverage/src/html'
}
}));
});
gulp.task('test', (callback) => {
runSequence(['build', 'clean-coverage'], 'pre-test', 'test-inner', 'remap-istanbul', callback);
});
gulp.task('dev-server', () => {
nodemon({
script: 'build/main.js'
});
});