This repository was archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.ts
118 lines (97 loc) · 2.24 KB
/
gulpfile.ts
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// tslint:disable: no-implicit-dependencies
import * as del from 'del'
import * as gulp from 'gulp'
import * as sourcemaps from 'gulp-sourcemaps'
import tslint from 'gulp-tslint'
import * as ts from 'gulp-typescript'
import { Linter } from 'tslint'
const OUTPUT = 'bin'
let _project: ts.Project | undefined
function getProject(): ts.Project {
if (_project === undefined) {
_project = ts.createProject('tsconfig.build.json', {
outDir: OUTPUT,
})
}
return _project
}
function reloadProject(): void {
_project = undefined
}
const transpile: gulp.TaskFunction = () => {
const tsProject = getProject()
const result =
tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.write('', {
includeContent: false,
}))
.pipe(gulp.dest(OUTPUT))
return result
}
const clean: gulp.TaskFunction = async () => {
await del([
`${OUTPUT}/**`,
])
}
const lint: gulp.TaskFunction = () => {
const tsProject = getProject()
const linter = Linter.createProgram(tsProject.configFileName)
const result =
tsProject.src()
.pipe(tslint({
formatter: 'verbose',
program: linter,
}))
.pipe(tslint.report({
summarizeFailureOutput: true,
}))
return result
}
const build: gulp.TaskFunction = gulp.parallel(
lint,
gulp.series(
clean,
transpile,
),
)
const watchTs: gulp.TaskFunction = () => {
const tsProject = getProject()
const result =
gulp.watch([
// tslint:disable-next-line: no-non-null-assertion
...tsProject.config.include!,
],
gulp.parallel(
transpile,
lint,
))
return result
}
const watchTsConfig: gulp.TaskFunction = () => {
const result =
gulp.watch([
'tsconfig.json',
'tsconfig.build.json',
],
done => {
reloadProject()
done()
})
return result
}
const watch: gulp.TaskFunction = gulp.series(
build,
gulp.parallel(
watchTs,
watchTsConfig,
),
)
export {
build,
clean,
lint,
watch,
}
export default build