mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 23:35:44 +00:00
chore(ipc): bootstrap tauri-specta generator (1 command, no cutover)
Stand up the FE<->BE contract pipeline end to end with near-zero surface: a tauri_specta::Builder collects one proven command (greet) and exports typed TS bindings to src/generated/bindings.ts. The existing generate_handler! stays the live invoke handler — no FE change yet. Safety: the export runs only under #[cfg(debug_assertions)] (debug launch) and a headless test, never in a release build, so a specta RC break can never block a release cargo build; the committed bindings.ts is plain TypeScript for tsc. The snapshot is committed (gitignore exception) so CI diffs catch contract drift. Pinned deps: specta / tauri-specta =2.0.0-rc.25, specta-typescript =0.0.12 (the latest mutually-consistent set; rc.21 + specta-typescript 0.0.9 no longer resolve). Grow collect_commands! crate-by-crate next, starting with psysonic-library.
This commit is contained in:
@@ -78,7 +78,39 @@ fn set_app_user_model_id() {
|
||||
}
|
||||
}
|
||||
|
||||
/// FE↔BE contract via tauri-specta. The builder collects `#[specta::specta]`
|
||||
/// commands and exports typed TS bindings; the existing `generate_handler!` stays
|
||||
/// the live invoke handler (no cutover yet). Export runs only in debug builds /
|
||||
/// tests, so a specta RC break can never block a release `cargo build` — the
|
||||
/// committed `bindings.ts` is plain TypeScript for `tsc`. Grow `collect_commands!`
|
||||
/// crate-by-crate (see the specta-contract plan).
|
||||
fn specta_builder() -> tauri_specta::Builder<tauri::Wry> {
|
||||
tauri_specta::Builder::<tauri::Wry>::new()
|
||||
.commands(tauri_specta::collect_commands![
|
||||
crate::lib_commands::app_api::core::greet
|
||||
])
|
||||
}
|
||||
|
||||
/// TS exporter config. Kept as a single seam so the exporter options (header /
|
||||
/// per-type BigInt-style handling for i64 DTOs) are configured in one place as
|
||||
/// commands are added crate-by-crate.
|
||||
fn bindings_exporter() -> specta_typescript::Typescript {
|
||||
specta_typescript::Typescript::default()
|
||||
}
|
||||
|
||||
/// Regenerate the committed bindings on a debug launch (matches the dev workflow;
|
||||
/// the CI freshness gate runs the equivalent export in a test — see `specta_export`).
|
||||
#[cfg(debug_assertions)]
|
||||
fn export_specta_bindings() {
|
||||
specta_builder()
|
||||
.export(bindings_exporter(), "../src/generated/bindings.ts")
|
||||
.expect("failed to export typescript bindings");
|
||||
}
|
||||
|
||||
pub fn run() {
|
||||
#[cfg(debug_assertions)]
|
||||
export_specta_bindings();
|
||||
|
||||
// Windows: bind this process to an explicit AppUserModelID before any window
|
||||
// or the SMTC media controls are created, so the OS can resolve the app
|
||||
// name/icon for taskbar grouping and the media tile (#1102 follow-up: the
|
||||
@@ -922,3 +954,15 @@ pub fn run() {
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running Psysonic");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod specta_export {
|
||||
// Headless generator + freshness seed: runs the same export as a debug launch
|
||||
// without a GUI, so `cargo test` regenerates `bindings.ts` and CI can diff it.
|
||||
#[test]
|
||||
fn bindings_are_exportable() {
|
||||
super::specta_builder()
|
||||
.export(super::bindings_exporter(), "../src/generated/bindings.ts")
|
||||
.expect("failed to export typescript bindings");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user