-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.babel.js
94 lines (83 loc) · 2.38 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
import path from 'path'
import fs from 'fs'
import del from 'rimraf'
import gulp from 'gulp'
import plumber from 'gulp-plumber'
import newer from 'gulp-newer'
import babel from 'gulp-babel'
import gutil from 'gulp-util'
import optimizejs from 'gulp-optimize-js'
import ava from 'gulp-ava'
import standard from 'gulp-standard'
import cache from 'gulp-cached'
import pkg from './package.json'
const paths = {
dist: 'lib',
src: 'src'
}
const files = {
src: `${paths.src}/**/*.{js,jsx}`,
assets: `${paths.src}/**/*.{ejs,json,applescript}`,
test: 'test/**/*.js',
babelRc: JSON.parse(fs.readFileSync(path.join(__dirname, '.babelrc'), 'utf8'))
}
let lintIgnore = []
try {
lintIgnore = pkg.standard.ignore.map(dir => `!${dir}`)
} catch (err) {}
files.lint = [files.src].concat(lintIgnore)
const verboseErrors = /.*(at Parser|\[as .*\]|internal\/process\/next_tick\.js|\/regenerator-runtime\/|node_modules\/babel-register|node_modules\/babel-core|node_modules\/babylon|node_modules\/require-precompiled|node_modules\/babel-traverse|_callee\$).*\n?/g
const transform = cb => gulp.src(files.src)
.pipe(plumber({
errorHandler (err) {
gutil.log(err.stack.replace(verboseErrors, ''))
}
}))
.pipe(newer(paths.dist))
.pipe(babel(files.babelRc))
.pipe(optimizejs())
.pipe(gulp.dest(paths.dist))
const lint = cb => gulp.src(files.lint)
.pipe(plumber({
errorHandler (err) {
gutil.log(err.stack)
}
}))
.pipe(newer(paths.dist))
.pipe(standard())
.pipe(standard.reporter('stylish', {
breakOnError: false,
quiet: true
}))
const test = () => gulp.src(files.test)
.pipe(plumber({
errorHandler (err) {
gutil.log(err.message.replace(verboseErrors, ''))
}
}))
// TODO:
// handle if file is null skip run ava task
.pipe(cache('test'))
.pipe(ava({
// watch: false,
// nyc: true
// files: files.test,
// concurrency: 50,
// failFast: true,
// powerAssert: false,
// require: [],
// babel: 'inherit'
}))
const copy = cb => gulp.src(files.assets)
.pipe(newer(paths.dist))
.pipe(gulp.dest(paths.dist))
const watch = cb => {
gulp.watch(files.src, lint)
gulp.watch(files.src, transform)
gulp.watch(files.assets, copy)
gulp.watch(files.test, test)
}
gulp.task('clean', cb => del(paths.dist, cb))
gulp.task('build', gulp.parallel(transform, copy))
gulp.task(watch)
gulp.task('default', gulp.series('clean', 'build'))