Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Allow Tauri configurations to be set in Tauri.toml and/or Cargo.toml #4806

Closed
simonhyll opened this issue Jul 31, 2022 · 7 comments
Closed
Labels

Comments

@simonhyll
Copy link
Sponsor Contributor

Describe the problem

As a Rust developer I have a certain love for the TOML format. There's nothing directly wrong with the JSON configuration file, it's just not as easy to manage as a TOML file. For example, you can't add comments in a JSON file, something that would be very useful for the Tauri config seeing as it has gotten pretty long, there's a lot of stuff to keep in memory regarding why you do things in your configs and it would be very nice to be able to put comments in there.

Describe the solution you'd like

Add the ability to write configurations in a Tauri.toml file, and/or directly in the Cargo.toml file. Due to best practises with Cargo.toml however it's probably best to use a Tauri.toml file.

# Tauri.toml
allowlist = { all = true }

[build]
beforeBuildCommand = "yarn build"
beforeDevCommand = "yarn dev"
# Cargo.toml
[package.metadata.tauri]
allowlist = { all = true }

[package.metadata.tauri.build]
beforeBuildCommand = "yarn build"
beforeDevCommand = "yarn dev"

Implementing this feature shouldn't be much more work than to find the configuration from either Cargo.toml or Tauri.toml, converting TOML into JSON, then passing it forward into existing functionality. As can be seen above with how I put allowlist at the root of the Tauri.toml file, it may be preferable to do some restructuring of the configurations if you add them to TOML since a Tauri.toml file containing a [tauri] section doesn't make much sense, but since that can make it a bit difficult to maintain both the JSON and TOML variants restructuring isn't really necessary.

Alternatives considered

Alternatively a less user friendly variant but makes it easier to maintain both the JSON and TOML variants:

[package.metadata.tauri]
config = {
    # Pretty much just directly the contents of tauri.conf.json
}

This variant might make it a bit easier to maintain both the JSON and TOML variants, since the other suggested solution may involve some slight restructuring of the config file.

Additional context

Here's a little utility function I wrote for Cargo Commander for converting JSON to Toml. Can be used as inspiration.
https://github.com/adaptive-simon/cargo-commander/blob/main/src/utils.rs#L240

@amrbashir amrbashir added scope: cli.rs The tauri-cli rust crate priority: 3 low good first issue Good for newcomers status: backlog Issue is ready and we can work on it labels Jul 31, 2022
@lucasfernog
Copy link
Member

you can't add comments in a JSON file

We do have JSON5 support though. And we could easily add toml support.

@lucasfernog lucasfernog added status: needs review A maintainer must review this code status: in progress Implementation is proceeding smoothly and removed good first issue Good for newcomers scope: cli.rs The tauri-cli rust crate status: backlog Issue is ready and we can work on it status: needs review A maintainer must review this code labels Jul 31, 2022
@simonhyll
Copy link
Sponsor Contributor Author

I saw in your commit that you're adding tauri.conf.toml, which makes sense, but is there any chance Tauri.toml could also be added? 100% just a matter of preference, I already have Cargo.toml and Commands.toml, having Tauri.toml would look nicer in my file tree than tauri.conf.toml 😅

@lucasfernog
Copy link
Member

I would prefer Tauri.toml too but it would mean some new additions that doesn't align well with the current API (that only leverages different file extensions).

@lucasfernog
Copy link
Member

Ahh I just remembered the config module is documented as unstable so I can do some changes :) (otherwise adding any new config value would be impossible since everything is also public for the codegen step).

@lucasfernog
Copy link
Member

@adaptive-simon Your wish is my command :)

@simonhyll
Copy link
Sponsor Contributor Author

@adaptive-simon Your wish is my command :)

Omg awesome! You're the best!! 😄

@lucasfernog
Copy link
Member

Now we just need to update the documentation :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants