-
Notifications
You must be signed in to change notification settings - Fork 43
/
gulpfile.js
100 lines (90 loc) · 2.41 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
/**
* @fileoverview Gulpfile for compiling project assets.
* @author [email protected] (Alvin Lin)
*/
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import * as del from 'del'
import browserify from 'browserify'
import gulp from 'gulp'
import gulpCssnano from 'gulp-cssnano'
import gulpLess from 'gulp-less'
import gulpTypescript from 'gulp-typescript'
import tsify from 'tsify'
import vinylBuffer from 'vinyl-buffer'
import vinylStream from 'vinyl-source-stream'
const clean = () => del.deleteAsync('dist')
const copyHTML = () => gulp.src('html/index.html').pipe(gulp.dest('dist/html'))
const watchHTML = () => gulp.watch('./html/*', copyHTML)
const copyIMG = () => gulp.src('img/*.png').pipe(gulp.dest('dist/img'))
const serverTypescriptFiles = [
'./src/server.ts',
'./src/server/*.ts',
'./src/lib/*.ts',
]
const compileTypescriptServer = () =>
gulp
.src(serverTypescriptFiles, { base: './src' })
.pipe(
gulpTypescript({
noImplicitAny: true,
target: 'es2015',
rootDir: './src',
removeComments: true,
moduleResolution: 'node',
module: 'es2020',
allowSyntheticDefaultImports: true,
}),
)
.pipe(gulp.dest('dist'))
const watchTypescriptServer = () =>
gulp.watch(serverTypescriptFiles, compileTypescriptServer)
// TODO(omgimanerd): Catch errors in stream and fail gracefully
const compileTypescriptClient = () =>
browserify({
entries: ['./src/client.ts'],
debug: true,
cache: {},
packageCache: {},
})
.plugin(tsify, { noImplicitAny: true, target: 'es6' })
.bundle()
.pipe(vinylStream('client.js'))
.pipe(vinylBuffer())
.pipe(gulp.dest('dist'))
const watchTypescriptClient = () =>
gulp.watch(
['./src/client/*.ts', './src/client.ts', './src/lib/*.ts'],
compileTypescriptClient,
)
const compileLess = () =>
gulp
.src('./less/*.less')
.pipe(gulpLess())
.pipe(gulpCssnano())
.pipe(gulp.dest('dist/css'))
const watchLess = () => gulp.watch('./less/*.less', compileLess)
const compile = gulp.parallel(
copyHTML,
copyIMG,
compileTypescriptServer,
compileTypescriptClient,
compileLess,
)
const watch = gulp.parallel(
watchTypescriptServer,
watchTypescriptClient,
watchLess,
watchHTML,
)
export {
clean,
copyHTML,
copyIMG,
compileTypescriptServer,
compileTypescriptClient,
compileLess,
watchLess,
compile,
watch,
watch as default,
}