forked from OXOYO/X-Admin-API-Generator-Koa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
82 lines (76 loc) · 1.84 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
/**
* 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(result => {
// Called for each ESLint result.
if (result.messages.length || result.warningCount || result.errorCount) {
console.log(`ESLint Check: ${result.filePath}`)
}
if (result.warningCount) {
console.log(`# Warnings: ${result.warningCount}`)
}
if (result.errorCount) {
console.log(`# Errors: ${result.errorCount}`)
}
if (result.messages.length) {
console.log(`# Messages: ${JSON.stringify(result.messages)}`)
}
})
)
}
// eslint
gulp.task('ESlint', async () => {
await lintFiles([
'src/**',
'!node_modules/**'
])
})
// nodemon
gulp.task('nodemon', async (done) => {
let stream = await gulpNodemon({
script: config.server.script,
ext: 'js',
env: {
'NODE_ENV': 'development'
},
tasks: (changedFiles) => {
lintFiles(changedFiles)
return []
}
})
await 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)
done()
})
})
// default
gulp.task('default', async () => {
// await gulpSequence('ESlint', 'nodemon')(() => {
// console.log('Service started!')
// })
gulp.series('ESlint', 'nodemon')()
})