Skip to content

Commit

Permalink
Combine "diff-tool-logic" with "backend-local-server"
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Feb 21, 2024
1 parent 69ac06d commit 4a21fe4
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 107 deletions.
39 changes: 6 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 10 additions & 1 deletion backend-local-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ 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"] }
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",
] }
4 changes: 0 additions & 4 deletions backend-local-server/TODO.md

This file was deleted.

4 changes: 4 additions & 0 deletions backend-local-server/TODOs.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions backend-local-server/src/bin/diffedit3-web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions backend-local-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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"
"###);
}
}
11 changes: 6 additions & 5 deletions backend-local-server/src/local_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<ExitCode>),
}
Expand All @@ -50,7 +51,7 @@ type ExitCodeSender = tokio::sync::mpsc::Sender<ExitCode>;
#[handler]
fn get_merge_data(
input: Data<&Arc<Box<dyn DataInterface>>>,
) -> Result<Json<diff_tool_logic::EntriesToCompare>> {
) -> Result<Json<crate::EntriesToCompare>> {
// 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.
Expand Down Expand Up @@ -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,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion backend-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions backend-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -25,15 +25,15 @@ fn logoutput(result: IndexMap<String, String>) {
#[tauri::command]
fn save(
result: IndexMap<String, String>,
state: tauri::State<diff_tool_logic::ThreeDirInput>,
) -> Result<(), diff_tool_logic::DataSaveError> {
state: tauri::State<diffedit3_web::fs::ThreeDirInput>,
) -> Result<(), diffedit3_web::DataSaveError> {
state.save(result)
}

#[tauri::command]
fn get_merge_data(
state: tauri::State<diff_tool_logic::ThreeDirInput>,
) -> Result<diff_tool_logic::EntriesToCompare, diff_tool_logic::DataReadError> {
state: tauri::State<diffedit3_web::fs::ThreeDirInput>,
) -> Result<diffedit3_web::EntriesToCompare, diffedit3_web::DataReadError> {
state.scan()
}

Expand All @@ -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)
});
Expand Down
21 changes: 0 additions & 21 deletions diff-tool-logic/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion diff-tool-logic/TODOs.md

This file was deleted.

30 changes: 0 additions & 30 deletions diff-tool-logic/src/lib.rs

This file was deleted.

0 comments on commit 4a21fe4

Please sign in to comment.