fix: dist setting

This commit is contained in:
mrxiaozhuox committed 2022-01-23 10:54:24 +08:00
1 parent f80303c00b
commit 5395e7693c
9 files changed
+61 -26

No files matched your search

+6 -1
View File
@@ -1,3 +1,5 @@
use std::path::PathBuf;
use crate::cfg::ConfigOptsBuild;
use structopt::StructOpt;
@@ -16,7 +18,10 @@ impl Build {
// change the relase state.
crate_config.with_release(self.build.release);
crate::builder::build(&crate_config)?;
crate::builder::build(
&crate_config,
self.build.dist.unwrap_or(PathBuf::from("dist")),
)?;
Ok(())
}
+29 -9
View File
@@ -1,14 +1,18 @@
use std::{process::{Command, Stdio}, fs::File, path::PathBuf, io::Write};
use std::{
fs::{File, OpenOptions},
io::Write,
path::PathBuf,
process::{Command, Stdio},
};
use structopt::StructOpt;
use crate::{error::{Error, Result}, cargo};
use crate::error::{Error, Result};
/// Build the Rust WASM app and all of its assets.
#[derive(Clone, Debug, StructOpt)]
#[structopt(name = "init")]
pub struct Init {
/// Init project path
#[structopt(default_value = ".")]
path: String,
@@ -16,24 +20,26 @@ pub struct Init {
/// Template path
#[structopt(default_value = "default", long)]
template: String,
}
impl Init {
pub fn init(self) -> Result<()> {
log::info!("🔧 Start to init a new project '{}'.", self.path);
let project_path = PathBuf::from(&self.path);
if project_path.join("Cargo.toml").is_file() {
log::warn!("Path '{}' is initialized.", self.path);
return Ok(());
}
let output = Command::new("cargo")
.arg("init")
.arg(&self.path)
.arg("--bin")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()?
;
.output()?;
if !output.status.success() {
return Err(Error::CargoError("Cargo init failed".into()));
@@ -54,8 +60,22 @@ impl Init {
// log::info!("🎯 Project initialization completed.");
if !Command::new("cargo")
.args(["add", "dioxus", "--features web"])
.output()?
.status
.success()
{
let mut file = OpenOptions::new()
.append(true)
.open(project_path.join("Cargo.toml"))?;
file.write_all("dioxus = { version = \"0.1.7\", features = [\"web\"] }".as_bytes())?;
}
log::info!("\n💡 Project initialized:");
log::info!("🎯> cd {}", self.path);
log::info!("🎯> dioxus serve");
Ok(())
}
}
}
+1 -2
View File
@@ -3,9 +3,9 @@ use structopt::StructOpt;
pub mod build;
pub mod cfg;
pub mod clean;
pub mod init;
pub mod serve;
pub mod translate;
pub mod init;
/// Build, bundle, & ship your Dioxus app.
///
@@ -36,7 +36,6 @@ pub enum Commands {
Serve(serve::Serve),
/// Init a new project for Dioxus.
Init(init::Init),
// /// Clean output artifacts.
// Clean(clean::Clean),
+7 -4
View File
@@ -1,5 +1,5 @@
use crate::{cfg::ConfigOptsServe, server};
use std::io::Write;
use std::{io::Write, path::PathBuf};
use structopt::StructOpt;
/// Run the WASM project on dev-server
@@ -16,15 +16,18 @@ impl Serve {
// change the relase state.
crate_config.with_release(self.serve.release);
crate::builder::build(&crate_config).expect("build failed");
let dist_path = self.serve.dist.clone().unwrap_or(PathBuf::from("dist"));
crate::builder::build(&crate_config, dist_path.clone()).expect("build failed");
let serve_html = String::from(include_str!("../../server/serve.html"));
let mut file = std::fs::File::create(crate_config.out_dir.join("index.html"))?;
let mut file =
std::fs::File::create(crate_config.crate_dir.join(dist_path).join("index.html"))?;
file.write_all(serve_html.as_bytes())?;
// start the develop server
server::startup(crate_config.clone()).await?;
server::startup(crate_config.clone(), &self.serve).await?;
Ok(())
}