Skip to content

updates to help sdk generation #517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions src/scripts/generate-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import { execSync, spawn } from "child_process";
import { execSync } from "child_process";
import fs from "fs";
import { kill } from "process";

const ENGINE_OPENAPI_URL = "https://demo.web3api.thirdweb.com/json";

async function main() {
const child = spawn("yarn", ["dev"], { detached: true });
if (!child.pid) return;
try {
const response = await fetch(ENGINE_OPENAPI_URL);
const jsonData = await response.json();

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

execSync(
"yarn openapi --input ./dist/openapi.json --output ./sdk/src --name Engine",
);
execSync(
"yarn openapi --input ./dist/openapi.json --output ./sdk/src --name Engine",
);

const code = fs
.readFileSync("./sdk/src/Engine.ts", "utf-8")
.replace(`export class Engine`, `class EngineLogic`).concat(`
const code = fs
.readFileSync("./sdk/src/Engine.ts", "utf-8")
.replace(`export class Engine`, `class EngineLogic`).concat(`
export class Engine extends EngineLogic {
constructor(config: { url: string; accessToken: string; }) {
super({ BASE: config.url, TOKEN: config.accessToken });
}
}
`);
fs.writeFileSync("./sdk/src/Engine.ts", code);
fs.writeFileSync("./sdk/src/Engine.ts", code);
} catch (error) {
console.error("Error:", error);
kill(process.pid, "SIGINT");
}
}

main();
Loading