-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
81 lines (63 loc) · 2.03 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
const gulp = require('gulp')
const ts = require('gulp-typescript')
const { Transform } = require('stream')
const merge = require('merge2')
const minify = require('gulp-minify')
const pump = require('pump')
const sourcemaps = require('gulp-sourcemaps')
const TS_SETTINGS = {
declaration: true,
target: 'esnext',
lib: ['es2017'],
moduleResolution: 'node',
module: 'commonjs',
importHelpers: true,
inlineSourceMap: true,
listFiles: false,
traceResolution: false,
pretty: true
}
const TS_BROWSER_SETTINGS = Object.assign({}, TS_SETTINGS, {
declaration: false,
target: 'es5',
lib: ['es5', 'dom']
})
const serverTS = ts.createProject(TS_SETTINGS)
gulp.task('server', function () {
const tsResult = gulp.src(['src/plugin/**/*.ts', 'src/lib/**/*.ts', 'src/api/**/*.ts', 'src/test/**/*.ts', 'src/index.ts'], {
base: 'src/'
}).pipe(serverTS())
return merge([
tsResult.dts.pipe(gulp.dest('build/')),
tsResult.js.pipe(gulp.dest('build/'))
])
})
const snippetTS = ts.createProject(TS_BROWSER_SETTINGS)
gulp.task('snippet', function () {
const tsResult = gulp.src('src/snippet/**/*.ts')
.pipe(snippetTS())
return merge([
tsResult.js.pipe(gulp.dest('build/snippet'))
])
})
const resourcesTS = ts.createProject(TS_BROWSER_SETTINGS)
gulp.task('test-resources', function () {
const tsResult = gulp.src('src/test-resources/**/*.ts')
.pipe(sourcemaps.init())
.pipe(resourcesTS())
const webrequire = require('.').default
return merge([
tsResult.dts.pipe(gulp.dest('build/test-resources')),
tsResult.js
.pipe(webrequire().through())
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/test-resources')).on('error', err => console.log(err.toString()))
])
})
gulp.task('watch', function () {
gulp.watch(['src/plugin/**/*.ts', 'src/lib/**/*.ts', 'src/api/**/*.ts', 'src/test/**/*.ts'], ['server'])
gulp.watch('src/snippet/**/*.ts', ['snippet'])
gulp.watch('src/test-resources/**/*.ts', ['test-resources'])
})
gulp.task('all', ['server', 'snippet'])
gulp.task('default', ['all', 'watch'])