-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
79 lines (73 loc) · 1.78 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
/**
* Created by OXOYO on 2017/10/25.
*/
const gulp = require('gulp')
const gulpEslint = require('gulp-eslint')
const gulpNodemon = require('gulp-nodemon')
const gulpSequence = require('gulp-sequence')
const eslintFriendlyFormatter = require('eslint-friendly-formatter')
const config = {
server: {
script: './src/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}`)
console.log(`# Messages: ${results.messages.length}`)
console.log(`# Warnings: ${results.warningCount}`)
console.log(`# Errors: ${results.errorCount}`)
})
).pipe(
gulpEslint.results(results => {
// Called once for all ESLint results.
console.log(`Total Results: ${results.length}`)
console.log(`Total Warnings: ${results.warningCount}`)
console.log(`Total Errors: ${results.errorCount}`)
})
)
}
// eslint
gulp.task('ESlint', () => {
lintFiles([
'src/**',
'!node_modules/**'
])
})
// nodemon
gulp.task('nodemon', () => {
let stream = gulpNodemon({
script: config.server.script,
ext: 'js',
env: {
'NODE_ENV': 'development'
},
tasks: (changedFiles) => {
lintFiles(changedFiles)
return []
}
})
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', () => {
gulpSequence('ESlint', 'nodemon')(() => {
console.log('Service started!')
})
})