-
Notifications
You must be signed in to change notification settings - Fork 18
/
gulpfile.js
94 lines (88 loc) · 2.12 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
90
91
92
93
94
/**
* Created by OXOYO on 2017/10/25.
*/
const gulp = require('gulp')
const gulpEslint = require('gulp-eslint')
const gulpNodemon = require('gulp-nodemon')
const eslintFriendlyFormatter = require('eslint-friendly-formatter')
const config = {
server: {
script: 'build/dev-server.js'
}
}
const lintFiles = (files) => {
return gulp.src(
files
).pipe(
gulpEslint({
configFile: './.eslintrc.js'
})
).pipe(
gulpEslint.format(eslintFriendlyFormatter)
).pipe(
gulpEslint.result(results => {
// Called for each ESLint result.
console.log(`ESLint result: ${results.filePath}`)
if (results.messages.length) {
console.log(`# Messages: ${results.messages.length}`)
}
if (results.warningCount) {
console.log(`# Warnings: ${results.warningCount}`)
}
if (results.errorCount) {
console.log(`# Errors: ${results.errorCount}`)
}
})
).pipe(
gulpEslint.results(results => {
// Called once for all ESLint results.
console.log(`Total Results: ${results.length}`)
if (results.messages) {
console.log(`Total Messages: ${results.messages.length}`)
}
if (results.warningCount) {
console.log(`Total Warnings: ${results.warningCount}`)
}
if (results.errorCount) {
console.log(`Total Errors: ${results.errorCount}`)
}
})
)
}
// eslint
gulp.task('ESlint', (done) => {
lintFiles([
'src/**',
'!node_modules/**'
])
done()
})
// nodemon
gulp.task('nodemon', (done) => {
let stream = gulpNodemon({
script: config.server.script,
ext: 'js',
env: {
'NODE_ENV': process.env.NODE_ENV
},
tasks: (changedFiles) => {
lintFiles(changedFiles)
return []
},
done: done
})
stream.on('restart', () => {
console.log('Service restarted!')
}).on('crash', () => {
console.error('Service has crashed!\n')
// restart the server in 10 seconds
// stream.emit('restart', 10)
})
})
// default
gulp.task('default', () => {
return gulp.series('ESlint', 'nodemon', (done) => {
console.log('Service started!')
done()
})()
})