codeBelt / generate-template-files

A simple generator to create custom template files for any application
https://medium.com/@robertsavian/generate-template-files-with-ease-19b320615359
MIT License
209 stars 31 forks source link

Add `caseConverter__` values to `CaseConverterEnum` #62

Closed TikiTDO closed 3 years ago

TikiTDO commented 3 years ago

The thing that really caught my eye with this lib is how it lets you write perfectly valid, type-safe files in typescript if you only restrict the use of case conversion to strings and comments. Unfortunately if you want to use case converters there are things you simply can't do.

For example, there is no way to make this snippet valid TS code.

// Given `__resourceName__ `is PascalCalse
export const __resourceName__(constantCase) _KEY = "__resourceName__(snakeCase)_exported_type";
const get__resourceName__ = (): Promise<ResultFor<__resourceName__(snakeCase)_exported_type>> => {
  get(__resourceName__(constantCase) _KEY)
}

This could be alleviated by allowing the case conversion tags to be underscored. In that case the above would look as follows:

// Given `__resourceName__ `is PascalCalse
export const __resourceName__constantCase___KEY = "__resourceName__snakeCase___exported_type";
export const get__resourceName__ = (): Promise<ResultFor<__resourceName__snakeCase___exported_type>> => {
  get(__resourceName__constantCase___KEY)
}

This ends up being totally valid TS, and at worst maybe need a few lint rules disabled. There's also no reason why the two couldn't coexist, so there shouldn't be any risk to existing users.

I've already tested that it works here. If you'd like I can merge this code into my other PR.

codeBelt commented 3 years ago

Hmm, Can you create a separate PR for this.

codeBelt commented 3 years ago

I think what you are suggesting for fix this issue https://github.com/codeBelt/generate-template-files/issues/52

TikiTDO commented 3 years ago

Yeah, it's a slightly different approach than the one proposed, but that one seems like it would take a decent bit of refactoring.