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

Function detect_module_language

crates/cli/src/util.rs:250–277  ·  view source on GitHub ↗
(path_to_module: &Path)

Source from the content-addressed store, hash-verified

248}
249
250pub 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
279pub fn url_to_host_and_protocol(url: &str) -> anyhow::Result<(&str, &str)> {
280 if contains_protocol(url) {

Callers 2

find_module_pathFunction · 0.85
buildFunction · 0.85

Calls 6

joinMethod · 0.80
flattenMethod · 0.80
OkFunction · 0.50
anyMethod · 0.45
pathMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…