-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
chore: fix generated file and class names #294
Conversation
@luizstacio are your requested changes looking good? |
I'm testing it using swayswap and because the name of the file has the underscore, looks like the I just write a custom function normalizeName(rawName: string): string {
const transformations: ((s: string) => string)[] = [
(s) => s.replace(/_/g, '-'), // replace "_" to '-'
(s) => s.replace(/\s+/g, '-'), // spaces to - so later we can automatically convert them
(s) => s.replace(/\./g, '-'), // replace "."
(s) => s.replace(/-[a-z]/g, (match) => match.slice(-1).toUpperCase()), // delete '-' and capitalize the letter after them
(s) => s.replace(/-/g, ''), // delete any '-' left
(s) => s.replace(/^\d+/, ''), // removes leading digits
(s) => s.replace(/[a-z]/, (match) => match.slice(-1).toUpperCase()), // upper case first letter
];
const finalName = transformations.reduce((s, t) => t(s), rawName);
if (finalName === '') {
throw new Error(`Can't guess class name, please rename file: ${rawName}`);
}
return finalName;
} |
@luizstacio I've added some tests, I linked my local Swap Swap to this |
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.
Nice!
Fixes #292
Previous version of
normalizeName
from TypeChain: https://github.com/dethcrypto/TypeChain/blob/2fcc74371ed0c2c587fb87e9ce0faa935e22942a/packages/typechain/src/parser/normalizeName.tsRecently updated version of
normalizeName
from TypeChain: https://github.com/dethcrypto/TypeChain/blob/3a8a99ad4641af8a4dae498566ccd837e15d7034/packages/typechain/src/parser/normalizeName.tsLuckily there was a copy already inside the fuels-ts repo