Skip to content

Commit

Permalink
Merge pull request #97 from dojoengine/manifest-parse
Browse files Browse the repository at this point in the history
allow ref names in dojoprovider
  • Loading branch information
ponderingdemocritus authored Dec 23, 2023
2 parents 98bf326 + 4790c97 commit fdc7da5
Show file tree
Hide file tree
Showing 6 changed files with 2,152 additions and 10 deletions.
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

0 comments on commit fdc7da5

Please sign in to comment.