feat: commit code
This commit is contained in:
1 parent
0ff4881d54
commit
bb69a04045
6 files changed
+55
-38
No files matched your search
+2
-2
@@ -7,11 +7,11 @@ name = "dioxus-cli"
|
|||||||
# desktop, web, mobile, ssr
|
# desktop, web, mobile, ssr
|
||||||
platforms = ["web"]
|
platforms = ["web"]
|
||||||
|
|
||||||
[web.app]
|
|
||||||
|
|
||||||
# Web `build` & `serve` dist path
|
# Web `build` & `serve` dist path
|
||||||
out_dir = "dist"
|
out_dir = "dist"
|
||||||
|
|
||||||
|
[web.app]
|
||||||
|
|
||||||
# resource (static) file folder
|
# resource (static) file folder
|
||||||
public_dir = "public"
|
public_dir = "public"
|
||||||
|
|
||||||
|
|||||||
+48
-28
@@ -1,4 +1,9 @@
|
|||||||
use std::{io::Write, path::PathBuf, process::Command, fs::copy};
|
use std::{
|
||||||
|
fs::{copy, create_dir_all},
|
||||||
|
io::Write,
|
||||||
|
path::PathBuf,
|
||||||
|
process::Command,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{cfg::ConfigOptsBuild, gen_page};
|
use crate::{cfg::ConfigOptsBuild, gen_page};
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
@@ -25,7 +30,7 @@ impl Build {
|
|||||||
|
|
||||||
if self.build.platform.is_some() {
|
if self.build.platform.is_some() {
|
||||||
if self.build.platform.unwrap().to_uppercase() == "DESKTOP" {
|
if self.build.platform.unwrap().to_uppercase() == "DESKTOP" {
|
||||||
log::info!("🚅 Running build command...");
|
log::info!("🚅 Running build [Desktop] command...");
|
||||||
|
|
||||||
let mut cmd = Command::new("cargo");
|
let mut cmd = Command::new("cargo");
|
||||||
cmd.current_dir(&crate_config.crate_dir)
|
cmd.current_dir(&crate_config.crate_dir)
|
||||||
@@ -47,36 +52,52 @@ impl Build {
|
|||||||
|
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
if crate_config.out_dir.is_dir() {
|
if crate_config.out_dir.is_dir() {
|
||||||
|
|
||||||
remove_dir_all(&crate_config.out_dir)?;
|
remove_dir_all(&crate_config.out_dir)?;
|
||||||
|
}
|
||||||
|
|
||||||
let release_type = match crate_config.release {
|
let release_type = match crate_config.release {
|
||||||
true => "release",
|
true => "release",
|
||||||
false => "debug",
|
false => "debug",
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut res_path = match &crate_config.executable {
|
let file_name: String;
|
||||||
crate::ExecutableType::Binary(name)
|
let mut res_path = match &crate_config.executable {
|
||||||
| crate::ExecutableType::Lib(name) => crate_config
|
crate::ExecutableType::Binary(name) | crate::ExecutableType::Lib(name) => {
|
||||||
|
file_name = name.clone();
|
||||||
|
crate_config
|
||||||
.target_dir
|
.target_dir
|
||||||
.join(format!("{}", release_type))
|
.join(format!("{}", release_type))
|
||||||
.join(format!("{}", name)),
|
.join(format!("{}", name))
|
||||||
|
|
||||||
crate::ExecutableType::Example(name) => crate_config
|
|
||||||
.target_dir
|
|
||||||
.join(format!("{}/examples", release_type))
|
|
||||||
.join(format!("{}", name)),
|
|
||||||
};
|
|
||||||
|
|
||||||
let target_file;
|
|
||||||
if cfg!(windows) {
|
|
||||||
res_path.set_extension("exe");
|
|
||||||
target_file = format!("{}.exe", &crate_config.dioxus_config.application.name);
|
|
||||||
} else {
|
|
||||||
target_file = crate_config.dioxus_config.application.name.clone();
|
|
||||||
}
|
}
|
||||||
copy(res_path, &crate_config.out_dir.join(target_file))?;
|
crate::ExecutableType::Example(name) => {
|
||||||
|
file_name = name.clone();
|
||||||
|
crate_config
|
||||||
|
.target_dir
|
||||||
|
.join(format!("{}", release_type))
|
||||||
|
.join("examples")
|
||||||
|
.join(format!("{}", name))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let target_file;
|
||||||
|
if cfg!(windows) {
|
||||||
|
res_path.set_extension("exe");
|
||||||
|
target_file = format!("{}.exe", &file_name);
|
||||||
|
} else {
|
||||||
|
target_file = file_name.clone();
|
||||||
}
|
}
|
||||||
|
create_dir_all(&crate_config.out_dir)?;
|
||||||
|
copy(res_path, &crate_config.out_dir.join(target_file))?;
|
||||||
|
|
||||||
|
log::info!(
|
||||||
|
"🏛 Build completed: [:{}]",
|
||||||
|
&crate_config
|
||||||
|
.dioxus_config
|
||||||
|
.application
|
||||||
|
.out_dir
|
||||||
|
.unwrap_or(PathBuf::from("dist"))
|
||||||
|
.display()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -93,8 +114,7 @@ impl Build {
|
|||||||
.join(
|
.join(
|
||||||
crate_config
|
crate_config
|
||||||
.dioxus_config
|
.dioxus_config
|
||||||
.web
|
.application
|
||||||
.app
|
|
||||||
.out_dir
|
.out_dir
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or(PathBuf::from("dist")),
|
.unwrap_or(PathBuf::from("dist")),
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use std::path::PathBuf;
|
|||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
/// Config options for the build system.
|
/// Config options for the build system.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, StructOpt)]
|
#[derive(Clone, Debug, Default, Deserialize, StructOpt)]
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ impl Clean {
|
|||||||
|
|
||||||
let out_dir = crate_config
|
let out_dir = crate_config
|
||||||
.dioxus_config
|
.dioxus_config
|
||||||
.web
|
.application
|
||||||
.app
|
|
||||||
.out_dir
|
.out_dir
|
||||||
.unwrap_or(PathBuf::from("dist"));
|
.unwrap_or(PathBuf::from("dist"));
|
||||||
if crate_config.crate_dir.join(&out_dir).is_dir() {
|
if crate_config.crate_dir.join(&out_dir).is_dir() {
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ impl Serve {
|
|||||||
.join(
|
.join(
|
||||||
crate_config
|
crate_config
|
||||||
.dioxus_config
|
.dioxus_config
|
||||||
.web
|
.application
|
||||||
.app
|
|
||||||
.out_dir
|
.out_dir
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or(PathBuf::from("dist")),
|
.unwrap_or(PathBuf::from("dist")),
|
||||||
|
|||||||
+3
-3
@@ -39,11 +39,11 @@ impl Default for DioxusConfig {
|
|||||||
application: ApplicationConfig {
|
application: ApplicationConfig {
|
||||||
name: "dioxus".into(),
|
name: "dioxus".into(),
|
||||||
platforms: vec![String::from("web")],
|
platforms: vec![String::from("web")],
|
||||||
|
out_dir: Some(PathBuf::from("dist")),
|
||||||
},
|
},
|
||||||
web: WebConfig {
|
web: WebConfig {
|
||||||
app: WebAppConfing {
|
app: WebAppConfing {
|
||||||
title: Some("dioxus | ⛺".into()),
|
title: Some("dioxus | ⛺".into()),
|
||||||
out_dir: Some(PathBuf::from("dist")),
|
|
||||||
public_dir: Some(PathBuf::from("public")),
|
public_dir: Some(PathBuf::from("public")),
|
||||||
},
|
},
|
||||||
watcher: WebWatcherConfing {
|
watcher: WebWatcherConfing {
|
||||||
@@ -67,6 +67,7 @@ impl Default for DioxusConfig {
|
|||||||
pub struct ApplicationConfig {
|
pub struct ApplicationConfig {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub platforms: Vec<String>,
|
pub platforms: Vec<String>,
|
||||||
|
pub out_dir: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@@ -79,7 +80,6 @@ pub struct WebConfig {
|
|||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct WebAppConfing {
|
pub struct WebAppConfing {
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
pub out_dir: Option<PathBuf>,
|
|
||||||
pub public_dir: Option<PathBuf>,
|
pub public_dir: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ impl CrateConfig {
|
|||||||
let workspace_dir = crate::cargo::workspace_root()?;
|
let workspace_dir = crate::cargo::workspace_root()?;
|
||||||
let target_dir = workspace_dir.join("target");
|
let target_dir = workspace_dir.join("target");
|
||||||
|
|
||||||
let out_dir = match dioxus_config.web.app.out_dir {
|
let out_dir = match dioxus_config.application.out_dir {
|
||||||
Some(ref v) => crate_dir.join(v),
|
Some(ref v) => crate_dir.join(v),
|
||||||
None => crate_dir.join("dist"),
|
None => crate_dir.join("dist"),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user