forked from soundxyz/sound-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
87 lines (77 loc) · 2.3 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
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
86
87
import makePublishManifestPkg from "@pnpm/exportable-manifest";
import type { ProjectManifest } from "@pnpm/types";
import { buildCode } from "bob-ts";
import { execaCommand } from "execa";
import { copy, ensureDir } from "fs-extra";
import { rm, writeFile } from "fs/promises";
import pkg from "./package.json";
const makePublishManifest = getDefault(makePublishManifestPkg);
await rm("dist", {
force: true,
recursive: true,
});
await copy("typechain", "src/typechain");
const tsc = execaCommand("tsc -p tsconfig.build.json", {
stdio: "inherit",
});
await ensureDir("dist");
await Promise.all([
copy("LICENSE", "dist/LICENSE"),
copy("contracts", "dist/contracts"),
writeFile(
"dist/package.json",
JSON.stringify(
await makePublishManifest(".", {
name: pkg.name,
version: pkg.version,
author: pkg.author,
homepage: pkg.homepage,
main: "index.js",
module: "index.mjs",
types: "index.d.ts",
dependencies: pkg.dependencies,
license: pkg.license,
repository: pkg.repository,
sideEffects: false,
exports: {
".": {
types: "./index.d.ts",
require: "./index.js",
import: "./index.mjs",
},
"./typechain": {
types: "./typechain/index.d.ts",
require: "./typechain/index.js",
import: "./typechain/index.mjs",
},
"./*": {
types: "./*.d.ts",
require: "./*.js",
import: "./*.mjs",
},
},
} as ProjectManifest),
null,
2
)
),
]);
await buildCode({
clean: false,
entryPoints: ["src"],
format: "interop",
outDir: "dist",
target: "node14",
sourcemap: false,
rollup: {
exports: "auto",
},
});
await tsc;
await rm("src/typechain", {
recursive: true,
force: true,
});
function getDefault<T>(v: T | { default?: T }) {
return (("default" in v ? v.default : v) || v) as T;
}