-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.babel.js
115 lines (95 loc) · 2.52 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//-------------------------------------------------------------------------------
// Imports
//-------------------------------------------------------------------------------
import gulp from 'gulp'
import babel from 'gulp-babel'
import eslint from 'gulp-eslint'
import mocha from 'gulp-mocha'
import sourcemaps from 'gulp-sourcemaps'
import util from 'gulp-util'
import del from 'del'
import babelRegister from 'babel-core/register'
//-------------------------------------------------------------------------------
// Gulp Properties
//-------------------------------------------------------------------------------
const sources = {
babel: [
'src/**',
'!**/tests/**'
]
}
//-------------------------------------------------------------------------------
// Gulp Tasks
//-------------------------------------------------------------------------------
gulp.task('default', ['prod'])
gulp.task('prod', ['babel'])
gulp.task('dev', ['babel', 'lint', 'babel-watch', 'lint-watch'])
gulp.task('test', ['lint', 'mocha'])
gulp.task('babel', function() {
return gulp.src(sources.babel)
.pipe(sourcemaps.init({
loadMaps: true
}))
.pipe(babel({
presets: ['es2015', 'stage-1', 'stage-2']
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'))
.on('error', (error) => {
util.log(error)
})
})
gulp.task('lint', () => {
return gulp.src([
'**/*.js',
'!node_modules/**',
'!dist/**'
])
.pipe(eslint())
.pipe(eslint.formatEach())
.pipe(eslint.failOnError())
.on('error', function (error) {
util.log('Stream Exiting With Error', error)
})
})
gulp.task('mocha', () => {
return gulp.src([
'**/__tests__/*.js',
'!node_modules/**',
'!dist/**'
])
.pipe(mocha({
compilers: {
js: babelRegister
}
}))
})
gulp.task('clean', () => {
return del([
'dist'
])
})
gulp.task('cleanse', () => {
return del([
'node_modules'
])
})
//-------------------------------------------------------------------------------
// Gulp Watchers
//-------------------------------------------------------------------------------
gulp.task('babel-watch', function() {
gulp.watch(sources.babel, ['babel'])
})
gulp.task('lint-watch', function() {
const lintAndPrint = eslint()
lintAndPrint.pipe(eslint.formatEach())
return gulp.watch('src/**/*.js', function (event) {
if (event.type !== 'deleted') {
gulp.src(event.path)
.pipe(lintAndPrint, {end: false})
.on('error', function (error) {
util.log(error)
})
}
})
})