Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
72 lines (63 loc) · 1.68 KB
/
Copy pathgulpfile.js
File metadata and controls
72 lines (63 loc) · 1.68 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
"use strict";
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const eslint = require('gulp-eslint');
const sequence = require('run-sequence');
const _glob = require('glob');
const co = require('co');
const childProcess = require('child_process');
const entry = './index.js';
const testDir = './test';
const testGlob = `${testDir}/*.spec.js`;
const perfDir = './perf';
const perfGlob = `${perfDir}/*.perf.js`;
const srcDir = './src';
const srcGlob = `${srcDir}/**/*.js`;
const glob = (path, options = {}) => new Promise((resolve, reject) => {
return _glob(path, options, (err, data) => {
if (err) {
return reject(err);
}
return resolve(data);
});
});
const spawn = (command, args = [], options = { stdio: 'inherit' }) => new Promise((resolve, reject) => {
const child = childProcess.spawn(command, args, options);
child.once('error', reject);
child.once('close', resolve);
});
gulp.task('lint', () => {
return gulp.src([ entry, srcGlob, testGlob, './gulpfile.js' ])
.pipe(eslint())
.pipe(eslint.format());
});
gulp.task('test', () => {
return gulp.src(testGlob)
.pipe(mocha({
reporter: 'spec'
}));
});
gulp.task('watch', () => {
gulp.watch([ entry, srcGlob, testGlob ], () => {
return sequence('lint', 'test');
});
});
gulp.task('perf', () => {
const skips = [ 'map-async', 'map-limit', 'map-series' ];
return co(function*() {
const files = yield glob(perfGlob);
for (let file of files) {
if (skips.every(skip => file.indexOf(skip) === -1)) {
yield spawn('node', [ file ]);
}
}
});
});
gulp.task('default', done => {
sequence(
'lint'
, 'test'
, 'watch'
, done
);
});