-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathgulpfile.js
80 lines (73 loc) · 1.87 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
const gulp = require('gulp')
const del = require('del')
const rollupConfig = require('./rollup.config')
const rollup = require('rollup')
const ts = require('gulp-typescript')
const through = require('through2')
const tsconfig = require('./tsconfig.json')
gulp.task('clean-lib', function (callback) {
del('lib/**')
callback()
})
gulp.task('copy-files', function () {
return gulp.src(['README.md', 'LICENSE']).pipe(gulp.dest('lib/'))
})
gulp.task('ts-es', function () {
const tsProject = ts({
...tsconfig.compilerOptions,
module: 'ES6',
})
return gulp
.src(['src/**/*.{ts,tsx}'], {
ignore: ['**/demos/**/*', '**/tests/**/*'],
})
.pipe(tsProject)
.pipe(gulp.dest('lib/es/'))
})
gulp.task('generate-package-json', function () {
return gulp
.src('./package.json')
.pipe(
through.obj((file, enc, cb) => {
const rawJSON = file.contents.toString()
const parsed = JSON.parse(rawJSON)
delete parsed.scripts
delete parsed.devDependencies
delete parsed.publishConfig
delete parsed.files
delete parsed.resolutions
delete parsed.packageManager
const stringified = JSON.stringify(parsed, null, 2)
file.contents = Buffer.from(stringified)
cb(null, file)
})
)
.pipe(gulp.dest('./lib/'))
})
gulp.task('ts-cjs', function () {
const tsProject = ts({
...tsconfig.compilerOptions,
module: 'commonjs',
})
return gulp
.src(['src/**/*.{ts,tsx}'], {
ignore: ['**/demos/**/*', '**/tests/**/*'],
})
.pipe(tsProject)
.pipe(gulp.dest('lib/cjs/'))
})
gulp.task('rollup', async function () {
const bundle = await rollup.rollup(rollupConfig)
return await bundle.write(rollupConfig.output)
})
gulp.task(
'build',
gulp.series(
'clean-lib',
'copy-files',
'generate-package-json',
'ts-es',
'ts-cjs',
'rollup'
)
)