diff --git a/Cargo.lock b/Cargo.lock index 974fa34..d90303a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -665,26 +665,12 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "diff-tool-logic" -version = "0.0.1" -dependencies = [ - "clap", - "indexmap 2.2.3", - "insta", - "itertools", - "serde", - "thiserror", - "toml 0.8.10", - "walkdir", -] - [[package]] name = "diffedit3-gui" version = "0.0.1" dependencies = [ "clap", - "diff-tool-logic", + "diffedit3-web", "indexmap 2.2.3", "serde", "serde_json", @@ -697,15 +683,17 @@ name = "diffedit3-web" version = "0.0.1" dependencies = [ "clap", - "diff-tool-logic", "indexmap 2.2.3", + "insta", "open", "poem", "rust-embed", "serde", "thiserror", "tokio", + "toml 0.8.10", "tracing-subscriber", + "walkdir", ] [[package]] @@ -766,12 +754,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" -[[package]] -name = "either" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" - [[package]] name = "embed-resource" version = "2.4.1" @@ -1590,9 +1572,9 @@ dependencies = [ [[package]] name = "insta" -version = "1.34.0" +version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d64600be34b2fcfc267740a243fa7744441bb4947a619ac4e5bb6507f35fbfc" +checksum = "7c985c1bef99cf13c58fade470483d81a2bfe846ebde60ed28cc2dddec2df9e2" dependencies = [ "console", "lazy_static", @@ -1632,15 +1614,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "0.4.8" diff --git a/Cargo.toml b/Cargo.toml index 30d150f..ec4651a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,9 +3,8 @@ version = "0.0.1" # Also update package.json and tauri.conf.json edition = "2021" [workspace] -members = ["diff-tool-logic", "backend-tauri", "backend-local-server"] +members = [ "backend-tauri", "backend-local-server"] default-members = [ - "diff-tool-logic", "backend-local-server", # `cargo build` should ignore the Tauri binary. # `cargo tauri build` must be used for that. diff --git a/backend-local-server/Cargo.toml b/backend-local-server/Cargo.toml index 4fa1ded..d7df505 100644 --- a/backend-local-server/Cargo.toml +++ b/backend-local-server/Cargo.toml @@ -5,7 +5,6 @@ edition = { workspace = true } [dependencies] clap = { version = "4.5.0", features = ["derive"] } -diff-tool-logic = { path = "../diff-tool-logic" } indexmap = { version = "2.2.3", features = ["serde"] } open = "5.0.1" poem = { version = "2.0.0", features = ["embed"] } @@ -13,4 +12,14 @@ rust-embed = { version = "8.2.0" } serde = { version = "1.0.196", features = ["serde_derive"] } thiserror = "1.0.57" tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread", "signal"] } +toml = { version = "0.8.10", features = ["indexmap"] } tracing-subscriber = "0.3.18" +walkdir = "2.4.0" + +[dev-dependencies] +insta = { version = "1.34.0", features = [ + "redactions", + "serde", + "yaml", + "json", +] } diff --git a/backend-local-server/TODO.md b/backend-local-server/TODO.md deleted file mode 100644 index 2e6c5aa..0000000 --- a/backend-local-server/TODO.md +++ /dev/null @@ -1,4 +0,0 @@ -Split the local server into a library, separate from a small binary. - -Perhaps combine this into one package with diff-toll-logic, with server features -perhaps locked behind a feature flag. \ No newline at end of file diff --git a/backend-local-server/TODOs.md b/backend-local-server/TODOs.md new file mode 100644 index 0000000..fa340fd --- /dev/null +++ b/backend-local-server/TODOs.md @@ -0,0 +1,4 @@ +build.rs script to check whether dist changed + +Move everything in `backend-local-server` one level up, make it the "diffedit3" +crate. \ No newline at end of file diff --git a/backend-local-server/src/bin/diffedit3-web.rs b/backend-local-server/src/bin/diffedit3-web.rs index 51072e2..57f90d0 100644 --- a/backend-local-server/src/bin/diffedit3-web.rs +++ b/backend-local-server/src/bin/diffedit3-web.rs @@ -6,7 +6,7 @@ use diffedit3_web::local_server::{run_server, MergeToolError}; #[command(version, about)] pub struct LocalServerCli { #[command(flatten)] - lib_cli: diff_tool_logic::Cli, + lib_cli: diffedit3_web::fs::Cli, /// Port to use for `http://127.0.0.1` #[arg(long, short, default_value = "8080")] port: usize, @@ -37,7 +37,7 @@ fn exit_with_cli_error(s: String) -> ! { #[tokio::main] async fn main() -> Result<(), MergeToolError> { let cli = LocalServerCli::parse(); - let input: diff_tool_logic::ThreeDirInput = match cli.lib_cli.try_into() { + let input: diffedit3_web::fs::ThreeDirInput = match cli.lib_cli.try_into() { Ok(i) => i, Err(err) => { exit_with_cli_error(err.to_string()); diff --git a/diff-tool-logic/src/fs.rs b/backend-local-server/src/fs.rs similarity index 100% rename from diff-tool-logic/src/fs.rs rename to backend-local-server/src/fs.rs diff --git a/backend-local-server/src/lib.rs b/backend-local-server/src/lib.rs index 789cdf4..7acebe3 100644 --- a/backend-local-server/src/lib.rs +++ b/backend-local-server/src/lib.rs @@ -1 +1,31 @@ +pub mod fs; +pub mod types; pub mod local_server; + +pub use fs::{Cli, ThreeDirInput}; +pub use types::*; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + insta::assert_yaml_snapshot!(ThreeDirInput::FakeData.scan().unwrap(), + @r###" + --- + added file: + - ~ + - added + - added + deleted_file: + - deleted + - ~ + - ~ + edited_file: + - "First\nThird\nFourth\nFourthAndAHalf\n\nFifth\nSixth\n----\none two" + - "First\nSecond\nThird\nFifth\nSixth\n----\none\n" + - "First\nSecond\nThird\nFifth\nSixth\n----\none\n" + "###); + } +} diff --git a/backend-local-server/src/local_server.rs b/backend-local-server/src/local_server.rs index 9f84b1a..7b344ce 100644 --- a/backend-local-server/src/local_server.rs +++ b/backend-local-server/src/local_server.rs @@ -2,7 +2,6 @@ use std::io; use std::sync::Arc; use std::time::Duration; -use diff_tool_logic::DataInterface; use poem::endpoint::EmbeddedFilesEndpoint; use poem::error::ResponseError; use poem::http::StatusCode; @@ -12,6 +11,8 @@ use poem::web::{Data, Json}; use poem::{handler, EndpointExt, Result, Route, Server}; use thiserror::Error; +use crate::DataInterface; + #[derive(rust_embed::RustEmbed)] #[folder = "../webapp/dist"] struct StaticFiles; @@ -33,9 +34,9 @@ pub enum MergeToolError { #[derive(Debug, Error)] enum ServerHTTPError { #[error("{0}")] - DataReadError(#[from] diff_tool_logic::DataReadError), + DataReadError(#[from] crate::DataReadError), #[error("{0}")] - DataSaveError(#[from] diff_tool_logic::DataSaveError), + DataSaveError(#[from] crate::DataSaveError), #[error("{0}")] FailedToSendExitSignal(tokio::sync::mpsc::error::SendError), } @@ -50,7 +51,7 @@ type ExitCodeSender = tokio::sync::mpsc::Sender; #[handler] fn get_merge_data( input: Data<&Arc>>, -) -> Result> { +) -> Result> { // TODO: We can consider wrapping this IO in `tokio::spawn_blocking`, but it // doesn't seem crucial since there shouldn't actually be that much concurrency. // The could also be weird side effects. @@ -104,7 +105,7 @@ fn acceptor_to_socket_address( } pub async fn run_server( - input: impl diff_tool_logic::DataInterface, + input: impl crate::DataInterface, min_port: usize, max_port: usize, open_browser: bool, diff --git a/diff-tool-logic/src/types.rs b/backend-local-server/src/types.rs similarity index 100% rename from diff-tool-logic/src/types.rs rename to backend-local-server/src/types.rs diff --git a/backend-tauri/Cargo.toml b/backend-tauri/Cargo.toml index 9621924..e09c531 100644 --- a/backend-tauri/Cargo.toml +++ b/backend-tauri/Cargo.toml @@ -12,7 +12,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" indexmap = { version = "2.2.3", features = ["serde"] } clap = { version = "4.5.0", features = ["derive"] } -diff-tool-logic = { path = "../diff-tool-logic" } +diffedit3-web = { path = "../backend-local-server" } [features] # this feature is used for production builds or when `devPath` points to the filesystem diff --git a/backend-tauri/src/main.rs b/backend-tauri/src/main.rs index 3901fa8..9b7affc 100644 --- a/backend-tauri/src/main.rs +++ b/backend-tauri/src/main.rs @@ -4,7 +4,7 @@ // #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] use clap::Parser; -use diff_tool_logic::DataInterface; +use diffedit3_web::DataInterface; use indexmap::IndexMap; use tauri::{CustomMenuItem, Menu, Submenu}; @@ -25,15 +25,15 @@ fn logoutput(result: IndexMap) { #[tauri::command] fn save( result: IndexMap, - state: tauri::State, -) -> Result<(), diff_tool_logic::DataSaveError> { + state: tauri::State, +) -> Result<(), diffedit3_web::DataSaveError> { state.save(result) } #[tauri::command] fn get_merge_data( - state: tauri::State, -) -> Result { + state: tauri::State, +) -> Result { state.scan() } @@ -44,8 +44,8 @@ fn get_merge_data( // So far, the most promising approach is to change the `font-size` root // CSS property fn main() { - let cli = diff_tool_logic::Cli::parse(); - let input: diff_tool_logic::ThreeDirInput = cli.try_into().unwrap_or_else(|err| { + let cli = diffedit3_web::Cli::parse(); + let input: diffedit3_web::ThreeDirInput = cli.try_into().unwrap_or_else(|err| { eprintln!("Error: {err}"); std::process::exit(2) }); diff --git a/diff-tool-logic/Cargo.toml b/diff-tool-logic/Cargo.toml deleted file mode 100644 index 03b55a1..0000000 --- a/diff-tool-logic/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "diff-tool-logic" -version = { workspace = true } -edition = { workspace = true } - -[dependencies] -clap = { version = "4.5.0", features = ["derive"] } -indexmap = { version = "2.2.3", features = ["serde"] } -itertools = "0.12.1" -serde = { version = "1.0.196", features = ["serde_derive"] } -thiserror = "1.0.57" -toml = { version = "0.8.10", features = ["indexmap"] } -walkdir = "2.4.0" - -[dev-dependencies] -insta = { version = "1.34.0", features = [ - "redactions", - "serde", - "yaml", - "json", -] } diff --git a/diff-tool-logic/TODOs.md b/diff-tool-logic/TODOs.md deleted file mode 100644 index 54c04c5..0000000 --- a/diff-tool-logic/TODOs.md +++ /dev/null @@ -1 +0,0 @@ -build.rs script to check whether dist changed diff --git a/diff-tool-logic/src/lib.rs b/diff-tool-logic/src/lib.rs deleted file mode 100644 index 49b1950..0000000 --- a/diff-tool-logic/src/lib.rs +++ /dev/null @@ -1,30 +0,0 @@ -pub mod fs; -pub mod types; - -pub use fs::{Cli, ThreeDirInput}; -pub use types::*; - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - insta::assert_yaml_snapshot!(ThreeDirInput::FakeData.scan().unwrap(), - @r###" - --- - added file: - - ~ - - added - - added - deleted_file: - - deleted - - ~ - - ~ - edited_file: - - "First\nThird\nFourth\nFourthAndAHalf\n\nFifth\nSixth\n----\none two" - - "First\nSecond\nThird\nFifth\nSixth\n----\none\n" - - "First\nSecond\nThird\nFifth\nSixth\n----\none\n" - "###); - } -}