Skip to content

Commit 1dd87fa

Browse files
Handle unique OpenAPI tags in engine sdk
1 parent 7cb2cfc commit 1dd87fa

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/scripts/generate-sdk.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,31 @@ async function main() {
2323

2424
const code = fs
2525
.readFileSync("./sdk/src/Engine.ts", "utf-8")
26-
.replace("export class Engine", "class EngineLogic")
27-
.concat(`
26+
.replace("export class Engine", "class EngineLogic").concat(`
2827
export class Engine extends EngineLogic {
2928
constructor(config: { url: string; accessToken: string; }) {
3029
super({ BASE: config.url, TOKEN: config.accessToken });
3130
}
3231
}
3332
`);
3433
fs.writeFileSync("./sdk/src/Engine.ts", code);
34+
35+
const tagsToReplace = ['erc20', 'erc721', 'erc1155'];
36+
tagsToReplace.forEach((tag) => {
37+
const fileName = `${tag.charAt(0).toUpperCase() + tag.slice(1)}Service.ts`;
38+
console.log(fileName);
39+
let code = fs.readFileSync(`./sdk/src/services/${fileName}`, "utf-8");
40+
// replace erc methods to avoid duplication with the tag
41+
// find all methods that start with 'ercX', remove 'ercX' from the name and lowercase the first letter
42+
const regex = new RegExp(`public\\s+${tag}(\\w+)\\(`, 'g');
43+
const methods = code.match(regex);
44+
methods?.forEach((method) => {
45+
const newMethod = method.replace(regex, (_, p1) => `public ${p1.charAt(0).toLowerCase() + p1.slice(1)}(`);
46+
code = code.replace(method, newMethod);
47+
});
48+
fs.writeFileSync(`./sdk/src/services/${fileName}`, code);
49+
});
50+
3551
} catch (error) {
3652
console.error("Error:", error);
3753
kill(process.pid, "SIGINT");

0 commit comments

Comments
 (0)