This repository has been archived by the owner on Mar 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.babel.js
81 lines (69 loc) · 1.87 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
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const babel = require('gulp-babel');
const eslint = require('gulp-eslint');
const rimraf = require('rimraf');
const run = require('run-sequence');
const watch = require('gulp-watch');
const gulpDocumentation = require('gulp-documentation');
const shell = require('gulp-shell');
const packageJson = require('./package.json');
const CONFIG = {
js: {
src: './src/**/*.js',
dst: './lib'
},
documentation: {
js: {
dst: './documentation'
}
}
}
function errorHandler(err) {
console.log(err.toString());
this.emit('end');
}
gulp.task('default', cb => {
run('lint', 'flowtype', 'build', 'flowcopy', cb);
});
gulp.task('build', cb => {
run('clean', 'babel', cb);
});
gulp.task('clean', cb => {
rimraf(CONFIG.js.dst, cb);
});
gulp.task('lint', cb => {
return gulp.src([CONFIG.js.src,'!node_modules/**'])
.on('error', errorHandler)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('flowtype', shell.task(['npm run flow check --show-all-errors']));
gulp.task('flowcopy', shell.task(['npm run flow:copy']));
gulp.task('babel', cb => {
gulp.src([CONFIG.js.src])
.pipe(sourcemaps.init())
.pipe(babel({
presets: [],
plugins: ['transform-flow-strip-types']
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(CONFIG.js.dst))
.on('end', cb);
});
gulp.task('doc', cb => {
run('docs', cb);
});
gulp.task('docs', cb => {
return gulp.src(CONFIG.js.src)
.pipe(gulpDocumentation('md', {}, {
'name': packageJson.name
}))
.pipe(gulp.dest(CONFIG.documentation.js.dst));
});
gulp.task('watch', () => {
return watch(CONFIG.js.src, (file) => {
run(['lint'], 'build', 'docs');
});
});