Huuums/vscode-folder-templates

conditional files / code generation.

Opened this issue · 3 comments

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).

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?

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.

I really like that approach.

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