t3-oss / create-t3-app

The best way to start a full-stack, typesafe Next.js app
https://create.t3.gg
MIT License
24.77k stars 1.14k forks source link

feat: using custom config files #1078

Open alumen2101 opened 1 year ago

alumen2101 commented 1 year ago

Is your feature request related to a problem? Please describe.

everytime i initialize a T3 app, i have to change tsconfig.json, tailwind.config.cjs to my preference.

Describe the solution you'd like to see

in CLI, using a flag and directory path that contains all the custom config files, so that it would use those files instead. yarn create t3-app --flag [PATH]

Describe alternate solutions

N/A

Additional information

No response

nexxeln commented 1 year ago

I really like this

juliusmarminge commented 1 year ago

I like this too, I think it'd be nice to allow something like

$ p create t3-app@latest --overrides ../path/to/my/tailwind.config.cjs --overrides ../path/to/tsconfig.json

and we'd infer the override based on the filename passed in 🤔

nexxeln commented 1 year ago

We can even have a config file in ~/.config/ct3a.toml or something and people would have to set that up just once pointing to their custom config files and then when using the CLI they won't have to pass any flags.

In addition to this we can have a flag like --no-overrides where you can get the default template without your custom files.

What do people prefer? Relative path or config file?

juliusmarminge commented 1 year ago

In addition to this we can have a flag like --no-overrides where you can get the default template without your custom files.

Yes opting out should be supported

What do people prefer? Relative path or config file?

I dont see why not support both. A parseOverrides function which would find stuff in a deterministic order and pass the parsed config to all the installers, so then you could even mix between a global config and per-project overrides.

Should also outline that we wouldn't take any responsibility whether your app will launch after applying all the overrides 🤣

juliusmarminge commented 1 year ago

Adding the discussion label as I think we should give this some thought before jumping into implementation

alumen2101 commented 1 year ago

Should also outline that we wouldn't take any responsibility whether your app will launch after applying all the overrides

is it possible to check passed in files in order to check them if they are valid or not?

juliusmarminge commented 1 year ago

is it possible to check passed in files in order to check them if they are valid or not?

I don't think that's our responsibility since this would be an advanced usage feature, like you might have extra stuff in your override files that would require additional dependencies, for example the tailwind config might be using tailwind plugins that wouldn't be installed by default

NathanPip commented 1 year ago

Hey, still pretty new to the T3 ecosystem but I whipped up a simple implementation of this here https://github.com/t3-oss/create-t3-app/pull/1091 :-)

NathanPip commented 1 year ago

Alright I've given this a little bit of thought. How does this sound? Like @nexxeln suggested we have a toml file configured like so

[override]
override_dir = {path_to_dir_with_override_files}
overrides = [{path_to_file_or_dir}, {path_to_file_or_dir}]

[override.otherCustomConfig]
override_dir = {path_to_dir_with_override_files}
overrides = [{path_to_file_or_dir}, {path_to_file_or_dir}]

Where the base override table will be the default override configuration and subtables act as seperate configs you use with a --useOverride [name_of_override_subtable] flag. And like @juliusmarminge suggested we have a --override [path_to_dir_or_file_or_toml] where we can infer based on the file name / extension or directory name and parse them out accordingly.

Overrides and parsing work like this.

This could add a lot of flexibility to scaffolding a project by adding the ability to create different configurations based on the needs of each project and mixing different configs with --override flags or paths added to overrides arrays inside of a toml.

Mvmo commented 1 year ago

@juliusmarminge @nexxeln I've created a draft and would like to hear your opinion and additional ideas for my proposal. I have implemented it in such a way that after a project is created, it checks if any of the following folders exist:

${T3_CONFIG}/override
${XDG_CONFIG_HOME}/t3stack/override
${HOME}/t3stack/override

If any of these folders exist, all files within the override directory are used to overwrite the defaults in the created project. This way, practically everything can be customized. I have also included some attachments in the draft #1503