-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
102 lines (90 loc) · 2.39 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
95
96
97
98
99
100
101
102
'use strict'
const gulp = require('gulp')
const browserify = require('browserify')
const tsify = require('tsify')
const babelify = require('babelify')
const source = require('vinyl-source-stream')
const buffer = require('vinyl-buffer')
const sourcemaps = require('gulp-sourcemaps')
const browserSync = require('browser-sync').create()
const sass = require('gulp-sass')
const cleanCSS = require('gulp-clean-css')
const log = require('fancy-log')
function bundleHandler (name) {
return function bundle () {
return browserify({ standalone: name })
.add([
`./src/${name}/view_model.ts`
])
.plugin(tsify)
.transform(babelify, { extensions: ['.tsx', '.ts'] })
.bundle().on('error', log)
.pipe(source(`${name}.js`))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./docs/js'))
.pipe(browserSync.stream({ once: true }))
}
}
function serveHandler (name) {
return function serve () {
return browserSync.init({
server: 'docs',
startPath: `/${name}.html`
})
}
}
function watchHandler (name, bundlerName) {
return function watch () {
gulp.watch(
[
`./src/${name}/*.ts`,
'./src/main/*.ts'
],
gulp.series(bundlerName, 'browserSyncReload')
)
gulp.watch(
'./docs/scss/**/*.scss',
gulp.series('css', 'browserSyncReload')
)
}
}
gulp.task('browserSyncReload', function (done) {
browserSync.reload()
done()
})
gulp.task('css', function () {
return gulp
.src('./docs/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(cleanCSS({ level: { 2: { all: true } } }))
.pipe(gulp.dest('./docs/css'))
})
/* Bundlers */
gulp.task('bundleValidation', bundleHandler('validation'))
gulp.task('bundleVisualization', bundleHandler('visualization'))
/* Servers */
gulp.task('serveValidation', gulp.series(
'css',
'bundleValidation',
gulp.parallel(
serveHandler('validation'),
watchHandler('validation', 'bundleValidation')
)
))
gulp.task('serveVisualization', gulp.series(
'css',
'bundleVisualization',
gulp.parallel(
serveHandler('visualization'),
watchHandler('visualization', 'bundleVisualization')
)
))
/* Bundle all the demos */
gulp.task('bundleAll', gulp.series(
'css',
'bundleValidation',
'bundleVisualization'
))
gulp.task('serve', gulp.series('serveValidation'))