-
Notifications
You must be signed in to change notification settings - Fork 16
/
gulpfile.babel.js
110 lines (98 loc) · 2.42 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import sourcemaps from 'gulp-sourcemaps';
import mocha from 'gulp-mocha';
import eslint from 'gulp-eslint';
import babel from 'gulp-babel';
import plumber from 'gulp-plumber';
import istanbul from 'gulp-babel-istanbul';
import util from 'gulp-util';
import del from 'del';
import Instrumenter from 'isparta';
import runSequence from 'run-sequence';
const paths = {
sourceFiles: ['src/**/*.js'],
tests: ['test/**/*.js'],
buildDir: 'build',
};
paths.buildFiles = [`${paths.buildDir}/**/*.js`];
/**
* Task to remove assets from last build
*/
gulp.task('clean', (done) => {
del(['build', 'coverage'], done);
});
/**
* Task to lint the src files
*/
gulp.task('lint', () => (
gulp.src(paths.sourceFiles)
.pipe(eslint())
.pipe(eslint.failOnError())
));
/**
* Task to run the build
*/
gulp.task('build', () => (
gulp.src(paths.sourceFiles)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['babel-preset-es2015'],
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.buildDir))
.on('error', util.log)
));
/**
* Task to hook anything required before the tests (basically just here for istanbul)
*/
gulp.task('coverage:instrument', () => (
gulp.src(paths.sourceFiles)
.pipe(istanbul({
instrumenter: Instrumenter,
includeUntested: true,
exclude: ['src/migrations/**/*.js'],
}))
.pipe(istanbul.hookRequire())
));
/**
* Task to conduct the requred tests
*/
gulp.task('test', () => (
gulp.src(paths.tests, { read: false })
.pipe(mocha({
bail: true,
require: 'babel-register',
reporter: 'list',
}))
.on('error', util.log)
));
gulp.task('coverage:report', () => (
gulp.src(paths.sourceFiles, { read: false })
.pipe(istanbul.writeReports({
dir: './coverage',
reporters: [
'lcov',
'json',
'text',
'text-summary',
],
reportOpts: {
dir: './coverage',
},
}))
.pipe(istanbul.enforceThresholds({ thresholds: { global: 10 } }))
.on('error', util.log)
));
gulp.task('test:coverage', done => (
runSequence('coverage:instrument', 'test', 'coverage:report', done)
));
/**
* Task to watch the files whilst developing
*/
gulp.task('watch', () => (
gulp.watch(paths.sourceFiles, ['build'])
));
gulp.task('prebuild', ['clean', 'lint', 'test:coverage']);
gulp.task('default', ['prebuild', 'build']);
gulp.task('prepublish', ['default']);