added automatic platform detection to cli if none is passed

This commit is contained in:
rtretter 2024-03-06 21:16:51 +01:00
parent 912885bfe2
commit f62c81ea0d
3 changed files with 23 additions and 5 deletions

2
Cargo.lock generated
View file

@ -2326,7 +2326,7 @@ dependencies = [
name = "dioxus-cli-config"
version = "0.5.0-alpha.0"
dependencies = [
"cargo_toml 0.16.3",
"cargo_toml 0.18.0",
"clap 4.4.18",
"once_cell",
"serde",

View file

@ -13,7 +13,7 @@ clap = { version = "4.2", features = ["derive"], optional = true }
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
toml = { workspace = true, optional = true }
cargo_toml = { version = "0.16.0", optional = true }
cargo_toml = { version = "0.18.0", optional = true }
once_cell = "1.18.0"
tracing = { workspace = true }

View file

@ -3,6 +3,7 @@ use manganis_cli_support::AssetManifest;
use super::*;
use std::{fs::create_dir_all, io::Write, path::PathBuf};
use cargo_toml::Dependency::{Simple, Inherited, Detailed};
/// Run the WASM project on dev-server
#[derive(Clone, Debug, Parser)]
@ -41,11 +42,28 @@ impl Serve {
crate_config.set_cargo_args(self.serve.cargo_args);
let platform = self
let mut platform = self
.serve
.platform
.unwrap_or(crate_config.dioxus_config.application.default_platform);
.platform;
if platform.is_none() {
if let Some(dependency) = &crate_config.manifest.dependencies.get("dioxus") {
let features = match dependency {
Inherited(detail) => detail.features.to_vec(),
Detailed(detail) => detail.features.to_vec(),
Simple(_) => vec![]
};
platform = features
.iter()
.next()
.and_then(|first_feature| serde_json::from_str(&format!(r#""{}""#, first_feature)).ok());
}
}
let platform = platform
.unwrap_or(crate_config.dioxus_config.application.default_platform);
match platform {
Platform::Web => {
// start the develop server