-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
78 lines (70 loc) · 1.74 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
const gulp = require('gulp')
const browserSync = require('browser-sync').create()
const babel = require('gulp-babel')
const eslint = require('gulp-eslint')
const fsPromises = require('fs').promises
const srcFiles = ['./src/**/*.js']
gulp.task('clean', () => {
return fsPromises.readdir('dist')
.then(fileList => {
if (fileList.length > 0) {
let unlinkPromises = []
fileList.forEach(fileName => {
unlinkPromises.push(fsPromises.unlink(`dist/${fileName}`))
})
return Promise.all(unlinkPromises)
}
}).catch(error => {
if (error.code !== 'ENOENT') { return Promise.reject(error) }
})
})
gulp.task('build', () =>
gulp.src(srcFiles)
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(gulp.dest('dist'))
)
gulp.task('lint', () => {
return gulp.src(srcFiles)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
})
gulp.task('server', () => {
browserSync.init({
port: 8080,
notify: false,
reloadOnRestart: true,
https: false,
server: ['./']
})
gulp.watch([
'**/*.html',
'**/*.js'
]).on('change', browserSync.reload)
})
gulp.task('development', gulp.series(
gulp.parallel('build'),
async function watch () {
gulp.watch(srcFiles, gulp.parallel('build'))
},
async function testServer () {
browserSync.init({
port: 8080,
notify: false,
reloadOnRestart: true,
https: false,
server: ['./'],
startPath: 'playground/test.html'
})
gulp.watch([
'dist/*',
'plaground/*'
]).on('change', browserSync.reload)
}
))
gulp.task('docs', gulp.series('build', function copyToDocs () {
return gulp.src('dist/kairoi.js')
.pipe(gulp.dest('docs/javascripts'))
}))