mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-26 22:20:19 +00:00
feat: bin flag for serve and build
This commit is contained in:
parent
bfbca2653f
commit
41fd7a1040
7 changed files with 28 additions and 13 deletions
|
@ -78,7 +78,7 @@ impl Autoformat {
|
|||
///
|
||||
/// Doesn't do mod-descending, so it will still try to format unreachable files. TODO.
|
||||
async fn autoformat_project(check: bool) -> Result<()> {
|
||||
let crate_config = crate::CrateConfig::new()?;
|
||||
let crate_config = crate::CrateConfig::new(None)?;
|
||||
|
||||
let mut files_to_format = vec![];
|
||||
collect_rs_files(&crate_config.crate_dir, &mut files_to_format);
|
||||
|
|
|
@ -13,7 +13,7 @@ pub struct Build {
|
|||
|
||||
impl Build {
|
||||
pub fn build(self) -> Result<()> {
|
||||
let mut crate_config = crate::CrateConfig::new()?;
|
||||
let mut crate_config = crate::CrateConfig::new(self.build.bin)?;
|
||||
|
||||
// change the release state.
|
||||
crate_config.with_release(self.build.release);
|
||||
|
|
|
@ -32,6 +32,10 @@ pub struct ConfigOptsBuild {
|
|||
/// Space separated list of features to activate
|
||||
#[clap(long)]
|
||||
pub features: Option<Vec<String>>,
|
||||
|
||||
/// The binary to serve
|
||||
#[clap(long)]
|
||||
pub bin: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Parser)]
|
||||
|
@ -86,6 +90,10 @@ pub struct ConfigOptsServe {
|
|||
/// Space separated list of features to activate
|
||||
#[clap(long)]
|
||||
pub features: Option<Vec<String>>,
|
||||
|
||||
/// The binary to serve
|
||||
#[clap(long)]
|
||||
pub bin: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// Ensure the given value for `--public-url` is formatted correctly.
|
||||
|
|
|
@ -7,7 +7,7 @@ pub struct Clean {}
|
|||
|
||||
impl Clean {
|
||||
pub fn clean(self) -> Result<()> {
|
||||
let crate_config = crate::CrateConfig::new()?;
|
||||
let crate_config = crate::CrateConfig::new(None)?;
|
||||
|
||||
let output = Command::new("cargo")
|
||||
.arg("clean")
|
||||
|
|
|
@ -48,7 +48,7 @@ impl Config {
|
|||
log::info!("🚩 Init config file completed.");
|
||||
}
|
||||
Config::FormatPrint {} => {
|
||||
println!("{:#?}", crate::CrateConfig::new()?.dioxus_config);
|
||||
println!("{:#?}", crate::CrateConfig::new(None)?.dioxus_config);
|
||||
}
|
||||
Config::CustomHtml {} => {
|
||||
let html_path = crate_root.join("index.html");
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct Serve {
|
|||
|
||||
impl Serve {
|
||||
pub async fn serve(self) -> Result<()> {
|
||||
let mut crate_config = crate::CrateConfig::new()?;
|
||||
let mut crate_config = crate::CrateConfig::new(self.serve.bin)?;
|
||||
|
||||
// change the relase state.
|
||||
crate_config.with_hot_reload(self.serve.hot_reload);
|
||||
|
|
|
@ -176,14 +176,19 @@ pub enum ExecutableType {
|
|||
}
|
||||
|
||||
impl CrateConfig {
|
||||
pub fn new() -> Result<Self> {
|
||||
pub fn new(bin: Option<PathBuf>) -> Result<Self> {
|
||||
let dioxus_config = DioxusConfig::load()?.unwrap_or_default();
|
||||
|
||||
let crate_root = crate::cargo::crate_root()?;
|
||||
|
||||
let crate_dir = if let Some(package) = &dioxus_config.application.sub_package {
|
||||
crate::cargo::crate_root()?.join(package)
|
||||
crate_root.join(package)
|
||||
} else if let Some(bin) = bin {
|
||||
crate_root.join(bin)
|
||||
} else {
|
||||
crate::cargo::crate_root()?
|
||||
crate_root
|
||||
};
|
||||
|
||||
let meta = crate::cargo::Metadata::get()?;
|
||||
let workspace_dir = meta.workspace_root;
|
||||
let target_dir = meta.target_directory;
|
||||
|
@ -202,8 +207,9 @@ impl CrateConfig {
|
|||
|
||||
let manifest = cargo_toml::Manifest::from_path(cargo_def).unwrap();
|
||||
|
||||
let output_filename = {
|
||||
match &manifest.package.as_ref().unwrap().default_run {
|
||||
let mut output_filename = String::from("dioxus_app");
|
||||
if let Some(package) = &manifest.package.as_ref() {
|
||||
output_filename = match &package.default_run {
|
||||
Some(default_run_target) => default_run_target.to_owned(),
|
||||
None => manifest
|
||||
.bin
|
||||
|
@ -216,9 +222,10 @@ impl CrateConfig {
|
|||
.or(manifest.bin.first())
|
||||
.or(manifest.lib.as_ref())
|
||||
.and_then(|prod| prod.name.clone())
|
||||
.expect("No executable or library found from cargo metadata."),
|
||||
}
|
||||
};
|
||||
.unwrap_or(String::from("dioxus_app")),
|
||||
};
|
||||
}
|
||||
|
||||
let executable = ExecutableType::Binary(output_filename);
|
||||
|
||||
let release = false;
|
||||
|
|
Loading…
Reference in a new issue