-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.mjs
58 lines (50 loc) · 1.49 KB
/
tsup.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
import { execSync } from "node:child_process";
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { build } from "tsup";
const VERSION = process.argv[2] ?? "dev";
const BANNER = `/**
**
**
**
** This file has been generated from source code in https://github.com/Gearbox-protocol/defillama repo
** Binary release: https://github.com/Gearbox-protocol/defillama/releases/tag/v${VERSION}
**
**
**
**/`;
/**
* For some reason, esbuild banner is not on top of the file
*/
async function addBanner(file) {
const content = await readFile(file, "utf-8");
await writeFile(file, content.replace("'use strict';", BANNER), "utf-8");
}
async function aliasDefillamaApi(file) {
const content = await readFile(file, "utf-8");
await writeFile(
file,
content.replace("@defillama/sdk", "@defillama/sdk5"),
"utf-8",
);
}
await build({
entry: ["src/adapter/index.ts", "src/yield-server/index.ts"],
outDir: "dist",
splitting: false,
sourcemap: false,
clean: true,
treeshake: true,
target: "node18",
external: ["../helper/cache/getLogs", "../utils", "ethers", "@defillama/sdk"],
});
await addBanner("dist/adapter/index.js");
await addBanner("dist/yield-server/index.js");
await aliasDefillamaApi("dist/yield-server/index.js");
const prettierPath = join(process.cwd(), "node_modules", ".bin", "prettier");
execSync(
`${prettierPath} --ignore-path '' --arrow-parens always --trailing-comma es5 --write ./dist`,
{
stdio: "inherit",
},
);