feat: bin flag for serve and build

This commit is contained in:
Miles Murgaw 2023-07-14 20:06:54 -04:00
parent bfbca2653f
commit 41fd7a1040
7 changed files with 28 additions and 13 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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.

View file

@ -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")

View file

@ -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");

View file

@ -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);

View file

@ -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;