From 14cfd2a5f255a9c521cd6ba21ca433ca2d00168a Mon Sep 17 00:00:00 2001 From: farhanW3 Date: Thu, 9 May 2024 17:18:56 -0700 Subject: [PATCH 1/2] updates to help sdk generation --- .github/workflows/npmPublish.yml | 7 ++++++ src/scripts/generate-sdk.ts | 43 +++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/.github/workflows/npmPublish.yml b/.github/workflows/npmPublish.yml index 7de7e2131..29469486c 100644 --- a/.github/workflows/npmPublish.yml +++ b/.github/workflows/npmPublish.yml @@ -21,6 +21,13 @@ jobs: - name: Install tsx run: npm install -g tsx + - name: Install tsx + run: npm install -g dotenv + + - name: Create .env file + run: | + echo "ENGINE_OPENAPI_URL=${{ secrets.ENGINE_OPENAPI_URL }}" >> .env + - name: Install dependencies working-directory: ./sdk run: yarn install diff --git a/src/scripts/generate-sdk.ts b/src/scripts/generate-sdk.ts index 8ad7d3468..dec2f6d65 100644 --- a/src/scripts/generate-sdk.ts +++ b/src/scripts/generate-sdk.ts @@ -1,27 +1,46 @@ -import { execSync, spawn } from "child_process"; +import { execSync } from "child_process"; +import dotenv from "dotenv"; import fs from "fs"; +import { kill } from "process"; + +dotenv.config(); + +const ENGINE_OPENAPI_URL = process.env.ENGINE_OPENAPI_URL; async function main() { - const child = spawn("yarn", ["dev"], { detached: true }); - if (!child.pid) return; + try { + console.log("ENGINE_OPENAPI_URL:", ENGINE_OPENAPI_URL); + if (!ENGINE_OPENAPI_URL) { + throw new Error("ENGINE_OPENAPI_URL is not defined"); + } + 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(); From 292d30cdc1fdc80a43a98e03a055f449f130f9ad Mon Sep 17 00:00:00 2001 From: farhanW3 Date: Thu, 9 May 2024 17:26:41 -0700 Subject: [PATCH 2/2] updates --- .github/workflows/npmPublish.yml | 7 ------- src/scripts/generate-sdk.ts | 9 +-------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/.github/workflows/npmPublish.yml b/.github/workflows/npmPublish.yml index 29469486c..7de7e2131 100644 --- a/.github/workflows/npmPublish.yml +++ b/.github/workflows/npmPublish.yml @@ -21,13 +21,6 @@ jobs: - name: Install tsx run: npm install -g tsx - - name: Install tsx - run: npm install -g dotenv - - - name: Create .env file - run: | - echo "ENGINE_OPENAPI_URL=${{ secrets.ENGINE_OPENAPI_URL }}" >> .env - - name: Install dependencies working-directory: ./sdk run: yarn install diff --git a/src/scripts/generate-sdk.ts b/src/scripts/generate-sdk.ts index dec2f6d65..96feedb62 100644 --- a/src/scripts/generate-sdk.ts +++ b/src/scripts/generate-sdk.ts @@ -1,18 +1,11 @@ import { execSync } from "child_process"; -import dotenv from "dotenv"; import fs from "fs"; import { kill } from "process"; -dotenv.config(); - -const ENGINE_OPENAPI_URL = process.env.ENGINE_OPENAPI_URL; +const ENGINE_OPENAPI_URL = "https://demo.web3api.thirdweb.com/json"; async function main() { try { - console.log("ENGINE_OPENAPI_URL:", ENGINE_OPENAPI_URL); - if (!ENGINE_OPENAPI_URL) { - throw new Error("ENGINE_OPENAPI_URL is not defined"); - } const response = await fetch(ENGINE_OPENAPI_URL); const jsonData = await response.json();