-
-
Notifications
You must be signed in to change notification settings - Fork 16
Add support for tauri configuration files #1376
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
833ba20
Add support for tauri configuration files
bdbelevate 085e9d9
Address PR comments
bdbelevate 8b528b3
Merge branch 'main' into main
bdbelevate 90729dd
Fix test and lints
dbanty d179bbe
Merge branch 'main' into main
dbanty 62476e6
Add changeset
dbanty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| versioning: minor | ||
| knope: minor | ||
| --- | ||
|
|
||
| # Add support for Tauri config files | ||
|
|
||
| Supports [Tauri configuration files](https://v1.tauri.app/v1/references/configuration-files) in json format named `tauri.conf.json`, `tauri.macos.conf.json`, `tauri.windows.conf.json`, and `tauri.linux.conf.json`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
crates/knope-versioning/src/versioned_file/tauri_conf_json.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| #[cfg(feature = "miette")] | ||
| use miette::Diagnostic; | ||
| use relative_path::RelativePathBuf; | ||
| use serde::Deserialize; | ||
| use serde_json::{Map, Value}; | ||
| use thiserror::Error; | ||
|
|
||
| use crate::{action::Action, semver::Version}; | ||
|
|
||
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
| pub struct TauriConfJson { | ||
| path: RelativePathBuf, | ||
| raw: String, | ||
| parsed: Json, | ||
| diff: Option<String>, | ||
| } | ||
|
|
||
| impl TauriConfJson { | ||
| pub(crate) fn new(path: RelativePathBuf, content: String) -> Result<Self, Error> { | ||
| match serde_json::from_str(&content) { | ||
| Ok(parsed) => Ok(TauriConfJson { | ||
| path, | ||
| raw: content, | ||
| parsed, | ||
| diff: None, | ||
| }), | ||
| Err(err) => Err(Error::Deserialize { path, source: err }), | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn get_version(&self) -> &Version { | ||
| &self.parsed.version | ||
| } | ||
|
|
||
| pub(crate) fn get_path(&self) -> &RelativePathBuf { | ||
| &self.path | ||
| } | ||
|
|
||
| pub(crate) fn set_version(mut self, new_version: &Version) -> serde_json::Result<Self> { | ||
| let mut json = serde_json::from_str::<Map<String, Value>>(&self.raw)?; | ||
| json.insert( | ||
| "version".to_string(), | ||
| Value::String(new_version.to_string()), | ||
| ); | ||
| self.raw = serde_json::to_string_pretty(&json)?; | ||
| self.diff = Some(new_version.to_string()); | ||
| Ok(self) | ||
| } | ||
|
|
||
| pub(crate) fn write(self) -> Option<Action> { | ||
| self.diff.map(|diff| Action::WriteToFile { | ||
| path: self.path, | ||
| content: self.raw, | ||
| diff, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Error)] | ||
| #[cfg_attr(feature = "miette", derive(Diagnostic))] | ||
| pub enum Error { | ||
| #[error("Error deserializing {path}: {source}")] | ||
| #[cfg_attr( | ||
| feature = "miette", | ||
| diagnostic( | ||
| code(tauri_conf_json::deserialize), | ||
| help( | ||
| "knope expects the tauri.conf.json file to be an object with a top level `version` property" | ||
| ), | ||
| url("https://knope.tech/reference/config-file/packages/#tauri-conf") | ||
| ) | ||
| )] | ||
| Deserialize { | ||
| path: RelativePathBuf, | ||
| #[source] | ||
| source: serde_json::Error, | ||
| }, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq)] | ||
| struct Json { | ||
| version: Version, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::str::FromStr; | ||
|
|
||
| use pretty_assertions::assert_eq; | ||
|
|
||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_get_version() { | ||
| let content = r#"{ | ||
| "productName": "tester", | ||
| "version": "0.1.0-rc.0" | ||
| }"#; | ||
|
|
||
| assert_eq!( | ||
| TauriConfJson::new(RelativePathBuf::new(), content.to_string()) | ||
| .unwrap() | ||
| .get_version(), | ||
| &Version::from_str("0.1.0-rc.0").unwrap() | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_set_version() { | ||
| let content = r#"{ | ||
| "productName": "tester", | ||
| "version": "0.1.0-rc.0" | ||
| }"#; | ||
|
|
||
| let new = TauriConfJson::new(RelativePathBuf::new(), content.to_string()) | ||
| .unwrap() | ||
| .set_version(&Version::from_str("1.2.3-rc.4").unwrap()) | ||
| .unwrap() | ||
| .write() | ||
| .expect("diff to write"); | ||
|
|
||
| let expected = r#"{ | ||
| "productName": "tester", | ||
| "version": "1.2.3-rc.4" | ||
| }"# | ||
| .to_string(); | ||
| let expected = Action::WriteToFile { | ||
| path: RelativePathBuf::new(), | ||
| content: expected, | ||
| diff: "1.2.3-rc.4".to_string(), | ||
| }; | ||
| assert_eq!(new, expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn retain_property_order() { | ||
| let content = r#"{ | ||
| "productName": "tester", | ||
| "version": "0.1.0-rc.0", | ||
| "identifier": "com.knope.tester" | ||
| }"#; | ||
|
|
||
| let new = TauriConfJson::new(RelativePathBuf::new(), content.to_string()) | ||
| .unwrap() | ||
| .set_version(&Version::from_str("1.2.3-rc.4").unwrap()) | ||
| .unwrap() | ||
| .write() | ||
| .expect("diff to write"); | ||
|
|
||
| let expected = r#"{ | ||
| "productName": "tester", | ||
| "version": "1.2.3-rc.4", | ||
| "identifier": "com.knope.tester" | ||
| }"# | ||
| .to_string(); | ||
| let expected = Action::WriteToFile { | ||
| path: RelativePathBuf::new(), | ||
| content: expected, | ||
| diff: "1.2.3-rc.4".to_string(), | ||
| }; | ||
| assert_eq!(new, expected); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
crates/knope/tests/prepare_release/tauri_conf_json/dryrun_stdout.log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Would add the following to Cargo.toml: version = 0.2.0 | ||
| Would add the following to package.json: 0.2.0 | ||
| Would add the following to tauri.conf.json: 0.2.0 | ||
| Would add the following to tauri.macos.conf.json: 0.2.0 | ||
| Would add files to git: | ||
| Cargo.toml | ||
| package.json | ||
| tauri.conf.json | ||
| tauri.macos.conf.json |
24 changes: 24 additions & 0 deletions
24
crates/knope/tests/prepare_release/tauri_conf_json/in/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| [package] | ||
| name = "knope-test" | ||
| version = "0.1.0" | ||
| description = "A Tauri App" | ||
| authors = ["you"] | ||
| edition = "2021" | ||
|
|
||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
|
||
| [lib] | ||
| # The `_lib` suffix may seem redundant but it is necessary | ||
| # to make the lib name unique and wouldn't conflict with the bin name. | ||
| # This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519 | ||
| name = "knope_test_lib" | ||
| crate-type = ["staticlib", "cdylib", "rlib"] | ||
|
|
||
| [build-dependencies] | ||
| tauri-build = { version = "2", features = [] } | ||
|
|
||
| [dependencies] | ||
| tauri = { version = "2", features = [] } | ||
| tauri-plugin-opener = "2" | ||
| serde = { version = "1", features = ["derive"] } | ||
| serde_json = "1" |
13 changes: 13 additions & 0 deletions
13
crates/knope/tests/prepare_release/tauri_conf_json/in/knope.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [package] | ||
| versioned_files = [ | ||
| "Cargo.toml", | ||
| "package.json", | ||
| "tauri.conf.json", | ||
| "tauri.macos.conf.json", | ||
| ] | ||
|
|
||
| [[workflows]] | ||
| name = "release" | ||
|
|
||
| [[workflows.steps]] | ||
| type = "PrepareRelease" |
21 changes: 21 additions & 0 deletions
21
crates/knope/tests/prepare_release/tauri_conf_json/in/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "name": "knope-test", | ||
| "private": true, | ||
| "version": "0.1.0", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "tsc && vite build", | ||
| "preview": "vite preview", | ||
| "tauri": "tauri" | ||
| }, | ||
| "dependencies": { | ||
| "@tauri-apps/api": "^2", | ||
| "@tauri-apps/plugin-opener": "^2" | ||
| }, | ||
| "devDependencies": { | ||
| "@tauri-apps/cli": "^2", | ||
| "vite": "^6.0.3", | ||
| "typescript": "~5.6.2" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.