Skip to content

Commit 55b5ecd

Browse files
authored
updates to help sdk generation (#517)
* updates to help sdk generation * updates
1 parent 28c11a0 commit 55b5ecd

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/scripts/generate-sdk.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
1-
import { execSync, spawn } from "child_process";
1+
import { execSync } from "child_process";
22
import fs from "fs";
3+
import { kill } from "process";
4+
5+
const ENGINE_OPENAPI_URL = "https://demo.web3api.thirdweb.com/json";
36

47
async function main() {
5-
const child = spawn("yarn", ["dev"], { detached: true });
6-
if (!child.pid) return;
8+
try {
9+
const response = await fetch(ENGINE_OPENAPI_URL);
10+
const jsonData = await response.json();
711

8-
await new Promise((resolve) => setTimeout(resolve, 10000));
9-
process.kill(-child.pid);
12+
// Save the JSON response to a file
13+
fs.writeFileSync(
14+
"./dist/openapi.json",
15+
JSON.stringify(jsonData, null, 2),
16+
"utf-8",
17+
);
1018

11-
execSync(
12-
"yarn openapi --input ./dist/openapi.json --output ./sdk/src --name Engine",
13-
);
19+
execSync(
20+
"yarn openapi --input ./dist/openapi.json --output ./sdk/src --name Engine",
21+
);
1422

15-
const code = fs
16-
.readFileSync("./sdk/src/Engine.ts", "utf-8")
17-
.replace(`export class Engine`, `class EngineLogic`).concat(`
23+
const code = fs
24+
.readFileSync("./sdk/src/Engine.ts", "utf-8")
25+
.replace(`export class Engine`, `class EngineLogic`).concat(`
1826
export class Engine extends EngineLogic {
1927
constructor(config: { url: string; accessToken: string; }) {
2028
super({ BASE: config.url, TOKEN: config.accessToken });
2129
}
2230
}
2331
`);
24-
fs.writeFileSync("./sdk/src/Engine.ts", code);
32+
fs.writeFileSync("./sdk/src/Engine.ts", code);
33+
} catch (error) {
34+
console.error("Error:", error);
35+
kill(process.pid, "SIGINT");
36+
}
2537
}
2638

2739
main();

0 commit comments

Comments
 (0)