-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
85 lines (70 loc) · 2.11 KB
/
gulpfile.js
File metadata and controls
85 lines (70 loc) · 2.11 KB
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
82
83
84
85
import path from 'node:path';
import fs from 'node:fs/promises';
import gulp from 'gulp';
import * as tsdown from 'tsdown';
import terser from 'gulp-plugin-terser';
const outDir = path.resolve(import.meta.dirname, 'dist');
const cleanOutDir = async function () {
await fs.rm(outDir, { recursive: true, force: true });
};
const compile = async function () {
const pkgString = await fs.readFile('./package.json', 'utf-8');
const pkg = JSON.parse(pkgString);
const banner = `/*!
* @module ${pkg.name}
* @description ${pkg.description}
* @version ${pkg.version}
* @link ${pkg.repository}
* @licence MIT License, https://opensource.org/licenses/MIT
*/`;
await tsdown.build({
entry: ['./capillaries.ts'],
format: ['esm', 'cjs'],
outDir: 'dist',
clean: true,
sourcemap: true,
dts: true,
minify: false,
esbuildOptions(options) {
options.banner = {
js: banner,
};
},
});
};
const minify = function () {
return gulp
.src('dist/*.js', { sourcemaps: true })
.pipe(terser())
.pipe(gulp.dest('dist', { sourcemaps: '.' }));
};
const preparePackageJson = async function () {
const targetPkgPath = path.resolve(outDir, 'package.json');
const jsonStr = await fs.readFile(targetPkgPath, 'utf-8');
const packageJson = JSON.parse(jsonStr);
packageJson.module = 'capillaries.mjs';
packageJson.types = 'capillaries.d.mts';
packageJson.main = 'capillaries.cjs';
packageJson.exports = {
'.': {
require: {
types: './capillaries.d.cts',
default: './capillaries.cjs',
},
import: {
types: './capillaries.d.mts',
default: './capillaries.mjs',
},
},
};
delete packageJson.scripts;
delete packageJson.devDependencies;
delete packageJson.private;
delete packageJson.engines;
await fs.writeFile(targetPkgPath, JSON.stringify(packageJson, null, 2));
};
const copyFiles = function () {
return gulp.src(['README.md', 'CHANGELOG.md', 'LICENSE', 'package.json']).pipe(gulp.dest(outDir));
};
export const build = gulp.series(cleanOutDir, compile, minify, copyFiles, preparePackageJson);
export default build;