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

Function detect_client_command

crates/cli/src/spacetime_config.rs:1132–1162  ·  view source on GitHub ↗

Simple auto-detection for projects without `spacetime.json`. Returns the client command and optionally the detected package manager.

(project_dir: &Path)

Source from the content-addressed store, hash-verified

1130/// Simple auto-detection for projects without `spacetime.json`.
1131/// Returns the client command and optionally the detected package manager.
1132pub fn detect_client_command(project_dir: &Path) -> Option<(String, Option<PackageManager>)> {
1133 // JavaScript/TypeScript: package.json with "dev" script
1134 let package_json = project_dir.join("package.json");
1135 if package_json.exists()
1136 && let Ok(content) = fs::read_to_string(&package_json)
1137 && let Ok(json) = serde_json::from_str::<serde_json::Value>(&content)
1138 {
1139 let has_dev = json.get("scripts").and_then(|s| s.get("dev")).is_some();
1140 if has_dev {
1141 let pm = detect_package_manager(project_dir);
1142 let cmd = pm.map(|p| p.run_dev_command()).unwrap_or("npm run dev");
1143 return Some((cmd.to_string(), pm));
1144 }
1145 }
1146
1147 // Rust: Cargo.toml
1148 if project_dir.join("Cargo.toml").exists() {
1149 return Some(("cargo run".to_string(), None));
1150 }
1151
1152 // C#: .csproj file
1153 if let Ok(entries) = fs::read_dir(project_dir) {
1154 for entry in entries.flatten() {
1155 if entry.path().extension().is_some_and(|e| e == "csproj") {
1156 return Some(("dotnet run".to_string(), None));
1157 }
1158 }
1159 }
1160
1161 None
1162}
1163
1164#[cfg(test)]
1165mod tests {

Callers 3

setup_for_projectFunction · 0.85
execFunction · 0.85

Calls 9

detect_package_managerFunction · 0.85
joinMethod · 0.80
unwrap_orMethod · 0.80
run_dev_commandMethod · 0.80
flattenMethod · 0.80
getMethod · 0.45
mapMethod · 0.45
to_stringMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…