This repository has been archived by the owner on Nov 9, 2023. It is now read-only.
forked from translate-tools/core
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
80 lines (67 loc) · 1.84 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 ts = require('gulp-typescript');
const mergeStream = require('merge-stream');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const cleanPackageJson = require('./scripts/gulp/cleanPackageJson');
const buildDir = 'dist';
// Helpers
function tsCompilerFactory(outPath, settings) {
return function compileTS() {
const tsProject = ts.createProject('tsconfig.json', settings);
return gulp
.src(['src/**/*.{ts,tsx}'])
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.write())
.pipe(gulp.dest(outPath));
};
}
function copyNotTranspilableSourcesFactory(outPath) {
return function copyNotTranspilableSources() {
return gulp.src([`src/**/*.{js,d.ts}`]).pipe(gulp.dest(outPath));
};
}
// Main
function buildESM() {
const out = `${buildDir}/esm`;
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 makeCJSFromESM() {
const esm = `${buildDir}/esm`;
const out = buildDir;
return mergeStream(
// Copy type declarations
gulp.src([`${esm}/**/*.ts`]),
// Convert to CJS
gulp
.src([`${esm}/**/*.js`])
.pipe(sourcemaps.init())
.pipe(
babel({
plugins: ['@babel/plugin-transform-modules-commonjs'],
}),
)
.pipe(sourcemaps.write()),
).pipe(gulp.dest(out));
}
function copyMetaFiles() {
return mergeStream(
// Clean package.json
gulp.src(['./package.json']).pipe(cleanPackageJson()),
// Copy other
gulp.src(['./README.md']),
).pipe(gulp.dest(buildDir));
}
// Compilations
const fullBuild = gulp.series([copyMetaFiles, buildESM(), makeCJSFromESM]);
module.exports.default = fullBuild;