-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
89 lines (75 loc) · 2.16 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
/*eslint no-mixed-requires:0*/
'use strict';
var q = require('q'),
_ = require('ls-lodash'),
del = require('del'),
path = require('path'),
qWebpack = q.denodeify(require('webpack')),
gulp = require('gulp'),
gutil = require('gulp-util'),
eslint = require('gulp-eslint'),
mocha = require('gulp-mocha'),
rename = require('gulp-rename'),
jsdoc2md = require('gulp-jsdoc-to-markdown'),
webpackConfig = require('./webpack.config.js'),
buildDir = path.resolve(__dirname, 'dist'),
libGlob = path.join('lib', '**', '*.js'),
testGlob = path.join('test', '**', '*.js');
function printWebpackStats(taskName) {
return function(stats) {
gutil.log('[' + taskName + ']', stats.toString({colors: true}));
};
}
gulp.task('default', [
'test',
'watch'
]);
gulp.task('test', [
'lint',
'build',
'mocha'
]);
gulp.task('build', [
'webpack',
'docs'
]);
gulp.task('watch', function() {
gulp.watch([libGlob, testGlob], ['test']);
});
gulp.task('lint', function() {
return gulp.src([testGlob, libGlob, './*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('mocha', ['build'], function() {
return gulp.src(testGlob)
.pipe(mocha({
reporter: process.env.CI ? 'spec' : 'nyan',
compilers: {js: require('babel/register')}
}));
});
gulp.task('clean', _.once(function() {
gutil.log('[clean]', 'First and ONLY run.');
return q.all([
q.nfcall(del, [path.join(buildDir, '**')]),
q.nfcall(del, [path.join('docs', 'api', '**')])
]);
}));
gulp.task('webpack', ['clean'], function() {
var taskName = 'webpack';
return qWebpack(webpackConfig)
.then(printWebpackStats(taskName))
.fail(function(err) {
throw new gutil.PluginError(taskName, err);
});
});
gulp.task('docs', function(){
return gulp.src('lib/index.js')
.pipe(jsdoc2md())
.on('error', function(err){
gutil.log(gutil.colors.red('[jsdoc2md] failed'), err.message);
})
.pipe(rename({ extname: '.md' }))
.pipe(gulp.dest('./docs/api'));
});