feat: add Dioxus.toml
This commit is contained in:
1 parent
70adff7e44
commit
9bb10c65a3
13 files changed
+269
-170
No files matched your search
@@ -1,5 +1,3 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::cfg::ConfigOptsBuild;
|
||||
use structopt::StructOpt;
|
||||
|
||||
@@ -18,10 +16,7 @@ impl Build {
|
||||
// change the relase state.
|
||||
crate_config.with_release(self.build.release);
|
||||
|
||||
crate::builder::build(
|
||||
&crate_config,
|
||||
self.build.dist.unwrap_or(PathBuf::from("dist")),
|
||||
)?;
|
||||
crate::builder::build(&crate_config)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -16,14 +16,6 @@ pub struct ConfigOptsBuild {
|
||||
#[serde(default)]
|
||||
pub release: bool,
|
||||
|
||||
/// The output dir for all final assets [default: dist]
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
pub dist: Option<PathBuf>,
|
||||
|
||||
/// The public URL from which assets are to be served [default: /]
|
||||
#[structopt(long, parse(from_str=parse_public_url))]
|
||||
pub public_url: Option<String>,
|
||||
|
||||
/// Optional pattern for the app loader script [default: None]
|
||||
///
|
||||
/// Patterns should include the sequences `{base}`, `{wasm}`, and `{js}` in order to
|
||||
@@ -74,14 +66,6 @@ pub struct ConfigOptsServe {
|
||||
#[structopt(long)]
|
||||
#[serde(default)]
|
||||
pub release: bool,
|
||||
|
||||
/// The output dir for all final assets [default: dist]
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
pub dist: Option<PathBuf>,
|
||||
|
||||
/// The public URL from which assets are to be served [default: /]
|
||||
#[structopt(long, parse(from_str=parse_public_url))]
|
||||
pub public_url: Option<String>,
|
||||
}
|
||||
|
||||
/// Ensure the given value for `--public-url` is formatted correctly.
|
||||
|
||||
+19
-8
@@ -13,9 +13,9 @@ use crate::error::{Error, Result};
|
||||
#[derive(Clone, Debug, StructOpt)]
|
||||
#[structopt(name = "init")]
|
||||
pub struct Init {
|
||||
/// Init project path
|
||||
/// Init project name
|
||||
#[structopt(default_value = ".")]
|
||||
path: String,
|
||||
name: String,
|
||||
|
||||
/// Template path
|
||||
#[structopt(default_value = "default", long)]
|
||||
@@ -24,18 +24,23 @@ pub struct Init {
|
||||
|
||||
impl Init {
|
||||
pub fn init(self) -> Result<()> {
|
||||
log::info!("🔧 Start to init a new project '{}'.", self.path);
|
||||
if self.name.contains(".") {
|
||||
log::error!("❗Unsupported project name.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let project_path = PathBuf::from(&self.path);
|
||||
log::info!("🔧 Start to init a new project '{}'.", self.name);
|
||||
|
||||
let project_path = PathBuf::from(&self.name);
|
||||
|
||||
if project_path.join("Cargo.toml").is_file() {
|
||||
log::warn!("Path '{}' is initialized.", self.path);
|
||||
log::warn!("Folder '{}' is initialized.", self.name);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let output = Command::new("cargo")
|
||||
.arg("init")
|
||||
.arg(&self.path)
|
||||
.arg(&format!("./{}", self.name))
|
||||
.arg("--bin")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
@@ -58,6 +63,11 @@ impl Init {
|
||||
let mut file = File::create(main_rs_file)?;
|
||||
file.write_all(&template_str.as_bytes())?;
|
||||
|
||||
let mut file = File::create(project_path.join("Dioxus.toml"))?;
|
||||
let dioxus_conf = String::from(include_str!("../../template/config.toml"))
|
||||
.replace("{project-name}", &self.name);
|
||||
file.write_all(dioxus_conf.as_bytes())?;
|
||||
|
||||
// log::info!("🎯 Project initialization completed.");
|
||||
|
||||
if !Command::new("cargo")
|
||||
@@ -72,8 +82,9 @@ impl Init {
|
||||
file.write_all("dioxus = { version = \"0.1.7\", features = [\"web\"] }".as_bytes())?;
|
||||
}
|
||||
|
||||
log::info!("\n💡 Project initialized:");
|
||||
log::info!("🎯> cd {}", self.path);
|
||||
println!("");
|
||||
log::info!("💡 Project initialized:");
|
||||
log::info!("🎯> cd ./{}", self.name);
|
||||
log::info!("🎯> dioxus serve");
|
||||
|
||||
Ok(())
|
||||
|
||||
+20
-8
@@ -1,4 +1,4 @@
|
||||
use crate::{cfg::ConfigOptsServe, server};
|
||||
use crate::{cfg::ConfigOptsServe, gen_page, server};
|
||||
use std::{io::Write, path::PathBuf};
|
||||
use structopt::StructOpt;
|
||||
|
||||
@@ -16,19 +16,31 @@ impl Serve {
|
||||
// change the relase state.
|
||||
crate_config.with_release(self.serve.release);
|
||||
|
||||
let dist_path = self.serve.dist.clone().unwrap_or(PathBuf::from("dist"));
|
||||
crate::builder::build(&crate_config).expect("build failed");
|
||||
|
||||
crate::builder::build(&crate_config, dist_path.clone()).expect("build failed");
|
||||
let serve_html = gen_page(&crate_config.dioxus_config, true);
|
||||
|
||||
let serve_html = String::from(include_str!("../../server/serve.html"));
|
||||
|
||||
let mut file =
|
||||
std::fs::File::create(crate_config.crate_dir.join(dist_path).join("index.html"))?;
|
||||
let mut file = std::fs::File::create(
|
||||
crate_config
|
||||
.crate_dir
|
||||
.join(
|
||||
crate_config
|
||||
.dioxus_config
|
||||
.web
|
||||
.app
|
||||
.out_dir
|
||||
.clone()
|
||||
.unwrap_or(PathBuf::from("dist")),
|
||||
)
|
||||
.join("index.html"),
|
||||
)?;
|
||||
file.write_all(serve_html.as_bytes())?;
|
||||
|
||||
// start the develop server
|
||||
server::startup(crate_config.clone(), &self.serve).await?;
|
||||
server::startup(crate_config.clone()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn regen_page() {}
|
||||
}
|
||||
Reference in new issue
Block a user