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