()
| 39 | } |
| 40 | |
| 41 | fn main() -> Result<()> { |
| 42 | let out_dir = "src/sdk/client_api"; |
| 43 | let index_replacement = "../../index"; |
| 44 | let other_replacement = "../../lib/type_builders"; |
| 45 | |
| 46 | let workspace_dir = Path::new(env!("CARGO_MANIFEST_DIR")) |
| 47 | .parent() |
| 48 | .unwrap() |
| 49 | .parent() |
| 50 | .unwrap(); |
| 51 | |
| 52 | // 1) Build prerequisite |
| 53 | run_inherit("cargo", &["build"], Some(workspace_dir))?; |
| 54 | |
| 55 | // 2) Get schema to a temp file (auto-cleaned) |
| 56 | let mut tmp_schema = NamedTempFile::new().context("create temp schema file")?; |
| 57 | let schema_json = run_capture( |
| 58 | "cargo", |
| 59 | &[ |
| 60 | "run", |
| 61 | "-p", |
| 62 | "spacetimedb-client-api-messages", |
| 63 | "--example", |
| 64 | "get_ws_schema_v2", |
| 65 | ], |
| 66 | )?; |
| 67 | use std::io::Write; |
| 68 | tmp_schema.write_all(schema_json.as_bytes())?; |
| 69 | let schema_path = tmp_schema.path(); |
| 70 | |
| 71 | // 3) Ensure output directory exists |
| 72 | if !Path::new(out_dir).exists() { |
| 73 | fs::create_dir_all(out_dir).context("create output directory")?; |
| 74 | } |
| 75 | |
| 76 | // 4) Generate TS client |
| 77 | run_inherit( |
| 78 | workspace_dir |
| 79 | .join("target/debug/spacetimedb-cli") |
| 80 | .with_extension(std::env::consts::EXE_EXTENSION), |
| 81 | &[ |
| 82 | "generate", |
| 83 | "-y", |
| 84 | "--lang", |
| 85 | "typescript", |
| 86 | "--out-dir", |
| 87 | out_dir, |
| 88 | "--module-def", |
| 89 | schema_path.to_str().unwrap(), |
| 90 | ], |
| 91 | None, |
| 92 | )?; |
| 93 | |
| 94 | // 5) Replace "spacetimedb" references under out_dir |
| 95 | let opts = ReplaceOptions { |
| 96 | dry_run: false, |
| 97 | only_exts: Some(vec![ |
| 98 | "ts".into(), |
nothing calls this directly
no test coverage detected
searching dependent graphs…