-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-registry.mjs
53 lines (43 loc) · 1.73 KB
/
gen-registry.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
import { writeFileSync } from "fs";
import { compile } from "json-schema-to-typescript";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
async function genChainRegistryChainInfo() {
const tsName = "ChainRegistryChainInfo";
const tsFile = tsName + ".ts";
console.log("Retrieving JSON schema...");
const res = await fetch(
"https://raw.githubusercontent.com/cosmos/chain-registry/master/chain.schema.json"
);
const schema = await res.json();
schema.title = tsName;
console.log("Compiling JSON schema to TypeScript...");
const types = await compile(schema, tsName, {
// See: https://github.com/bcherny/json-schema-to-typescript?tab=readme-ov-file#options
strictIndexSignatures: true,
});
const target = join(__dirname, "..", "src", "registry", "types", tsFile);
writeFileSync(target, types);
console.log("Wrote types to", target);
}
async function genChainRegistryAssetList() {
const tsName = "ChainRegistryAssetList";
const tsFile = tsName + ".ts";
console.log("Retrieving JSON schema...");
const res = await fetch(
"https://raw.githubusercontent.com/cosmos/chain-registry/master/assetlist.schema.json"
);
const schema = await res.json();
schema.title = tsName;
console.log("Compiling JSON schema to TypeScript...");
const types = await compile(schema, tsName, {
// See: https://github.com/bcherny/json-schema-to-typescript?tab=readme-ov-file#options
strictIndexSignatures: true,
});
const target = join(__dirname, "..", "src", "registry", "types", tsFile);
writeFileSync(target, types);
console.log("Wrote types to", target);
}
await genChainRegistryChainInfo();
await genChainRegistryAssetList();