-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
76 lines (65 loc) · 1.82 KB
/
build.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
66
67
68
69
70
71
72
73
74
75
76
import path from "node:path";
import { globSync } from "glob";
import * as esbuild from "esbuild";
import * as tsup from "tsup";
import fs from "fs";
import CssModulesPlugin from "esbuild-css-modules-plugin";
async function build(relativePath) {
const tasks = [];
const pkg = relativePath.split(path.sep).slice(2)[0];
const files = ["index.ts"];
if (pkg === "everest-ui") {
files.push("internal.ts");
}
// Use POSIX paths for consistency across tools
const entryPoints = files
.map((file) => path.join(relativePath, "src", file).replace(/\\/g, "/"))
.filter((filePath) => fs.existsSync(filePath));
if (entryPoints.length === 0) {
console.log(`No entry points found for ${relativePath}`);
return;
}
const dist = path.join(relativePath, "dist").replace(/\\/g, "/");
const esbuildConfig = {
entryPoints,
external: ["@everest-ui/*"],
packages: "external",
bundle: true,
sourcemap: true,
format: "cjs",
target: "es2022",
outdir: dist,
plugins: [CssModulesPlugin],
};
console.log(`Building ${relativePath}...`);
tasks.push(
esbuild
.build(esbuildConfig)
.then(() => console.log(`CJS: Built ${relativePath}`)),
);
tasks.push(
esbuild
.build({
...esbuildConfig,
format: "esm",
outExtension: { ".js": ".mjs" },
})
.then(() => console.log(`ESM: Built ${relativePath}`)),
);
tasks.push(
tsup
.build({
entry: entryPoints,
format: ["cjs", "esm"],
dts: { only: true },
outDir: dist,
silent: false,
external: [/@everest-ui\/.+/],
css: true,
})
.then(() => console.log(`TSC: Built ${relativePath}`)),
);
await Promise.all(tasks);
}
globSync("packages/*/*").forEach((path) => build(path.replace(/\\/g, "/")));
function done() {}