-
Notifications
You must be signed in to change notification settings - Fork 347
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
Support Typescript generate scaffold #2111
Conversation
packages/cli/src/utils/utils.ts
Outdated
@@ -113,27 +114,131 @@ export function findReplace(manifest: string, replacer: RegExp, value: string): | |||
return manifest.replace(replacer, value); | |||
} | |||
|
|||
export function replaceArrayValueInTsManifest(manifest: string, key: string, newValue: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to generalise this. Im also a little confused with the naming. It says to replace an array value, but takes a key rather than an index.
packages/cli/src/utils/utils.ts
Outdated
@@ -113,27 +114,131 @@ export function findReplace(manifest: string, replacer: RegExp, value: string): | |||
return manifest.replace(replacer, value); | |||
} | |||
|
|||
export function replaceArrayValueInTsManifest(manifest: string, key: string, newValue: string): string { | |||
const start = manifest.indexOf(`${key}:`); | |||
if (start === -1) return manifest; // If the value is not found, return the original manifest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think rather than this function doing a no-op it would be better to throw and let the caller decide what to do.
Same with the open brackets check
packages/cli/src/utils/utils.ts
Outdated
if (start === -1) return manifest; // If the value is not found, return the original manifest | ||
|
||
let openBrackets = 0; | ||
let startIndex, endIndex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing types
packages/cli/src/utils/utils.ts
Outdated
let openBraces = 0; | ||
let startIndex = 0; | ||
const components: string[] = []; | ||
|
||
for (let i = 0; i < content.length; i++) { | ||
if (content[i] === '{') { | ||
if (openBraces === 0) startIndex = i; | ||
openBraces++; | ||
} else if (content[i] === '}') { | ||
openBraces--; | ||
if (openBraces === 0) { | ||
components.push(content.slice(startIndex, i + 1).trim()); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be deduped with above functions too
@@ -152,6 +160,23 @@ export function constructDatasources(userInput: UserInput): EthereumDs { | |||
|
|||
const assets = new Map([[abiName, {file: userInput.abiPath}]]); | |||
|
|||
if (isTs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for readability, reduced union types and easier testing it would be worth splitting these functions into yaml and TS versions
packages/cli/src/utils/utils.ts
Outdated
@@ -113,27 +114,131 @@ export function findReplace(manifest: string, replacer: RegExp, value: string): | |||
return manifest.replace(replacer, value); | |||
} | |||
|
|||
export function replaceArrayValueInTsManifest(manifest: string, key: string, newValue: string): string { | |||
const start = manifest.indexOf(`${key}:`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there are multiple occurrences?
[cleanEvents, cleanFunctions] = filterExistingMethods( | ||
selectedEvents, | ||
selectedFunctions, | ||
existingDs, | ||
address, | ||
yamlExtractor | ||
); | ||
|
||
constructedEvents = constructMethod<EventFragment>(cleanEvents); | ||
constructedFunctions = constructMethod<FunctionFragment>(cleanFunctions); | ||
|
||
const userInput: UserInput = { | ||
startBlock: startBlock, | ||
functions: constructedFunctions, | ||
events: constructedEvents, | ||
abiPath: `./abis/${abiFileName}`, | ||
address: address, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be de-duped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of minor things
if (casedInputAddress && d.options.address) { | ||
return casedInputAddress.toLowerCase() === d.options.address.toLowerCase(); | ||
return casedInputAddress === d.options.address.toLowerCase(); | ||
} | ||
return casedInputAddress === d.options.address || (!casedInputAddress && !d.options.address); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make much sense. The casedInputAddress === d.options.address
outside of the if will always be false.
Also why is .toLowerCase()
removed here?
splitArrayString(dataSources) | ||
.filter((d) => { | ||
const match = d.match(ADDRESS_REG); | ||
return match && match[1].toLowerCase() === casedInputAddress; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check needs to be added.
return match && match[1].toLowerCase() === casedInputAddress; | |
return match && match.length >= 2 && match[1].toLowerCase() === casedInputAddress; |
b5e6c4e
to
26850a3
Compare
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes #2098
codegen:generate
working with ts-manifest, instead of targetting.yaml
it will now be updating the.ts
manifest with chosen abi methodsPlease delete options that are not relevant.
Checklist