forked from spacebudz/lucid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
100 lines (90 loc) · 2.95 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
88
89
90
91
92
93
94
95
96
97
98
99
100
import { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts";
import * as esbuild from "https://deno.land/x/[email protected]/mod.js";
import packageInfo from "./package.json" assert { type: "json" };
await emptyDir("./dist");
//** NPM ES Module for Node.js and Browser */
await build({
entryPoints: ["./mod.ts"],
outDir: "./dist",
test: false,
scriptModule: false,
typeCheck: false,
shims: {},
package: {
...packageInfo,
engines: {
node: ">=14",
},
dependencies: {
"node-fetch": "^3.2.3",
"@peculiar/webcrypto": "^1.4.0",
"ws": "^8.10.0",
},
main: "./esm/mod.js",
type: "module",
},
});
Deno.copyFileSync("LICENSE", "dist/LICENSE");
Deno.copyFileSync("README.md", "dist/README.md");
// copy wasm files
// Core
Deno.copyFileSync(
"src/core/wasm_modules/cardano_multiplatform_lib_nodejs/cardano_multiplatform_lib_bg.wasm",
"dist/esm/src/core/wasm_modules/cardano_multiplatform_lib_nodejs/cardano_multiplatform_lib_bg.wasm",
);
Deno.writeTextFileSync(
"dist/esm/src/core/wasm_modules/cardano_multiplatform_lib_nodejs/package.json",
JSON.stringify({ type: "commonjs" }),
);
Deno.copyFileSync(
"src/core/wasm_modules/cardano_multiplatform_lib_web/cardano_multiplatform_lib_bg.wasm",
"dist/esm/src/core/wasm_modules/cardano_multiplatform_lib_web/cardano_multiplatform_lib_bg.wasm",
);
// Message
Deno.copyFileSync(
"src/core/wasm_modules/cardano_message_signing_nodejs/cardano_message_signing_bg.wasm",
"dist/esm/src/core/wasm_modules/cardano_message_signing_nodejs/cardano_message_signing_bg.wasm",
);
Deno.writeTextFileSync(
"dist/esm/src/core/wasm_modules/cardano_message_signing_nodejs/package.json",
JSON.stringify({ type: "commonjs" }),
);
Deno.copyFileSync(
"src/core/wasm_modules/cardano_message_signing_web/cardano_message_signing_bg.wasm",
"dist/esm/src/core/wasm_modules/cardano_message_signing_web/cardano_message_signing_bg.wasm",
);
//** Web ES Module */
// Core
Deno.mkdirSync("dist/web/wasm_modules/cardano_multiplatform_lib_web", {
recursive: true,
});
// Message
Deno.mkdirSync("dist/web/wasm_modules/cardano_message_signing_web", {
recursive: true,
});
await esbuild.build({
bundle: true,
format: "esm",
entryPoints: ["./dist/esm/mod.js"],
outfile: "./dist/web/mod.js",
minify: true,
external: [
"./wasm_modules/cardano_multiplatform_lib_nodejs/cardano_multiplatform_lib.js",
"./wasm_modules/cardano_message_signing_nodejs/cardano_message_signing.js",
"node-fetch",
"@peculiar/webcrypto",
"ws",
],
});
esbuild.stop();
// copy wasm file
// Core
Deno.copyFileSync(
"src/core/wasm_modules/cardano_multiplatform_lib_web/cardano_multiplatform_lib_bg.wasm",
"dist/web/wasm_modules/cardano_multiplatform_lib_web/cardano_multiplatform_lib_bg.wasm",
);
// Message
Deno.copyFileSync(
"src/core/wasm_modules/cardano_message_signing_web/cardano_message_signing_bg.wasm",
"dist/web/wasm_modules/cardano_message_signing_web/cardano_message_signing_bg.wasm",
);