-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.ts
46 lines (42 loc) · 1.05 KB
/
build.ts
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
import fs from "fs";
import path from "path";
import glob from "fast-glob";
import { build, BuildOptions } from "esbuild";
(async () => {
const entryPoints = [];
const srcdir = path.resolve("src");
const outdir = path.resolve("dist");
const files = glob.stream(["**", "!*.d.ts", "!**/__tests__"], {
cwd: srcdir,
}) as AsyncIterable<string>;
for await (const file of files) {
if (path.extname(file) === ".ts") {
entryPoints.push(path.resolve(srcdir, file));
} else {
const outfile = path.join(outdir, file);
await fs.promises.mkdir(path.dirname(outfile), { recursive: true });
await fs.promises.copyFile(path.join(srcdir, file), outfile);
}
}
const opts: BuildOptions = {
outdir,
entryPoints,
outbase: srcdir,
platform: "node",
target: ["node14"],
};
await Promise.all([
build({
...opts,
format: "cjs",
}),
build({
...opts,
format: "esm",
outExtension: { ".js": ".mjs" },
}),
]);
})().catch((err) => {
console.error(err);
process.exit(1);
});