diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..c0b2ad2 --- /dev/null +++ b/TODO.md @@ -0,0 +1,14 @@ +# TODO + +## Ben + +- [ ] Transport : Packet splitting +- [ ] State : Event history tracking +- [ ] State : Post game sync +- [ ] API : Handling Profile Syncing +- [ ] ALL : State Update Events +- [ ] ALL : Game Replay Screen +- [ ] Frontend : Scaffolding +- [ ] Meta : CI Setup +- [ ] Meta : README Instructions +- [x] Meta : Recipes for type binding generation diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 2aafc34..feba03b 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -9,6 +9,10 @@ edition = "2021" name = "manhunt_app_lib" crate-type = ["staticlib", "cdylib", "rlib"] +[[bin]] +name = "export-types" +path = "src/export_types.rs" + [build-dependencies] tauri-build = { version = "2", features = [] } diff --git a/backend/src/export_types.rs b/backend/src/export_types.rs new file mode 100644 index 0000000..301014d --- /dev/null +++ b/backend/src/export_types.rs @@ -0,0 +1,20 @@ +use std::path::PathBuf; + +use manhunt_app_lib::mk_specta; +use specta_typescript::Typescript; + +pub fn main() { + let args = std::env::args().collect::>(); + let path = args.get(1).expect("Usage: export-types path"); + let path = PathBuf::from(path) + .canonicalize() + .expect("Failed to canonicalize path"); + let specta = mk_specta(); + specta + .export(Typescript::default(), &path) + .expect("Failed to export types"); + println!( + "Successfully exported type and commands to {}", + path.to_str().unwrap() + ); +} diff --git a/backend/src/lib.rs b/backend/src/lib.rs index 65e13d7..87d01d4 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -11,7 +11,6 @@ use lobby::{Lobby, LobbyState, StartGameInfo}; use location::TauriLocation; use profile::PlayerProfile; use serde::{Deserialize, Serialize}; -use specta_typescript::Typescript; use tauri::{AppHandle, Manager, State}; use tauri_specta::collect_commands; use tokio::sync::RwLock; @@ -282,11 +281,8 @@ async fn use_powerup(state: State<'_, AppStateHandle>) -> Result { } } -#[cfg_attr(mobile, tauri::mobile_entry_point)] -pub fn run() { - let state = RwLock::new(AppState::Setup); - - let builder = tauri_specta::Builder::::new().commands(collect_commands![ +pub fn mk_specta() -> tauri_specta::Builder { + tauri_specta::Builder::::new().commands(collect_commands![ start_lobby, quit_game_or_lobby, get_current_screen, @@ -298,12 +294,14 @@ pub fn run() { mark_caught, grab_powerup, use_powerup, - ]); + ]) +} + +#[cfg_attr(mobile, tauri::mobile_entry_point)] +pub fn run() { + let state = RwLock::new(AppState::Setup); - #[cfg(debug_assertions)] - builder - .export(Typescript::default(), "../frontend/src/bindings.ts") - .expect("Failed to export typescript bindings"); + let builder = mk_specta(); tauri::Builder::default() .manage(state) diff --git a/justfile b/justfile index 9982e51..4df0ae4 100644 --- a/justfile +++ b/justfile @@ -26,5 +26,9 @@ npm *CMD: cargo *CMD: nix develop --command cargo {{CMD}} +# Export types from the backend to TypeScript bindings +[working-directory: 'backend'] +export-types: + nix develop --command cargo run --bin export-types ../frontend/src/bindings.ts