Skip to content
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

allow ref names in dojoprovider #97

Merged
merged 6 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ jobs:
- uses: actions/checkout@v2
- uses: oven-sh/setup-bun@v1

- name: Install dependencies
- name: Install Protobuf Compiler
run: sudo apt-get install -y protobuf-compiler

- name: Link dependencies
run: bun link

- name: Install dependencies
Expand All @@ -22,6 +25,9 @@ jobs:
- name: Run Prettier
run: bun x prettier --check .

- name: Build dependencies
run: bun run build

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
Expand Down
Binary file modified bun.lockb
Binary file not shown.
32 changes: 24 additions & 8 deletions packages/core/bin/generateComponents.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");

const parseModelName = (model) => {
// Define a set of known acronyms
const acronyms = new Set(["ERC"]);

return model.name
.split("::")
.pop()
.split("_")
.map((part) => {
// If the part is a known acronym, keep it in uppercase
if (acronyms.has(part.toUpperCase())) {
return part.toUpperCase();
}
// If the part is fully numeric, keep it as is
if (!isNaN(parseInt(part))) {
return part;
}
// Capitalize the first letter and make the rest lowercase
return part.charAt(0).toUpperCase() + part.slice(1).toLowerCase();
})
.join("");
};

// Check for the required arguments
if (process.argv.length !== 6) {
console.log(
Expand Down Expand Up @@ -52,14 +75,7 @@ manifest.models.forEach((model) => {
const types = [];
const customTypes = [];

let result = model.name.split("::").pop().split("_");
let modelName = result
.map((part) => {
return part === part.toLowerCase() && part.length > 2
? part.charAt(0).toUpperCase() + part.slice(1)
: part.toUpperCase();
})
.join("");
let modelName = parseModelName(model);

try {
const output = execSync(
Expand Down
36 changes: 35 additions & 1 deletion packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,41 @@ export const getContractByName = (manifest: any, name: string) => {
return (
manifest.contracts.find((contract: any) => {
const nameParts = contract.name.split("::");
return nameParts[nameParts.length - 1] === name;
// Check if the last part matches or if the full name matches
return (
nameParts[nameParts.length - 1] === name ||
contract.name === name
);
})?.address || ""
);
};

/**
* Parses a model name into a class name.
*
* @param {any} model - The model object.
* @returns {string} The class name.
*
*/
export const parseModelName = (model: any) => {
// Define a set of known acronyms
const acronyms = new Set(["ERC"]);

return model.name
.split("::")
.pop()
.split("_")
.map((part: string) => {
// If the part is a known acronym, keep it in uppercase
if (acronyms.has(part.toUpperCase())) {
return part.toUpperCase();
}
// If the part is fully numeric, keep it as is
if (!isNaN(parseInt(part))) {
return part;
}
// Capitalize the first letter and make the rest lowercase
return part.charAt(0).toUpperCase() + part.slice(1).toLowerCase();
})
.join("");
};
Loading
Loading