-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
153 lines (131 loc) · 3.04 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const del = require('del');
const runSequence = require('run-sequence');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const isparta = require('isparta');
const loadPlugins = require('gulp-load-plugins');
const concat = require('gulp-concat');
const codecov = require('gulp-codecov');
const mochaGlobals = require('./test/setup/.globals');
const Instrumenter = isparta.Instrumenter;
// Load all of our Gulp plugins
const $ = loadPlugins();
const watchFiles = ['src/**/*', 'test/**/*'];
const destinationFolder = 'dist';
/**
* Require register babel.
*/
function registerBabel_() {
require('babel-register');
}
/**
* Mocha helper.
* @return {gulp}
*/
function mocha_() {
return gulp.src(['test/setup/node.js', 'test/unit/**/*.js'], {read: false})
.pipe($.mocha({
reporter: 'spec',
globals: Object.keys(mochaGlobals.globals),
ignoreLeaks: false,
}));
}
/**
* Test helper.
* @return {gulp}
*/
function test() {
registerBabel_();
return mocha_();
}
/**
* Build helper.
* @param {Function} done
*/
function build(done) {
runSequence(
'clean',
'build-src',
['lint'],
done
);
}
/**
* Clean distribution folder.
* @param {Function} done [description]
*/
function cleanDist(done) {
del([destinationFolder]).then(() => done());
}
/**
* Coverage helper.
* @param {Function} done
*/
function coverage(done) {
registerBabel_();
gulp.src(['src/**/*.js'])
.pipe($.istanbul({
instrumenter: Instrumenter,
includeUntested: true,
}))
.pipe($.istanbul.hookRequire())
.on('finish', () => {
return test()
.pipe($.istanbul.writeReports())
.on('end', done);
});
}
/**
* CodeCov helper.
*/
function codeCoverageServer() {
gulp.src('./coverage/lcov.info')
.pipe(codecov());
}
/**
* Test watch helper.
*/
function testWatch() {
gulp.watch(watchFiles, ['test']);
}
// General build
gulp.task('build', build);
// Build the src files
gulp.task('build-src', () => {
return gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(concat('all.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
});
gulp.task('watch-src', () => {
return gulp.watch('src/**/*.js', [
'build-src',
]);
});
gulp.task('watch', ['watch-src']);
// Performs eslint functions
const lintWatchFiles = ['**/*.js',
'!node_modules/**',
'!coverage/**',
'!dist/**'];
gulp.task('lint', () => {
return gulp.src(lintWatchFiles)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint:watch', () => {
gulp.watch(lintWatchFiles, ['lint']);
});
// Remove the built files
gulp.task('clean', cleanDist);
// Set up coverage and run tests
gulp.task('coverage', coverage);
// Run our tests
gulp.task('test', test);
gulp.task('test:watch', testWatch);
gulp.task('test:coverage:travis', codeCoverageServer);