mod api;
pub(crate) mod builder;
mod types;
use std::path::PathBuf;
use forge_core::schema::SchemaRegistry;
use crate::Error;
use crate::binding::BindingSet;
pub struct DioxusGenerator {
output_dir: PathBuf,
}
impl DioxusGenerator {
pub fn new(output_dir: impl Into<PathBuf>) -> Self {
Self {
output_dir: output_dir.into(),
}
}
pub fn generate(&self, registry: &SchemaRegistry) -> Result<(), Error> {
std::fs::create_dir_all(&self.output_dir)?;
let bindings = BindingSet::from_registry(registry);
std::fs::write(self.output_dir.join("types.rs"), types::generate(registry)?)?;
std::fs::write(self.output_dir.join("api.rs"), api::generate(&bindings)?)?;
std::fs::write(self.output_dir.join("mod.rs"), Self::mod_content())?;
Ok(())
}
fn mod_content() -> &'static str {
r#"// @generated by FORGE - DO NOT EDIT
#![allow(dead_code, unused_imports)]
pub mod api;
pub mod types;
pub use api::*;
pub use forge_dioxus::{
ConnectionState, ForgeAuth, ForgeAuthProvider, ForgeClient, ForgeClientConfig,
ForgeClientError, ForgeError, ForgeProvider, ForgeUpload, JobExecutionState, Mutation,
QueryState, SignalError, SubscriptionHandle, SubscriptionState, TokenPair, WorkflowExecutionState,
use_auth_key, use_connection_state, use_forge_auth, use_forge_client, use_forge_job,
use_forge_mutation, use_forge_query, use_forge_subscription, use_forge_workflow,
use_viewer,
};
pub use types::*;
"#
}
}