MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / main

Function main

tools/generate-client-api/src/main.rs:41–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41fn 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(),

Callers

nothing calls this directly

Calls 9

run_captureFunction · 0.85
replace_in_treeFunction · 0.85
joinMethod · 0.80
run_inheritFunction · 0.70
newFunction · 0.50
OkFunction · 0.50
unwrapMethod · 0.45
as_bytesMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…