-
Notifications
You must be signed in to change notification settings - Fork 0
/
kinobi.mjs
40 lines (33 loc) · 1.01 KB
/
kinobi.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
import path from "path";
import { fileURLToPath } from "url";
import {
renderRustVisitor,
renderJavaScriptVisitor,
} from "@kinobi-so/renderers";
import { rootNodeFromAnchor } from "@kinobi-so/nodes-from-anchor";
import { readJson } from "@kinobi-so/renderers-core";
import { visit } from "@kinobi-so/visitors-core";
import fs from "fs/promises";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const clientDir = path.join(__dirname, "clients");
const idlDir = path.join(__dirname, "target", "idl");
const idlFiles = await fs.readdir(idlDir);
for (const idlFile of idlFiles) {
const idlPath = path.join(idlDir, idlFile);
const idl = readJson(idlPath);
const node = rootNodeFromAnchor(idl);
const sdkName = idl.metadata.name;
await visit(
node,
renderJavaScriptVisitor(
path.join(clientDir, "js", sdkName, "src", "generated")
)
);
visit(
node,
renderRustVisitor(
path.join(clientDir, "rust", sdkName, "src", "generated"),
{ format: true }
)
);
}