-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
67 lines (56 loc) · 1.67 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
require('dotenv').config()
const browserSync = require('browser-sync').create()
const del = require('del')
const gulp = require('gulp')
const path = require('path')
const copyData = gulp.parallel(copyLegend, copyMap)
const build = gulp.series(clean, gulp.parallel(copyData, copySrcFiles))
gulp.task('build', build)
gulp.task('clean', clean)
gulp.task('default', gulp.series(clean, build, gulp.parallel(serve, watch)))
gulp.task('serve', gulp.parallel(serve, watch))
gulp.task('static', makeStatic)
const buildDir = path.join(__dirname, 'build')
const buildDataDir = path.join(buildDir, 'data')
const legendFile = path.join(__dirname, 'output/legend.json')
const mapFile = path.join(__dirname, 'output/language-areas.json')
const staticSrc = path.join(__dirname, 'www')
const staticSrcGlob = path.join(staticSrc, '**/*.*')
const staticTargetDir = __dirname
function clean() {
return del(buildDir)
}
function copyLegend() {
return gulp.src(legendFile)
.pipe(gulp.dest(buildDataDir))
}
function copyMap() {
return gulp.src(mapFile)
.pipe(gulp.dest(buildDataDir))
}
function copySrcFiles() {
return gulp.src(staticSrcGlob)
.pipe(gulp.dest(buildDir))
}
function makeStatic() {
return gulp.src(path.join(buildDir, '**/*.*'))
.pipe(gulp.dest(staticTargetDir))
}
function reload(done) {
browserSync.reload()
done()
}
function serve() {
return browserSync
.init({
server: {
baseDir: buildDir
},
// If this env variable is not defined, defaults to system default browser
browser: process.env.BROWSER,
host: '0.0.0.0'
})
}
function watch() {
gulp.watch([legendFile, mapFile, staticSrcGlob], gulp.series(clean, build, reload))
}