-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example to export typescript types
- Loading branch information
1 parent
6bd239f
commit 09a8090
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"rust-analyzer.cargo.features": ["ts-gen"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// This example connects to a radio via serial, and demonstrates how to | ||
/// configure handlers for different types of decoded radio packets. | ||
/// https://meshtastic.org/docs/supported-hardware | ||
/// | ||
/// Run this example with the command `cargo run --example generate_typescript_types --features "ts-gen"` | ||
extern crate meshtastic; | ||
|
||
use meshtastic::ts::specta::{ | ||
export::ts_with_cfg, | ||
ts::{BigIntExportBehavior, ExportConfiguration, ModuleExportBehavior, TsExportError}, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
// Exports relative to the root workspace directory | ||
export_ts_types("./examples/bindings.ts")?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn export_ts_types(file_path: &str) -> Result<(), TsExportError> { | ||
// Sets up a default configuration for exporting typescript types | ||
let ts_export_config = ExportConfiguration::default() | ||
.bigint(BigIntExportBehavior::String) | ||
.modules(ModuleExportBehavior::Enabled); | ||
|
||
// Use Specta helper function to export typescript types | ||
ts_with_cfg(file_path, &ts_export_config) | ||
} |