-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.mjs
65 lines (54 loc) · 1.55 KB
/
gulpfile.mjs
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
import { deleteAsync } from 'del';
import gulp from 'gulp';
import cleanPackageJson from 'gulp-clean-package';
import gulpSourceMaps from 'gulp-sourcemaps';
import gulpTypescript from 'gulp-typescript';
import mergeStream from 'merge-stream';
const buildDir = 'dist';
// Helpers
function tsCompilerFactory(outPath, settings) {
return function compileTS() {
const tsProject = gulpTypescript.createProject('tsconfig.json', settings);
return gulp
.src(['src/**/!(*.test).{ts,tsx}'])
.pipe(gulpSourceMaps.init())
.pipe(tsProject())
.pipe(gulpSourceMaps.write('./sourcemaps'))
.pipe(gulp.dest(outPath));
};
}
function copyNotTranspilableSourcesFactory(outPath) {
return function copyNotTranspilableSources() {
return gulp.src([`src/**/!(*.test).{js,d.ts}`]).pipe(gulp.dest(outPath));
};
}
// Main
function buildESM() {
const out = buildDir;
return gulp.parallel([
// Compile TS files
Object.assign(tsCompilerFactory(out, { module: 'esnext' }), {
displayName: 'TSC:esnext',
}),
// Copy js files and declarations
Object.assign(copyNotTranspilableSourcesFactory(out), {
displayName: 'CopyPureSources:esnext',
}),
]);
}
function copyMetaFiles() {
return mergeStream(
// Clean package.json
gulp
.src(['./package.json'])
.pipe(cleanPackageJson({ publicProperties: ['publishConfig'] })),
// Copy other
gulp.src(['README.md', 'LICENSE']),
).pipe(gulp.dest(buildDir));
}
function clean() {
return deleteAsync(buildDir);
}
// Compilations
const fullBuild = gulp.series([clean, copyMetaFiles, buildESM()]);
export default fullBuild;