mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-24 05:03:06 +00:00
fix: commit code
This commit is contained in:
parent
25e3ee848c
commit
b01b3f519f
8 changed files with 67 additions and 47 deletions
|
@ -170,13 +170,13 @@ pub fn build_desktop(config: &CrateConfig) -> Result<()> {
|
|||
}
|
||||
};
|
||||
|
||||
let target_file;
|
||||
if cfg!(windows) {
|
||||
let target_file = if cfg!(windows) {
|
||||
res_path.set_extension("exe");
|
||||
target_file = format!("{}.exe", &file_name);
|
||||
format!("{}.exe", &file_name)
|
||||
} else {
|
||||
target_file = file_name;
|
||||
}
|
||||
file_name
|
||||
};
|
||||
|
||||
create_dir_all(&config.out_dir)?;
|
||||
copy(res_path, &config.out_dir.join(target_file))?;
|
||||
|
||||
|
@ -238,7 +238,12 @@ pub fn gen_page(config: &DioxusConfig, serve: bool) -> String {
|
|||
|
||||
html = html.replace("{app_name}", &config.application.name);
|
||||
|
||||
let title = config.web.app.title.clone().unwrap_or_else(|| "dioxus | ⛺".into());
|
||||
let title = config
|
||||
.web
|
||||
.app
|
||||
.title
|
||||
.clone()
|
||||
.unwrap_or_else(|| "dioxus | ⛺".into());
|
||||
|
||||
html.replace("{app_title}", &title)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
//! Utilities for working with cargo and rust files
|
||||
use crate::error::{Error, Result};
|
||||
use std::{env, fs, path::{PathBuf, Path}, process::Command, str};
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
str,
|
||||
};
|
||||
|
||||
/// How many parent folders are searched for a `Cargo.toml`
|
||||
const MAX_ANCESTORS: u32 = 10;
|
||||
|
|
|
@ -22,12 +22,18 @@ impl Build {
|
|||
crate_config.as_example(self.build.example.unwrap());
|
||||
}
|
||||
|
||||
if self.build.platform.is_some() && self.build.platform.unwrap().to_uppercase() == "DESKTOP" {
|
||||
crate::builder::build_desktop(&crate_config)?;
|
||||
match self.build.platform.as_str() {
|
||||
"web" => {
|
||||
crate::builder::build(&crate_config)?;
|
||||
}
|
||||
"desktop" => {
|
||||
crate::builder::build_desktop(&crate_config)?;
|
||||
}
|
||||
_ => {
|
||||
return Err(anyhow::anyhow!("Unsoppurt platform target."));
|
||||
}
|
||||
}
|
||||
|
||||
crate::builder::build(&crate_config)?;
|
||||
|
||||
let temp = gen_page(&crate_config.dioxus_config, false);
|
||||
|
||||
let mut file = std::fs::File::create(
|
||||
|
|
|
@ -20,8 +20,8 @@ pub struct ConfigOptsBuild {
|
|||
pub example: Option<String>,
|
||||
|
||||
/// Build platform: support Web & Desktop [default: "web"]
|
||||
#[structopt(long)]
|
||||
pub platform: Option<String>,
|
||||
#[structopt(long, default_value = "web")]
|
||||
pub platform: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, StructOpt)]
|
||||
|
@ -40,8 +40,8 @@ pub struct ConfigOptsServe {
|
|||
pub release: bool,
|
||||
|
||||
/// Build platform: support Web & Desktop [default: "web"]
|
||||
#[structopt(long)]
|
||||
pub platform: Option<String>,
|
||||
#[structopt(long, default_value = "web")]
|
||||
pub platform: String,
|
||||
}
|
||||
|
||||
/// Ensure the given value for `--public-url` is formatted correctly.
|
||||
|
|
|
@ -21,25 +21,38 @@ impl Serve {
|
|||
crate_config.as_example(self.serve.example.unwrap());
|
||||
}
|
||||
|
||||
if self.serve.platform.is_some() && self.serve.platform.unwrap().to_uppercase() == "DESKTOP" {
|
||||
crate::builder::build_desktop(&crate_config)?;
|
||||
|
||||
match &crate_config.executable {
|
||||
crate::ExecutableType::Binary(name)
|
||||
| crate::ExecutableType::Lib(name)
|
||||
| crate::ExecutableType::Example(name) => {
|
||||
let mut file = crate_config.out_dir.join(name);
|
||||
if cfg!(windows) {
|
||||
file.set_extension("exe");
|
||||
}
|
||||
Command::new(crate_config.out_dir.join(file).to_str().unwrap().to_string())
|
||||
.output()?;
|
||||
}
|
||||
match self.serve.platform.as_str() {
|
||||
"web" => {
|
||||
crate::builder::build(&crate_config)?;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
"desktop" => {
|
||||
crate::builder::build_desktop(&crate_config)?;
|
||||
|
||||
crate::builder::build(&crate_config).expect("build failed");
|
||||
match &crate_config.executable {
|
||||
crate::ExecutableType::Binary(name)
|
||||
| crate::ExecutableType::Lib(name)
|
||||
| crate::ExecutableType::Example(name) => {
|
||||
let mut file = crate_config.out_dir.join(name);
|
||||
if cfg!(windows) {
|
||||
file.set_extension("exe");
|
||||
}
|
||||
Command::new(
|
||||
crate_config
|
||||
.out_dir
|
||||
.join(file)
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
)
|
||||
.output()?;
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
_ => {
|
||||
return Err(anyhow::anyhow!("Unsoppurt platform target."));
|
||||
}
|
||||
}
|
||||
|
||||
// generate dev-index page
|
||||
Serve::regen_dev_page(&crate_config)?;
|
||||
|
|
|
@ -13,9 +13,8 @@ impl DioxusConfig {
|
|||
let crate_dir = crate::cargo::crate_root()?;
|
||||
|
||||
if !crate_dir.join("Dioxus.toml").is_file() {
|
||||
return Err(crate::error::Error::Unique(
|
||||
"Config file: `Dioxus.toml` not found.".into(),
|
||||
));
|
||||
log::warn!("Config file: `Dioxus.toml` not found; using default config.");
|
||||
return Ok(DioxusConfig::default());
|
||||
}
|
||||
|
||||
let mut dioxus_conf_file = File::open(crate_dir.join("Dioxus.toml"))?;
|
||||
|
@ -151,12 +150,7 @@ impl CrateConfig {
|
|||
.lib
|
||||
.as_ref()
|
||||
.and_then(|lib| lib.name.clone())
|
||||
.or_else(|| {
|
||||
manifest
|
||||
.package
|
||||
.as_ref().map(|pkg| pkg.name.clone())
|
||||
|
||||
})
|
||||
.or_else(|| manifest.package.as_ref().map(|pkg| pkg.name.clone()))
|
||||
.expect("No lib found from cargo metadata");
|
||||
let executable = ExecutableType::Binary(output_filename);
|
||||
|
||||
|
|
|
@ -25,9 +25,6 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
// Commands::Config(_) => {
|
||||
// //
|
||||
// }
|
||||
Commands::Serve(opts) => {
|
||||
if let Err(e) = opts.serve().await {
|
||||
log::error!("serve error: {}", e);
|
||||
|
|
|
@ -58,16 +58,16 @@ pub async fn startup(config: CrateConfig) -> anyhow::Result<()> {
|
|||
| DebouncedEvent::Write(e)
|
||||
| DebouncedEvent::Remove(e)
|
||||
| DebouncedEvent::Rename(e, _) => {
|
||||
let mut reload = false;
|
||||
let mut should_reload = false;
|
||||
for path in &allow_watch_path {
|
||||
let temp = crate_dir.clone().join(path);
|
||||
if e.starts_with(temp) {
|
||||
reload = true;
|
||||
should_reload = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if reload && builder::build(&watcher_conf).is_ok() {
|
||||
if should_reload && builder::build(&watcher_conf).is_ok() {
|
||||
// change the websocket reload state to true;
|
||||
// the page will auto-reload.
|
||||
if watcher_conf
|
||||
|
|
Loading…
Reference in a new issue