make some extra dependencies only enabled for the CLI
This commit is contained in:
1 parent
532ffaa614
commit
4ff86d9763
2 files changed
+30
-21
No files matched your search
@@ -9,18 +9,18 @@ license = "MIT OR Apache-2.0"
|
|||||||
keywords = ["react", "gui", "cli", "dioxus", "wasm"]
|
keywords = ["react", "gui", "cli", "dioxus", "wasm"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.2", features = ["derive"] }
|
clap = { version = "4.2", features = ["derive"], optional = true }
|
||||||
serde = { version = "1.0.136", features = ["derive"] }
|
serde = { version = "1.0.136", features = ["derive"] }
|
||||||
serde_json = "1.0.79"
|
serde_json = "1.0.79"
|
||||||
toml = "0.5.8"
|
toml = { version = "0.5.8", optional = true }
|
||||||
cargo_toml = "0.16.0"
|
cargo_toml = { version = "0.16.0", optional = true }
|
||||||
|
|
||||||
# bundling
|
|
||||||
tauri-bundler = { version = "=1.3.0", features = ["native-tls-vendored"], optional = true }
|
|
||||||
tauri-utils = { version = "=1.4.*", optional = true }
|
|
||||||
once_cell = "1.18.0"
|
once_cell = "1.18.0"
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
|
|
||||||
|
# bundling
|
||||||
|
tauri-bundler = { version = "=1.3.0", features = ["native-tls-vendored"], optional = true }
|
||||||
|
tauri-utils = { version = "=1.4.*", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
cli = ["tauri-bundler", "tauri-utils"]
|
cli = ["tauri-bundler", "tauri-utils", "clap", "toml", "cargo_toml"]
|
||||||
@@ -1,20 +1,16 @@
|
|||||||
use crate::BundleConfig;
|
use crate::BundleConfig;
|
||||||
use crate::CargoError;
|
use crate::CargoError;
|
||||||
use crate::{crate_root, Metadata};
|
|
||||||
use clap::ValueEnum;
|
|
||||||
use core::fmt::{Display, Formatter};
|
use core::fmt::{Display, Formatter};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::path::PathBuf;
|
||||||
collections::HashMap,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Serialize, Deserialize, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Debug)]
|
||||||
|
#[cfg_attr(feature = "cli", derive(clap::ValueEnum))]
|
||||||
pub enum Platform {
|
pub enum Platform {
|
||||||
#[clap(name = "web")]
|
#[cfg_attr(feature = "cli", clap(name = "web"))]
|
||||||
#[serde(rename = "web")]
|
#[serde(rename = "web")]
|
||||||
Web,
|
Web,
|
||||||
#[clap(name = "desktop")]
|
#[cfg_attr(feature = "cli", clap(name = "desktop"))]
|
||||||
#[serde(rename = "desktop")]
|
#[serde(rename = "desktop")]
|
||||||
Desktop,
|
Desktop,
|
||||||
}
|
}
|
||||||
@@ -28,10 +24,12 @@ pub struct DioxusConfig {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub bundle: BundleConfig,
|
pub bundle: BundleConfig,
|
||||||
|
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
#[serde(default = "default_plugin")]
|
#[serde(default = "default_plugin")]
|
||||||
pub plugin: toml::Value,
|
pub plugin: toml::Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
fn default_plugin() -> toml::Value {
|
fn default_plugin() -> toml::Value {
|
||||||
toml::Value::Boolean(true)
|
toml::Value::Boolean(true)
|
||||||
}
|
}
|
||||||
@@ -54,6 +52,7 @@ impl std::error::Error for LoadDioxusConfigError {}
|
|||||||
pub enum CrateConfigError {
|
pub enum CrateConfigError {
|
||||||
Cargo(CargoError),
|
Cargo(CargoError),
|
||||||
Io(std::io::Error),
|
Io(std::io::Error),
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
Toml(toml::de::Error),
|
Toml(toml::de::Error),
|
||||||
LoadDioxusConfig(LoadDioxusConfigError),
|
LoadDioxusConfig(LoadDioxusConfigError),
|
||||||
}
|
}
|
||||||
@@ -70,6 +69,7 @@ impl From<std::io::Error> for CrateConfigError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
impl From<toml::de::Error> for CrateConfigError {
|
impl From<toml::de::Error> for CrateConfigError {
|
||||||
fn from(err: toml::de::Error) -> Self {
|
fn from(err: toml::de::Error) -> Self {
|
||||||
Self::Toml(err)
|
Self::Toml(err)
|
||||||
@@ -87,6 +87,7 @@ impl Display for CrateConfigError {
|
|||||||
match self {
|
match self {
|
||||||
Self::Cargo(err) => write!(f, "{}", err),
|
Self::Cargo(err) => write!(f, "{}", err),
|
||||||
Self::Io(err) => write!(f, "{}", err),
|
Self::Io(err) => write!(f, "{}", err),
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
Self::Toml(err) => write!(f, "{}", err),
|
Self::Toml(err) => write!(f, "{}", err),
|
||||||
Self::LoadDioxusConfig(err) => write!(f, "{}", err),
|
Self::LoadDioxusConfig(err) => write!(f, "{}", err),
|
||||||
}
|
}
|
||||||
@@ -96,6 +97,7 @@ impl Display for CrateConfigError {
|
|||||||
impl std::error::Error for CrateConfigError {}
|
impl std::error::Error for CrateConfigError {}
|
||||||
|
|
||||||
impl DioxusConfig {
|
impl DioxusConfig {
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
/// Load the dioxus config from a path
|
/// Load the dioxus config from a path
|
||||||
pub fn load(bin: Option<PathBuf>) -> Result<Option<DioxusConfig>, CrateConfigError> {
|
pub fn load(bin: Option<PathBuf>) -> Result<Option<DioxusConfig>, CrateConfigError> {
|
||||||
let crate_dir = crate::cargo::crate_root();
|
let crate_dir = crate::cargo::crate_root();
|
||||||
@@ -145,7 +147,8 @@ impl DioxusConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn acquire_dioxus_toml(dir: &Path) -> Option<PathBuf> {
|
#[cfg(feature = "cli")]
|
||||||
|
fn acquire_dioxus_toml(dir: &std::path::Path) -> Option<PathBuf> {
|
||||||
// prefer uppercase
|
// prefer uppercase
|
||||||
let uppercase_conf = dir.join("Dioxus.toml");
|
let uppercase_conf = dir.join("Dioxus.toml");
|
||||||
if uppercase_conf.is_file() {
|
if uppercase_conf.is_file() {
|
||||||
@@ -171,6 +174,7 @@ impl Default for DioxusConfig {
|
|||||||
out_dir: out_dir_default(),
|
out_dir: out_dir_default(),
|
||||||
asset_dir: asset_dir_default(),
|
asset_dir: asset_dir_default(),
|
||||||
|
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
tools: Default::default(),
|
tools: Default::default(),
|
||||||
|
|
||||||
sub_package: None,
|
sub_package: None,
|
||||||
@@ -202,6 +206,7 @@ impl Default for DioxusConfig {
|
|||||||
publisher: Some(name),
|
publisher: Some(name),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
plugin: toml::Value::Table(toml::map::Map::new()),
|
plugin: toml::Value::Table(toml::map::Map::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,8 +223,9 @@ pub struct ApplicationConfig {
|
|||||||
#[serde(default = "asset_dir_default")]
|
#[serde(default = "asset_dir_default")]
|
||||||
pub asset_dir: PathBuf,
|
pub asset_dir: PathBuf,
|
||||||
|
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub tools: HashMap<String, toml::Value>,
|
pub tools: std::collections::HashMap<String, toml::Value>,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub sub_package: Option<String>,
|
pub sub_package: Option<String>,
|
||||||
@@ -334,6 +340,7 @@ pub struct CrateConfig {
|
|||||||
pub workspace_dir: PathBuf,
|
pub workspace_dir: PathBuf,
|
||||||
pub target_dir: PathBuf,
|
pub target_dir: PathBuf,
|
||||||
pub asset_dir: PathBuf,
|
pub asset_dir: PathBuf,
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
pub manifest: cargo_toml::Manifest<cargo_toml::Value>,
|
pub manifest: cargo_toml::Manifest<cargo_toml::Value>,
|
||||||
pub executable: ExecutableType,
|
pub executable: ExecutableType,
|
||||||
pub dioxus_config: DioxusConfig,
|
pub dioxus_config: DioxusConfig,
|
||||||
@@ -353,10 +360,11 @@ pub enum ExecutableType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CrateConfig {
|
impl CrateConfig {
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
pub fn new(bin: Option<PathBuf>) -> Result<Self, CrateConfigError> {
|
pub fn new(bin: Option<PathBuf>) -> Result<Self, CrateConfigError> {
|
||||||
let dioxus_config = DioxusConfig::load(bin.clone())?.unwrap_or_default();
|
let dioxus_config = DioxusConfig::load(bin.clone())?.unwrap_or_default();
|
||||||
|
|
||||||
let crate_root = crate_root()?;
|
let crate_root = crate::crate_root()?;
|
||||||
|
|
||||||
let crate_dir = if let Some(package) = &dioxus_config.application.sub_package {
|
let crate_dir = if let Some(package) = &dioxus_config.application.sub_package {
|
||||||
crate_root.join(package)
|
crate_root.join(package)
|
||||||
@@ -366,7 +374,7 @@ impl CrateConfig {
|
|||||||
crate_root
|
crate_root
|
||||||
};
|
};
|
||||||
|
|
||||||
let meta = Metadata::get()?;
|
let meta = crate::Metadata::get()?;
|
||||||
let workspace_dir = meta.workspace_root;
|
let workspace_dir = meta.workspace_root;
|
||||||
let target_dir = meta.target_directory;
|
let target_dir = meta.target_directory;
|
||||||
|
|
||||||
@@ -411,6 +419,7 @@ impl CrateConfig {
|
|||||||
workspace_dir,
|
workspace_dir,
|
||||||
target_dir,
|
target_dir,
|
||||||
asset_dir,
|
asset_dir,
|
||||||
|
#[cfg(feature = "cli")]
|
||||||
manifest,
|
manifest,
|
||||||
executable,
|
executable,
|
||||||
release,
|
release,
|
||||||
|
|||||||
Reference in new issue
Block a user