|
1 |
| -import { execSync, spawn } from "child_process"; |
| 1 | +import { execSync } from "child_process"; |
2 | 2 | import fs from "fs";
|
| 3 | +import { kill } from "process"; |
| 4 | + |
| 5 | +const ENGINE_OPENAPI_URL = "https://demo.web3api.thirdweb.com/json"; |
3 | 6 |
|
4 | 7 | 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(); |
7 | 11 |
|
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 | + ); |
10 | 18 |
|
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 | + ); |
14 | 22 |
|
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(` |
18 | 26 | export class Engine extends EngineLogic {
|
19 | 27 | constructor(config: { url: string; accessToken: string; }) {
|
20 | 28 | super({ BASE: config.url, TOKEN: config.accessToken });
|
21 | 29 | }
|
22 | 30 | }
|
23 | 31 | `);
|
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 | + } |
25 | 37 | }
|
26 | 38 |
|
27 | 39 | main();
|
0 commit comments