Huuums / vscode-folder-templates

Create your own Component structure with a simple click.
MIT License
209 stars 31 forks source link

conditional files / code generation. #100

Open vaukalak opened 2 years ago

vaukalak commented 2 years ago

suppose I have the following folder structure:

- FTName/
--- index.ts
--- [FTName].tsx
--- [FTName].tests.tsx
--- hooks.tsx

However, not all files need hooks.ts files and hence import in the [FTName].tsx. In theory, the work-around would be to create 2 templates. But in this case, I'll need to create a separate template for any specific scenario (suppose we'll have some optional files like utils, styles, and so on).

Huuums commented 2 years ago

Interesting suggestion.

So how could we go about it?

First idea I have is something like an extra option in the settings

optionalFiles: ["hooks.tsx"]

and for the files in this array we ask before actually creating the file? seems kinda intrusive and possibly annoying to work with.

What do you think?

aguscha333 commented 1 year ago

Optional files could have a bit of a different structure:

optionalFiles: [
{ fileName: "hooks.tsx", "defaultValue": "false"},
{ fileName: "[FTName].stories.tsx", "defaultValue": "true"}
]

If optional files are included, if the defaultValues are what you need then it is just one more "enter" key press not much friction to be annoyed at. If you need to edit it and select or deselect some of the optionals you won't be annoyed because you are taking advantage of the functionality. If you don't need optional files at all then this step would be ommited and that's it.

Huuums commented 1 year ago

I really like that approach.

Thanks alot. Will try to put this in when I have some free time.