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

fix: changeCase should not affect prefix #1072

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zotune
Copy link

@zotune zotune commented Jan 9, 2024

Based on issues:
#779
#780

Description:
There's an issue when using symbols like dot in prefix, ie {fileNameWithoutExt}.
image
It does not work because Keygen Case style overwrites it:
image

Without Keygen Case style:
image

@zotune zotune changed the title changeCase should not affect prefix fix: changeCase should not affect prefix Jan 9, 2024
@dfaust
Copy link

dfaust commented Jun 1, 2024

I had the same issue and fixed it, too.

Unfortunately your solution has two problems.

  1. The key prefix is prepended even if it's empty or source.
  2. Change case is not applied to the file name.

The following code should work without these issues:

  key = changeCase(key, Config.keygenStyle)

  let keyPrefix = Config.keyPrefix
  if (keyPrefix && keygenStrategy !== 'empty' && keygenStrategy !== 'source') {
    if (filepath && keyPrefix.includes('fileName')) {
      keyPrefix = keyPrefix
        .replace('{fileName}', changeCase(basename(filepath), Config.keygenStyle))
        .replace('{fileNameWithoutExt}', changeCase(basename(filepath, extname(filepath)), Config.keygenStyle))
    }

    key = keyPrefix + key
  }

  key = key.trim()

@zotune
Copy link
Author

zotune commented Jun 3, 2024

@dfaust Thank you. Looks good. Should I update this PR with your code changes? (I was unable to test this)

@dfaust
Copy link

dfaust commented Jun 3, 2024

@zotune Sure, go ahead.

@zotune
Copy link
Author

zotune commented Jun 3, 2024

@dfaust Done. Let me know if its okay.

@dfaust
Copy link

dfaust commented Jun 3, 2024

@zotune Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants