Skip to content

Commit

Permalink
Handle unique OpenAPI tags in engine sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges committed Oct 13, 2024
1 parent 7cb2cfc commit 1dd87fa
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/scripts/generate-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,31 @@ async function main() {

const code = fs
.readFileSync("./sdk/src/Engine.ts", "utf-8")
.replace("export class Engine", "class EngineLogic")
.concat(`
.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);

const tagsToReplace = ['erc20', 'erc721', 'erc1155'];
tagsToReplace.forEach((tag) => {
const fileName = `${tag.charAt(0).toUpperCase() + tag.slice(1)}Service.ts`;
console.log(fileName);
let code = fs.readFileSync(`./sdk/src/services/${fileName}`, "utf-8");
// replace erc methods to avoid duplication with the tag
// find all methods that start with 'ercX', remove 'ercX' from the name and lowercase the first letter
const regex = new RegExp(`public\\s+${tag}(\\w+)\\(`, 'g');
const methods = code.match(regex);
methods?.forEach((method) => {
const newMethod = method.replace(regex, (_, p1) => `public ${p1.charAt(0).toLowerCase() + p1.slice(1)}(`);
code = code.replace(method, newMethod);
});
fs.writeFileSync(`./sdk/src/services/${fileName}`, code);
});

} catch (error) {
console.error("Error:", error);
kill(process.pid, "SIGINT");
Expand Down

0 comments on commit 1dd87fa

Please sign in to comment.