| 248 | } |
| 249 | |
| 250 | pub fn detect_module_language(path_to_module: &Path) -> anyhow::Result<ModuleLanguage> { |
| 251 | // TODO: Possible add a config file durlng spacetime init with the language |
| 252 | if !path_to_module.exists() { |
| 253 | anyhow::bail!( |
| 254 | "Module directory does not exist: '{}'. \ |
| 255 | Check your --module-path flag or the module-path setting in spacetime.json.", |
| 256 | path_to_module.display() |
| 257 | ); |
| 258 | } |
| 259 | // check for Cargo.toml |
| 260 | if path_to_module.join("Cargo.toml").exists() { |
| 261 | Ok(ModuleLanguage::Rust) |
| 262 | } else if path_to_module.is_dir() |
| 263 | && path_to_module |
| 264 | .read_dir() |
| 265 | .map_err(|e| anyhow::anyhow!("Failed to read directory {}: {}", path_to_module.display(), e))? |
| 266 | .flatten() |
| 267 | .any(|entry| entry.path().extension() == Some("csproj".as_ref())) |
| 268 | { |
| 269 | Ok(ModuleLanguage::Csharp) |
| 270 | } else if path_to_module.join("package.json").exists() { |
| 271 | Ok(ModuleLanguage::Javascript) |
| 272 | } else if path_to_module.join("CMakeLists.txt").exists() { |
| 273 | Ok(ModuleLanguage::Cpp) |
| 274 | } else { |
| 275 | anyhow::bail!("Could not detect the language of the module. Are you in a SpacetimeDB project directory?") |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | pub fn url_to_host_and_protocol(url: &str) -> anyhow::Result<(&str, &str)> { |
| 280 | if contains_protocol(url) { |