-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
54 lines (43 loc) · 1.33 KB
/
esbuild.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
/* eslint node/no-unpublished-require: 0 */
/* eslint no-unused-vars: 0 */
import * as utils from "@switchboard-xyz/common/esm-utils";
import { execSync } from "child_process";
import fs from "fs";
import fsPromises from "fs/promises";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const buildFiles = ["tsconfig.tsbuildinfo"];
const outDir = path.join(__dirname, "dist");
async function main() {
await Promise.all([
fsPromises.rm(outDir, { recursive: true, force: true }),
fsPromises.rm(path.join(__dirname, "dist-cjs"), {
recursive: true,
force: true,
}),
buildFiles.map((f) => fsPromises.rm(f, { force: true })),
]);
fs.mkdirSync(outDir, { recursive: true });
execSync(`pnpm exec tsc --removeComments --outDir dist`, {
encoding: "utf-8",
});
execSync(
`pnpm exec tsc --removeComments --outDir dist-cjs -p tsconfig.cjs.json`,
{
encoding: "utf-8",
}
);
await utils
.moveCjsFilesAsync("dist-cjs", "dist")
.then(() => fsPromises.rm("dist-cjs", { recursive: true, force: true }));
console.log(`Generating entrypoints ...`);
utils.generateEntrypoints(__dirname, "dist", {
index: "index",
});
}
main().catch((error) => {
console.error(error);
throw error;
});