unjs / c12

⚙️ Smart Configuration Loader
MIT License
543 stars 20 forks source link

Create config file/directory if it doesn't exist. #141

Open SelfhostedPro opened 9 months ago

SelfhostedPro commented 9 months ago

Describe the feature

It would be really nice to add an option like create: true to write whatever the default is to the config file/directory. I can definitely make a PR if needed.

Additional information

pi0 commented 9 months ago

It is a nice idea but the most tricky thing is that the default config template, is rally up to the consumer of c12, also the filename and I imagine this might be better handled in upper layers.

Do you care to explain more of your usecase for this feature?

SelfhostedPro commented 7 months ago

Sure, I don't want a user to have to write a default config (most of my users will have an interest in technology but may not want to/know how to write yaml).

I'm providing a UI to be able to change these settings so the users don't have to. I wound up just writing my own logic for it in the meantime but it may be beneficial to have it as an option so I don't need to.

https://github.com/SelfhostedPro/yacht-nuxt/blob/main/modules/config/runtime/server/utils/config.ts