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

chore: fix generated file and class names #294

Merged
merged 4 commits into from
May 27, 2022
Merged

Conversation

camsjams
Copy link
Contributor

@camsjams camsjams requested a review from luizstacio May 26, 2022 00:08
@camsjams camsjams self-assigned this May 26, 2022
@camsjams camsjams changed the title Fix name generation chore: fix generated file and class names May 26, 2022
@camsjams camsjams requested a review from luizstacio May 26, 2022 04:30
QuinnLee
QuinnLee previously approved these changes May 26, 2022
@camsjams
Copy link
Contributor Author

@luizstacio are your requested changes looking good?

@luizstacio
Copy link
Member

@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 normalizeName didn't try to improve the name and just use it.

I just write a custom normalizeName and tested locally this one should work better for us;

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;
}

@camsjams
Copy link
Contributor Author

camsjams commented May 27, 2022

@luizstacio I've added some tests, I linked my local Swap Swap to this typechain-target-fuels and it worked, it reverted the names back to how they were previous to TypeChain v8+

Copy link
Member

@luizstacio luizstacio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@camsjams camsjams merged commit 7586f98 into master May 27, 2022
@camsjams camsjams deleted the feature/issue-292 branch May 27, 2022 16:58
pedronauck added a commit that referenced this pull request May 31, 2022
* 'master' of github.com:FuelLabs/fuels-ts:
  feat!: Refactor Contract API namespaces (#303)
  chore: fix generated file and class names (#294)
  fix: change import crypto to ether/random (#297)
  feat: enable utxo validation (#278)
  feat: improve AbiCoder (#290)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix TypeChain generated Class names
3 participants