-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
59 lines (50 loc) · 1.51 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
/* eslint-disable spellcheck/spell-checker */
const gulp = require('gulp');
const ts = require('gulp-typescript');
const mergeStream = require('merge-stream');
const sourcemaps = require('gulp-sourcemaps');
const cleanPackageJson = require('gulp-clean-package');
const buildDir = 'dist';
// Helpers
function tsCompilerFactory(outPath, settings) {
return function compileTS() {
const tsProject = ts.createProject('tsconfig.json', settings);
return gulp
.src(['src/**/!(*.test).{ts,tsx}'])
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.write())
.pipe(gulp.dest(outPath));
};
}
// Main
function build() {
return gulp.parallel([
// Compile TS files
Object.assign(tsCompilerFactory(buildDir, { module: 'commonjs' }), {
displayName: 'TSC:esnext',
}),
// Copy js files and declarations
Object.assign(
function copyNotTranspilableSources() {
return gulp.src([`src/**/!(*.test).{js,d.ts}`]).pipe(gulp.dest(buildDir));
},
{
displayName: 'CopyPureSources:esnext',
},
),
]);
}
function copyMetaFiles() {
return mergeStream(
// Clean package.json
gulp.src(['package.json']).pipe(cleanPackageJson()),
// Copy other
gulp.src(['README.md', 'LICENSE']),
// Disable encoding for images https://github.com/gulpjs/gulp/issues/2803#issuecomment-2106926786
gulp.src(['docs/*'], { encoding: false }).pipe(gulp.dest(buildDir + '/docs')),
).pipe(gulp.dest(buildDir));
}
// Compilations
const fullBuild = gulp.series([copyMetaFiles, build()]);
module.exports.default = fullBuild;