From a4ae4598fbf4aa41562efe2c0afbf37049da7ba8 Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Sat, 5 Feb 2022 09:11:44 +0800 Subject: [PATCH 01/13] docs: update reamde --- README.md | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 75e05b3cf..7bc1fa131 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,46 @@

๐Ÿ“ฆโœจ dioxus-cli

-

- Tooling to supercharge dioxus projects -

+

Tooling to supercharge dioxus projects

-![Dioxus Logo](https://dioxuslabs.com/guide/images/dioxuslogo_full.png) - - -# About - dioxus-cli (inspired by wasm-pack and webpack) is a tool to help get dioxus projects off the ground. It handles all the build, development, bundling, and publishing to make web development simple. - ## Installation ``` $ cargo install dioxus-cli ``` -Now, `dioxus` is in your path. \ No newline at end of file +Now, `dioxus` is in your path, you can use `dioxus --help` to get the help document. + +``` +dioxus 0.1.2 +Build, bundle, & ship your Dioxus app + +USAGE: + dioxus.exe [FLAGS] + +FLAGS: + -h, --help Prints help information + -v Enable verbose logging + -V, --version Prints version information + +SUBCOMMANDS: + build Build the Rust WASM app and all of its assets + clean Clean output artifacts + config Dioxus config file controls + create Init a new project for Dioxus + help Prints this message or the help of the given subcommand(s) + serve Build, watch & serve the Rust WASM app and all of its assets + translate Translate some source file into Dioxus code +``` + +## Get Started + +You can use the `dioxus crate project_name` to init a dioxus project, its will be clone from the [dioxus-template](https://github.com/DioxusLabs/dioxus-template). + +or you can assign the template path: + +``` +dioxus create hello --template gh:dioxuslabs/dioxus-template +``` \ No newline at end of file From eb7388794a09eae788ad70aaabfb483e37cc19b3 Mon Sep 17 00:00:00 2001 From: Aster Date: Mon, 7 Feb 2022 05:28:18 +0800 Subject: [PATCH 02/13] Replace struct-opt with clap --- .gitignore | 1 + Cargo.toml | 26 +++++++++++++------------- README.md | 7 ++++++- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 96ef6c0b9..2e049011e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target Cargo.lock +.idea/ \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 5bbfd7ac2..0f2ad96c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dioxus-cli" -version = "0.1.2" +version = "0.1.3" authors = ["Jonathan Kelley"] edition = "2018" description = "CLI tool for developing, testing, and publishing Dioxus apps" @@ -9,31 +9,31 @@ license = "MIT/Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -thiserror = "1.0.23" -log = "0.4.13" +thiserror = "1.0.30" +log = "0.4.14" fern = { version = "0.6.0", features = ["colored"] } wasm-bindgen-cli-support = "0.2.79" -anyhow = "1.0.38" -serde = { version = "1.0.133", features = ["derive"] } -serde_json = "1" +anyhow = "1.0.53" +serde = { version = "1.0.136", features = ["derive"] } +serde_json = "1.0.79" toml = "0.5.8" fs_extra = "1.2.0" -cargo_toml = "0.10.0" -futures = "0.3.12" +cargo_toml = "0.11.4" +futures = "0.3.21" notify = { version = "5.0.0-pre.13", features = ["serde"] } html_parser = "0.6.2" binary-install = "0.0.2" convert_case = "0.5.0" -structopt = "0.3.25" cargo_metadata = "0.14.1" -tokio = { version = "1.15.0", features = ["full"] } +tokio = { version = "1.16.1", features = ["full"] } atty = "0.2.14" regex = "1.5.4" chrono = "0.4.19" +clap = "3.0.14" -axum = { version = "0.4.4", features = ["ws", "headers"] } -tower-http = { version = "0.2.0", features = ["fs", "trace"] } -headers = "0.3" +axum = { version = "0.4.5", features = ["ws", "headers"] } +tower-http = { version = "0.2.2", features = ["fs", "trace"] } +headers = "0.3.7" # hyper = { version = "0.14.11", features = ["full"] } [[bin]] diff --git a/README.md b/README.md index 75e05b3cf..ab4cf1225 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,13 @@ dioxus-cli (inspired by wasm-pack and webpack) is a tool to help get dioxus proj ## Installation -``` +```shell +# for stable $ cargo install dioxus-cli +# for latest +$ cargo install --git https://github.com/DioxusLabs/cli +# for developing +$ cargo install --path . --debug ``` Now, `dioxus` is in your path. \ No newline at end of file From b6c6dd6532335c5acd2c2eea54300f6f6b341a64 Mon Sep 17 00:00:00 2001 From: Aster Date: Tue, 8 Feb 2022 00:51:21 +0800 Subject: [PATCH 03/13] Clean struct-opt derive --- Cargo.toml | 7 ++++--- src/cli/build/mod.rs | 8 +++----- src/cli/cfg.rs | 9 +++------ src/cli/clean/mod.rs | 10 ++-------- src/cli/config/mod.rs | 7 ++----- src/cli/create/mod.rs | 13 +------------ src/cli/mod.rs | 33 ++++++++++++++++++++++++++------- src/cli/serve/mod.rs | 6 ++---- src/cli/translate/mod.rs | 13 ++----------- tests/main.rs | 4 ++++ 10 files changed, 49 insertions(+), 61 deletions(-) create mode 100644 tests/main.rs diff --git a/Cargo.toml b/Cargo.toml index 0f2ad96c4..89943ec62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,11 +9,13 @@ license = "MIT/Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +# cli core +clap = {version = "3.0.14", features = ["derive"]} thiserror = "1.0.30" +wasm-bindgen-cli-support = "0.2.79" +# features log = "0.4.14" fern = { version = "0.6.0", features = ["colored"] } -wasm-bindgen-cli-support = "0.2.79" -anyhow = "1.0.53" serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" toml = "0.5.8" @@ -29,7 +31,6 @@ tokio = { version = "1.16.1", features = ["full"] } atty = "0.2.14" regex = "1.5.4" chrono = "0.4.19" -clap = "3.0.14" axum = { version = "0.4.5", features = ["ws", "headers"] } tower-http = { version = "0.2.2", features = ["fs", "trace"] } diff --git a/src/cli/build/mod.rs b/src/cli/build/mod.rs index 684cec58c..b4d7f5fe4 100644 --- a/src/cli/build/mod.rs +++ b/src/cli/build/mod.rs @@ -1,10 +1,8 @@ -use std::{io::Write, path::PathBuf}; +use super::*; -use crate::{cfg::ConfigOptsBuild, gen_page}; -use structopt::StructOpt; /// Build the Rust WASM app and all of its assets. -#[derive(Clone, Debug, StructOpt)] +#[derive(Clone, Debug, Parser)] #[structopt(name = "build")] pub struct Build { #[structopt(flatten)] @@ -15,7 +13,7 @@ impl Build { pub fn build(self) -> anyhow::Result<()> { let mut crate_config = crate::CrateConfig::new()?; - // change the relase state. + // change the release state. crate_config.with_release(self.build.release); if self.build.example.is_some() { diff --git a/src/cli/cfg.rs b/src/cli/cfg.rs index ece00e07e..fdd627e85 100644 --- a/src/cli/cfg.rs +++ b/src/cli/cfg.rs @@ -1,10 +1,7 @@ -use std::path::PathBuf; -use structopt::StructOpt; - -use serde::Deserialize; +use super::*; /// Config options for the build system. -#[derive(Clone, Debug, Default, Deserialize, StructOpt)] +#[derive(Clone, Debug, Default, Deserialize, Parser)] pub struct ConfigOptsBuild { /// The index HTML file to drive the bundling process [default: index.html] #[structopt(parse(from_os_str))] @@ -24,7 +21,7 @@ pub struct ConfigOptsBuild { pub platform: String, } -#[derive(Clone, Debug, Default, Deserialize, StructOpt)] +#[derive(Clone, Debug, Default, Deserialize, Parser)] pub struct ConfigOptsServe { /// The index HTML file to drive the bundling process [default: index.html] #[structopt(parse(from_os_str))] diff --git a/src/cli/clean/mod.rs b/src/cli/clean/mod.rs index 62593b1ee..334f93572 100644 --- a/src/cli/clean/mod.rs +++ b/src/cli/clean/mod.rs @@ -1,13 +1,7 @@ -use std::{ - fs::remove_dir_all, - path::PathBuf, - process::{Command, Stdio}, -}; - -use structopt::StructOpt; +use super::*; /// Build the Rust WASM app and all of its assets. -#[derive(Clone, Debug, StructOpt)] +#[derive(Clone, Debug, Parser)] #[structopt(name = "clean")] pub struct Clean {} diff --git a/src/cli/config/mod.rs b/src/cli/config/mod.rs index d5291a7d6..e5d7bdbe4 100644 --- a/src/cli/config/mod.rs +++ b/src/cli/config/mod.rs @@ -1,10 +1,7 @@ -use std::{fs::File, io::Write}; - -use serde::Deserialize; -use structopt::StructOpt; +use super::*; /// Build the Rust WASM app and all of its assets. -#[derive(Clone, Debug, Deserialize, StructOpt)] +#[derive(Clone, Debug, Deserialize, Parser)] #[structopt(name = "config")] pub enum Config { /// Init `Dioxus.toml` for project/folder. diff --git a/src/cli/create/mod.rs b/src/cli/create/mod.rs index fa553c55a..b92a193b7 100644 --- a/src/cli/create/mod.rs +++ b/src/cli/create/mod.rs @@ -1,15 +1,4 @@ -use std::{ - fs::File, - io::{Read, Write}, - path::PathBuf, - process::{Command, Stdio}, -}; - -use regex::Regex; -use serde::Deserialize; -use structopt::StructOpt; - -use crate::{error::Result, Error}; +use super::*; /// Build the Rust WASM app and all of its assets. #[derive(Clone, Debug, Default, Deserialize, StructOpt)] diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 4a72e00ac..e3bd18b3b 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,5 +1,3 @@ -use structopt::StructOpt; - pub mod build; pub mod cfg; pub mod clean; @@ -8,17 +6,38 @@ pub mod create; pub mod serve; pub mod translate; +use std::{io::Write, path::PathBuf}; +use crate::{cfg::ConfigOptsBuild, gen_page}; +use clap::{Parser}; +use serde::Deserialize; +use std::{ + fs::remove_dir_all, + process::{Command, Stdio}, +}; +use std::{fs::File}; +use std::{ + io::{Read}, +}; +use regex::Regex; +use crate::{error::Result, Error}; +use crate::{cfg::ConfigOptsServe, server, CrateConfig}; +use html_parser::Dom; +use html_parser::Element; +use html_parser::Node; +use std::fmt::{Display, Formatter}; +use std::process::exit; + /// Build, bundle, & ship your Dioxus app. /// /// -#[derive(StructOpt)] -#[structopt(name = "dioxus")] +#[derive(Parser, Debug)] +#[clap(name = "dioxus")] pub struct Cli { - #[structopt(subcommand)] + #[clap(subcommand)] pub action: Commands, /// Enable verbose logging. - #[structopt(short)] + #[clap(short)] pub v: bool, // // // note: dioxus is still roughly compatible with trunk @@ -27,7 +46,7 @@ pub struct Cli { // pub config: Option, } -#[derive(StructOpt)] +#[derive(Parser)] pub enum Commands { /// Build the Rust WASM app and all of its assets. Build(build::Build), diff --git a/src/cli/serve/mod.rs b/src/cli/serve/mod.rs index 8f26e0f30..d7184f5f9 100644 --- a/src/cli/serve/mod.rs +++ b/src/cli/serve/mod.rs @@ -1,9 +1,7 @@ -use crate::{cfg::ConfigOptsServe, gen_page, server, CrateConfig}; -use std::{io::Write, path::PathBuf, process::{Command, Stdio}}; -use structopt::StructOpt; +use super::*; /// Run the WASM project on dev-server -#[derive(Clone, Debug, StructOpt)] +#[derive(Clone, Debug, Parser)] #[structopt(name = "serve")] pub struct Serve { #[structopt(flatten)] diff --git a/src/cli/translate/mod.rs b/src/cli/translate/mod.rs index a717d632a..4e23533aa 100644 --- a/src/cli/translate/mod.rs +++ b/src/cli/translate/mod.rs @@ -1,16 +1,7 @@ -use anyhow::Result; -use html_parser::Dom; -use html_parser::Element; -use html_parser::Node; -#[allow(unused_imports)] -use std::fmt::{Display, Formatter}; -use std::io::Read; -use std::path::PathBuf; -use std::process::exit; -use structopt::StructOpt; +use super::*; /// Build the Rust WASM app and all of its assets. -#[derive(Clone, Debug, StructOpt)] +#[derive(Clone, Debug, Parser)] #[structopt(name = "translate")] pub struct Translate { /// Activate debug mode diff --git a/tests/main.rs b/tests/main.rs new file mode 100644 index 000000000..f9bb6a890 --- /dev/null +++ b/tests/main.rs @@ -0,0 +1,4 @@ +#[test] +fn ready() { + println!("Compiled successfully!") +} \ No newline at end of file From ce628e1197095c778432fcb51df6d5f176a4f868 Mon Sep 17 00:00:00 2001 From: Aster Date: Wed, 9 Feb 2022 16:11:02 +0800 Subject: [PATCH 04/13] Fix compiler errors --- Cargo.toml | 2 ++ src/cli/build/mod.rs | 9 ++++----- src/cli/cfg.rs | 16 ++++++++-------- src/cli/clean/mod.rs | 4 ++-- src/cli/config/mod.rs | 9 +++++---- src/cli/create/mod.rs | 20 ++++++++------------ src/cli/mod.rs | 33 +++++++++++++++++---------------- src/cli/serve/mod.rs | 10 +++++----- src/cli/translate/mod.rs | 10 +++++----- src/error.rs | 37 +++++++++++++++++++++++++++++++++++++ src/main.rs | 4 ++-- src/server/mod.rs | 3 ++- tests/main.rs | 8 ++++---- 13 files changed, 101 insertions(+), 64 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 89943ec62..3ae7b4610 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,8 @@ tokio = { version = "1.16.1", features = ["full"] } atty = "0.2.14" regex = "1.5.4" chrono = "0.4.19" +anyhow = "1.0.53" +hyper = "0.14.17" axum = { version = "0.4.5", features = ["ws", "headers"] } tower-http = { version = "0.2.2", features = ["fs", "trace"] } diff --git a/src/cli/build/mod.rs b/src/cli/build/mod.rs index b4d7f5fe4..1c665abd3 100644 --- a/src/cli/build/mod.rs +++ b/src/cli/build/mod.rs @@ -1,16 +1,15 @@ use super::*; - /// Build the Rust WASM app and all of its assets. #[derive(Clone, Debug, Parser)] -#[structopt(name = "build")] +#[clap(name = "build")] pub struct Build { - #[structopt(flatten)] + #[clap(flatten)] pub build: ConfigOptsBuild, } impl Build { - pub fn build(self) -> anyhow::Result<()> { + pub fn build(self) -> Result<()> { let mut crate_config = crate::CrateConfig::new()?; // change the release state. @@ -28,7 +27,7 @@ impl Build { crate::builder::build_desktop(&crate_config)?; } _ => { - return Err(anyhow::anyhow!("Unsoppurt platform target.")); + return custom_error!("Unsoppurt platform target."); } } diff --git a/src/cli/cfg.rs b/src/cli/cfg.rs index fdd627e85..f1e3d0845 100644 --- a/src/cli/cfg.rs +++ b/src/cli/cfg.rs @@ -4,40 +4,40 @@ use super::*; #[derive(Clone, Debug, Default, Deserialize, Parser)] pub struct ConfigOptsBuild { /// The index HTML file to drive the bundling process [default: index.html] - #[structopt(parse(from_os_str))] + #[clap(parse(from_os_str))] pub target: Option, /// Build in release mode [default: false] - #[structopt(long)] + #[clap(long)] #[serde(default)] pub release: bool, /// Build a example [default: ""] - #[structopt(long)] + #[clap(long)] pub example: Option, /// Build platform: support Web & Desktop [default: "web"] - #[structopt(long, default_value = "web")] + #[clap(long, default_value = "web")] pub platform: String, } #[derive(Clone, Debug, Default, Deserialize, Parser)] pub struct ConfigOptsServe { /// The index HTML file to drive the bundling process [default: index.html] - #[structopt(parse(from_os_str))] + #[clap(parse(from_os_str))] pub target: Option, /// Build a example [default: ""] - #[structopt(long)] + #[clap(long)] pub example: Option, /// Build in release mode [default: false] - #[structopt(long)] + #[clap(long)] #[serde(default)] pub release: bool, /// Build platform: support Web & Desktop [default: "web"] - #[structopt(long, default_value = "web")] + #[clap(long, default_value = "web")] pub platform: String, } diff --git a/src/cli/clean/mod.rs b/src/cli/clean/mod.rs index 334f93572..74a99fec2 100644 --- a/src/cli/clean/mod.rs +++ b/src/cli/clean/mod.rs @@ -2,11 +2,11 @@ use super::*; /// Build the Rust WASM app and all of its assets. #[derive(Clone, Debug, Parser)] -#[structopt(name = "clean")] +#[clap(name = "clean")] pub struct Clean {} impl Clean { - pub fn clean(self) -> anyhow::Result<()> { + pub fn clean(self) -> Result<()> { let crate_config = crate::CrateConfig::new()?; let output = Command::new("cargo") diff --git a/src/cli/config/mod.rs b/src/cli/config/mod.rs index e5d7bdbe4..3cbf368e0 100644 --- a/src/cli/config/mod.rs +++ b/src/cli/config/mod.rs @@ -1,8 +1,9 @@ use super::*; + /// Build the Rust WASM app and all of its assets. -#[derive(Clone, Debug, Deserialize, Parser)] -#[structopt(name = "config")] +#[derive(Clone, Debug, Deserialize, Subcommand)] +#[clap(name = "config")] pub enum Config { /// Init `Dioxus.toml` for project/folder. Init { @@ -10,14 +11,14 @@ pub enum Config { name: String, /// Cover old config - #[structopt(long)] + #[clap(long)] #[serde(default)] force: bool, }, } impl Config { - pub fn config(self) -> anyhow::Result<()> { + pub fn config(self) -> Result<()> { let crate_root = crate::cargo::crate_root()?; match self { Config::Init { name, force } => { diff --git a/src/cli/create/mod.rs b/src/cli/create/mod.rs index b92a193b7..f00bc5dd9 100644 --- a/src/cli/create/mod.rs +++ b/src/cli/create/mod.rs @@ -1,15 +1,16 @@ use super::*; +use crate::custom_error; /// Build the Rust WASM app and all of its assets. -#[derive(Clone, Debug, Default, Deserialize, StructOpt)] -#[structopt(name = "create")] +#[derive(Clone, Debug, Default, Deserialize, Parser)] +#[clap(name = "create")] pub struct Create { /// Init project name - #[structopt(default_value = ".")] + #[clap(default_value = ".")] name: String, /// Template path - #[structopt(default_value = "gh:dioxuslabs/dioxus-template", long)] + #[clap(default_value = "gh:dioxuslabs/dioxus-template", long)] template: String, } @@ -23,10 +24,7 @@ impl Create { let project_path = PathBuf::from(&self.name); if project_path.join("Dioxus.toml").is_file() || project_path.join("Cargo.toml").is_file() { - return Err(Error::Other(anyhow::anyhow!( - "๐Ÿงจ Folder '{}' is initialized.", - &self.name - ))); + return custom_error!("๐Ÿงจ Folder '{}' is initialized.", &self.name); } log::info!("๐Ÿ”ง Start to create a new project '{}'.", self.name); @@ -47,9 +45,7 @@ impl Create { .stderr(Stdio::inherit()) .output()?; if !install_output.status.success() { - return Err(Error::Other(anyhow::anyhow!( - "Try to install cargo-generate failed." - ))); + return custom_error!("Try to install cargo-generate failed."); } } @@ -63,7 +59,7 @@ impl Create { .output()?; if !generate_output.status.success() { - return Err(Error::Other(anyhow::anyhow!("Generate project failed."))); + return custom_error!("Generate project failed."); } let mut dioxus_file = File::open(project_path.join("Dioxus.toml"))?; diff --git a/src/cli/mod.rs b/src/cli/mod.rs index e3bd18b3b..8ec374933 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -6,31 +6,31 @@ pub mod create; pub mod serve; pub mod translate; -use std::{io::Write, path::PathBuf}; +use crate::custom_error; use crate::{cfg::ConfigOptsBuild, gen_page}; -use clap::{Parser}; +use crate::{cfg::ConfigOptsServe, server, CrateConfig}; +use crate::{error::Result, Error}; +use clap::Parser; +use html_parser::Dom; +use html_parser::Element; +use html_parser::Node; +use regex::Regex; use serde::Deserialize; +use std::fmt::{Display, Formatter}; +use std::fs::File; +use std::io::Read; +use std::process::exit; use std::{ fs::remove_dir_all, process::{Command, Stdio}, }; -use std::{fs::File}; -use std::{ - io::{Read}, -}; -use regex::Regex; -use crate::{error::Result, Error}; -use crate::{cfg::ConfigOptsServe, server, CrateConfig}; -use html_parser::Dom; -use html_parser::Element; -use html_parser::Node; -use std::fmt::{Display, Formatter}; -use std::process::exit; +use std::{io::Write, path::PathBuf}; +use clap::{Subcommand}; /// Build, bundle, & ship your Dioxus app. /// /// -#[derive(Parser, Debug)] +#[derive(Parser)] #[clap(name = "dioxus")] pub struct Cli { #[clap(subcommand)] @@ -42,7 +42,7 @@ pub struct Cli { // // // note: dioxus is still roughly compatible with trunk // /// Path to the Trunk config file [default: Trunk.toml] - // #[structopt(long, parse(from_os_str), env = "TRUNK_CONFIG")] + // #[clap(long, parse(from_os_str), env = "TRUNK_CONFIG")] // pub config: Option, } @@ -59,5 +59,6 @@ pub enum Commands { /// Clean output artifacts. Clean(clean::Clean), /// Dioxus config file controls. + #[clap(subcommand)] Config(config::Config), } diff --git a/src/cli/serve/mod.rs b/src/cli/serve/mod.rs index d7184f5f9..d627ace47 100644 --- a/src/cli/serve/mod.rs +++ b/src/cli/serve/mod.rs @@ -2,14 +2,14 @@ use super::*; /// Run the WASM project on dev-server #[derive(Clone, Debug, Parser)] -#[structopt(name = "serve")] +#[clap(name = "serve")] pub struct Serve { - #[structopt(flatten)] + #[clap(flatten)] pub serve: ConfigOptsServe, } impl Serve { - pub async fn serve(self) -> anyhow::Result<()> { + pub async fn serve(self) -> Result<()> { let mut crate_config = crate::CrateConfig::new()?; // change the relase state. @@ -49,7 +49,7 @@ impl Serve { return Ok(()); } _ => { - return Err(anyhow::anyhow!("Unsoppurt platform target.")); + return custom_error!("Unsoppurt platform target."); } } @@ -62,7 +62,7 @@ impl Serve { Ok(()) } - pub fn regen_dev_page(crate_config: &CrateConfig) -> anyhow::Result<()> { + pub fn regen_dev_page(crate_config: &CrateConfig) -> Result<()> { let serve_html = gen_page(&crate_config.dioxus_config, true); let mut file = std::fs::File::create( diff --git a/src/cli/translate/mod.rs b/src/cli/translate/mod.rs index 4e23533aa..55ba101cd 100644 --- a/src/cli/translate/mod.rs +++ b/src/cli/translate/mod.rs @@ -2,24 +2,24 @@ use super::*; /// Build the Rust WASM app and all of its assets. #[derive(Clone, Debug, Parser)] -#[structopt(name = "translate")] +#[clap(name = "translate")] pub struct Translate { /// Activate debug mode // short and long flags (-d, --debug) will be deduced from the field's name - #[structopt(short, long)] + #[clap(short, long)] pub component: bool, /// Input file - #[structopt(short, long)] + #[clap(short, long)] pub file: Option, /// Output file, stdout if not present - #[structopt(parse(from_os_str))] + #[clap(parse(from_os_str))] pub output: Option, } impl Translate { - pub fn translate(self) -> anyhow::Result<()> { + pub fn translate(self) -> Result<()> { let Translate { component, output, diff --git a/src/error.rs b/src/error.rs index 8684abf74..d40868333 100644 --- a/src/error.rs +++ b/src/error.rs @@ -11,6 +11,15 @@ pub enum Error { #[error("I/O Error: {0}")] IO(#[from] std::io::Error), + #[error("Format Error: {0}")] + FormatError(#[from] std::fmt::Error), + + #[error("Format failed: {0}")] + ParseError(String), + + #[error("Runtime Error: {0}")] + RuntimeError(String), + #[error("Failed to write error")] FailedToWrite, @@ -20,6 +29,9 @@ pub enum Error { #[error("Failed to write error")] CargoError(String), + #[error("{0}")] + CustomError(String), + #[error(transparent)] Other(#[from] anyhow::Error), } @@ -35,3 +47,28 @@ impl From for Error { Error::Unique(s) } } + +impl From for Error { + fn from(e: html_parser::Error) -> Self { + Self::ParseError(e.to_string()) + } +} + +impl From for Error { + fn from(e: hyper::Error) -> Self { + Self::RuntimeError(e.to_string()) + } +} + +#[macro_export] +macro_rules! custom_error { + ($msg:literal $(,)?) => { + Err(Error::CustomError($msg.to_string())) + }; + ($err:expr $(,)?) => { + Err(Error::from($err)) + }; + ($fmt:expr, $($arg:tt)*) => { + Err(Error::CustomError(format!($fmt, $($arg)*))) + }; +} diff --git a/src/main.rs b/src/main.rs index 6b8c177db..97d4a3bb4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,9 @@ +use clap::Parser; use dioxus_cli::*; -use structopt::StructOpt; #[tokio::main] async fn main() -> Result<()> { - let args = Cli::from_args(); + let args = Cli::parse(); set_up_logging(); match args.action { diff --git a/src/server/mod.rs b/src/server/mod.rs index 880f25ceb..f312e07c2 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -10,6 +10,7 @@ use notify::{RecommendedWatcher, Watcher}; use std::{path::PathBuf, sync::Arc}; use tower_http::services::ServeDir; +use crate::Result; use crate::{builder, serve::Serve, CrateConfig}; use tokio::sync::broadcast; @@ -17,7 +18,7 @@ struct WsRelodState { update: broadcast::Sender, } -pub async fn startup(config: CrateConfig) -> anyhow::Result<()> { +pub async fn startup(config: CrateConfig) -> Result<()> { log::info!("๐Ÿš€ Starting development server..."); let dist_path = config.out_dir.clone(); diff --git a/tests/main.rs b/tests/main.rs index f9bb6a890..1849f5dc8 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -1,4 +1,4 @@ -#[test] -fn ready() { - println!("Compiled successfully!") -} \ No newline at end of file +#[test] +fn ready() { + println!("Compiled successfully!") +} From 59ebb9ec116449bcd77ab554b34a6bb8e09796b9 Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Wed, 9 Feb 2022 21:11:41 +0800 Subject: [PATCH 05/13] feat: add `default_platform` config --- src/assets/dioxus.toml | 15 ++++++++------- src/cli/build/mod.rs | 10 +++++++++- src/cli/cfg.rs | 12 ++++++------ src/cli/serve/mod.rs | 16 ++++++++++++++-- src/config.rs | 4 ++-- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/assets/dioxus.toml b/src/assets/dioxus.toml index 717b070e2..31e306079 100644 --- a/src/assets/dioxus.toml +++ b/src/assets/dioxus.toml @@ -1,23 +1,24 @@ [application] -# App (Project) Name +# dioxus project name name = "{{project-name}}" -# Dioxus App Support Platform -# desktop, web, mobile, ssr -platforms = ["web"] +# default platfrom +# you can also use `dioxus serve/build --platform XXX` to use other platform +# value: web | desktop +default_platform = "web" # Web `build` & `serve` dist path out_dir = "dist" +# resource (static) file folder +public_dir = "public" + [web.app] # HTML title tag content title = "dioxus | โ›บ" -# resource (static) file folder -public_dir = "public" - [web.watcher] watch_path = ["src"] diff --git a/src/cli/build/mod.rs b/src/cli/build/mod.rs index 684cec58c..bae291b7e 100644 --- a/src/cli/build/mod.rs +++ b/src/cli/build/mod.rs @@ -22,7 +22,15 @@ impl Build { crate_config.as_example(self.build.example.unwrap()); } - match self.build.platform.as_str() { + let platform = self.build.platform.unwrap_or_else(|| { + crate_config + .dioxus_config + .application + .default_platform + .clone() + }); + + match platform.as_str() { "web" => { crate::builder::build(&crate_config)?; } diff --git a/src/cli/cfg.rs b/src/cli/cfg.rs index ece00e07e..2271f0453 100644 --- a/src/cli/cfg.rs +++ b/src/cli/cfg.rs @@ -19,9 +19,9 @@ pub struct ConfigOptsBuild { #[structopt(long)] pub example: Option, - /// Build platform: support Web & Desktop [default: "web"] - #[structopt(long, default_value = "web")] - pub platform: String, + /// Build platform: support Web & Desktop [default: "default_platform"] + #[structopt(long)] + pub platform: Option, } #[derive(Clone, Debug, Default, Deserialize, StructOpt)] @@ -39,9 +39,9 @@ pub struct ConfigOptsServe { #[serde(default)] pub release: bool, - /// Build platform: support Web & Desktop [default: "web"] - #[structopt(long, default_value = "web")] - pub platform: String, + /// Build platform: support Web & Desktop [default: "default_platform"] + #[structopt(long)] + pub platform: Option, } /// Ensure the given value for `--public-url` is formatted correctly. diff --git a/src/cli/serve/mod.rs b/src/cli/serve/mod.rs index 8f26e0f30..ff263b6b5 100644 --- a/src/cli/serve/mod.rs +++ b/src/cli/serve/mod.rs @@ -1,5 +1,9 @@ use crate::{cfg::ConfigOptsServe, gen_page, server, CrateConfig}; -use std::{io::Write, path::PathBuf, process::{Command, Stdio}}; +use std::{ + io::Write, + path::PathBuf, + process::{Command, Stdio}, +}; use structopt::StructOpt; /// Run the WASM project on dev-server @@ -21,7 +25,15 @@ impl Serve { crate_config.as_example(self.serve.example.unwrap()); } - match self.serve.platform.as_str() { + let platform = self.serve.platform.unwrap_or_else(|| { + crate_config + .dioxus_config + .application + .default_platform + .clone() + }); + + match platform.as_str() { "web" => { crate::builder::build(&crate_config)?; } diff --git a/src/config.rs b/src/config.rs index 1151445ef..a7f5d1fec 100644 --- a/src/config.rs +++ b/src/config.rs @@ -31,7 +31,7 @@ impl Default for DioxusConfig { Self { application: ApplicationConfig { name: "dioxus".into(), - platforms: vec![String::from("web")], + default_platform: "web".to_string(), out_dir: Some(PathBuf::from("dist")), }, web: WebConfig { @@ -59,7 +59,7 @@ impl Default for DioxusConfig { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ApplicationConfig { pub name: String, - pub platforms: Vec, + pub default_platform: String, pub out_dir: Option, } From a0356c7f36cc8862ec3f49f92d07330070e3fa3e Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Wed, 9 Feb 2022 21:25:29 +0800 Subject: [PATCH 06/13] fix: clean `out_dir` --- src/builder.rs | 6 ++++-- src/cli/build/mod.rs | 2 +- src/cli/serve/mod.rs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 257072a6a..24168a934 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -120,7 +120,7 @@ pub fn build(config: &CrateConfig) -> Result<()> { Ok(()) } -pub fn build_desktop(config: &CrateConfig) -> Result<()> { +pub fn build_desktop(config: &CrateConfig, is_serve: bool) -> Result<()> { log::info!("๐Ÿš… Running build [Desktop] command..."); let mut cmd = Command::new("cargo"); @@ -146,7 +146,9 @@ pub fn build_desktop(config: &CrateConfig) -> Result<()> { } if output.status.success() { - if config.out_dir.is_dir() { + // this code will clean the output dir. + // if using the serve, we will not clean the out_dir. + if config.out_dir.is_dir() && !is_serve { remove_dir_all(&config.out_dir)?; } diff --git a/src/cli/build/mod.rs b/src/cli/build/mod.rs index bae291b7e..a29ba654b 100644 --- a/src/cli/build/mod.rs +++ b/src/cli/build/mod.rs @@ -35,7 +35,7 @@ impl Build { crate::builder::build(&crate_config)?; } "desktop" => { - crate::builder::build_desktop(&crate_config)?; + crate::builder::build_desktop(&crate_config, false)?; } _ => { return Err(anyhow::anyhow!("Unsoppurt platform target.")); diff --git a/src/cli/serve/mod.rs b/src/cli/serve/mod.rs index ff263b6b5..fe70f7914 100644 --- a/src/cli/serve/mod.rs +++ b/src/cli/serve/mod.rs @@ -38,7 +38,7 @@ impl Serve { crate::builder::build(&crate_config)?; } "desktop" => { - crate::builder::build_desktop(&crate_config)?; + crate::builder::build_desktop(&crate_config, true)?; match &crate_config.executable { crate::ExecutableType::Binary(name) From 653ee254c036653674a984cb716d0239c4c38f27 Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Wed, 9 Feb 2022 21:30:00 +0800 Subject: [PATCH 07/13] docs: update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7bc1fa131..31e957111 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ dioxus-cli (inspired by wasm-pack and webpack) is a tool to help get dioxus proj ## Installation ``` -$ cargo install dioxus-cli +$ cargo install --git https://github.com/DioxusLabs/cli ``` Now, `dioxus` is in your path, you can use `dioxus --help` to get the help document. From 9d8b95dfc43023da050943300df86ba2612c72a6 Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Wed, 9 Feb 2022 21:59:26 +0800 Subject: [PATCH 08/13] feat: add `public_dir` for other platform --- src/builder.rs | 31 ++++++++++++++++++++++++++++++- src/config.rs | 6 +++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 24168a934..1458d52ba 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -91,6 +91,7 @@ pub fn build(config: &CrateConfig) -> Result<()> { .out_name(&dioxus_config.application.name) .generate(&bindgen_outdir)?; + // this code will copy all public file to the output dir let copy_options = fs_extra::dir::CopyOptions { overwrite: true, skip_exist: false, @@ -183,9 +184,37 @@ pub fn build_desktop(config: &CrateConfig, is_serve: bool) -> Result<()> { file_name }; - create_dir_all(&config.out_dir)?; + if !config.out_dir.is_dir() { + create_dir_all(&config.out_dir)?; + } copy(res_path, &config.out_dir.join(target_file))?; + // this code will copy all public file to the output dir + if config.public_dir.is_dir() { + let copy_options = fs_extra::dir::CopyOptions { + overwrite: true, + skip_exist: false, + buffer_size: 64000, + copy_inside: false, + content_only: false, + depth: 0, + }; + + for entry in std::fs::read_dir(&config.public_dir)? { + let path = entry?.path(); + if path.is_file() { + std::fs::copy(&path, &config.out_dir.join(path.file_name().unwrap()))?; + } else { + match fs_extra::dir::copy(&path, &config.out_dir, ©_options) { + Ok(_) => {} + Err(e) => { + log::warn!("Error copying dir: {}", e); + } + } + } + } + } + log::info!( "๐Ÿšฉ Build completed: [./{}]", config diff --git a/src/config.rs b/src/config.rs index a7f5d1fec..5949310dd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -33,11 +33,11 @@ impl Default for DioxusConfig { name: "dioxus".into(), default_platform: "web".to_string(), out_dir: Some(PathBuf::from("dist")), + public_dir: Some(PathBuf::from("public")), }, web: WebConfig { app: WebAppConfing { title: Some("dioxus | โ›บ".into()), - public_dir: Some(PathBuf::from("public")), }, watcher: WebWatcherConfing { watch_path: Some(vec![PathBuf::from("src")]), @@ -61,6 +61,7 @@ pub struct ApplicationConfig { pub name: String, pub default_platform: String, pub out_dir: Option, + pub public_dir: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -73,7 +74,6 @@ pub struct WebConfig { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct WebAppConfing { pub title: Option, - pub public_dir: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -130,7 +130,7 @@ impl CrateConfig { let cargo_def = &crate_dir.join("Cargo.toml"); - let public_dir = match dioxus_config.web.app.public_dir { + let public_dir = match dioxus_config.application.public_dir { Some(ref v) => crate_dir.join(v), None => crate_dir.join("public"), }; From 62712219406ef95d83060bf637c0fa831bcc30d8 Mon Sep 17 00:00:00 2001 From: Aster Date: Thu, 10 Feb 2022 04:02:09 +0800 Subject: [PATCH 09/13] Fix format and clippy --- rustfmt.toml | 8 ++++++++ src/builder.rs | 12 +++++------- src/cli/config/mod.rs | 1 - src/cli/mod.rs | 32 +++++++++++++------------------- src/server/mod.rs | 3 +-- 5 files changed, 27 insertions(+), 29 deletions(-) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 000000000..9071fb4b5 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,8 @@ +version = "Two" +edition = "2018" + +imports_granularity = "Crate" +#use_small_heuristics = "Max" +#control_brace_style = "ClosingNextLine" +normalize_comments = true +format_code_in_doc_comments = true \ No newline at end of file diff --git a/src/builder.rs b/src/builder.rs index 257072a6a..f3090f85d 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -11,13 +11,11 @@ use std::{ use wasm_bindgen_cli_support::Bindgen; pub fn build(config: &CrateConfig) -> Result<()> { - /* - [1] Build the project with cargo, generating a wasm32-unknown-unknown target (is there a more specific, better target to leverage?) - [2] Generate the appropriate build folders - [3] Wasm-bindgen the .wasm fiile, and move it into the {builddir}/modules/xxxx/xxxx_bg.wasm - [4] Wasm-opt the .wasm file with whatever optimizations need to be done - [5] Link up the html page to the wasm module - */ + // [1] Build the project with cargo, generating a wasm32-unknown-unknown target (is there a more specific, better target to leverage?) + // [2] Generate the appropriate build folders + // [3] Wasm-bindgen the .wasm fiile, and move it into the {builddir}/modules/xxxx/xxxx_bg.wasm + // [4] Wasm-opt the .wasm file with whatever optimizations need to be done + // [5] Link up the html page to the wasm module let CrateConfig { out_dir, diff --git a/src/cli/config/mod.rs b/src/cli/config/mod.rs index 3cbf368e0..6d672b7a5 100644 --- a/src/cli/config/mod.rs +++ b/src/cli/config/mod.rs @@ -1,6 +1,5 @@ use super::*; - /// Build the Rust WASM app and all of its assets. #[derive(Clone, Debug, Deserialize, Subcommand)] #[clap(name = "config")] diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 8ec374933..1b5ba0be7 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -6,30 +6,25 @@ pub mod create; pub mod serve; pub mod translate; -use crate::custom_error; -use crate::{cfg::ConfigOptsBuild, gen_page}; -use crate::{cfg::ConfigOptsServe, server, CrateConfig}; -use crate::{error::Result, Error}; -use clap::Parser; -use html_parser::Dom; -use html_parser::Element; -use html_parser::Node; +use crate::{ + cfg::{ConfigOptsBuild, ConfigOptsServe}, + custom_error, + error::Result, + gen_page, server, CrateConfig, Error, +}; +use clap::{Parser, Subcommand}; +use html_parser::{Dom, Element, Node}; use regex::Regex; use serde::Deserialize; -use std::fmt::{Display, Formatter}; -use std::fs::File; -use std::io::Read; -use std::process::exit; use std::{ - fs::remove_dir_all, - process::{Command, Stdio}, + fmt::{Display, Formatter}, + fs::{remove_dir_all, File}, + io::{Read, Write}, + path::PathBuf, + process::{exit, Command, Stdio}, }; -use std::{io::Write, path::PathBuf}; -use clap::{Subcommand}; /// Build, bundle, & ship your Dioxus app. -/// -/// #[derive(Parser)] #[clap(name = "dioxus")] pub struct Cli { @@ -39,7 +34,6 @@ pub struct Cli { /// Enable verbose logging. #[clap(short)] pub v: bool, - // // // note: dioxus is still roughly compatible with trunk // /// Path to the Trunk config file [default: Trunk.toml] // #[clap(long, parse(from_os_str), env = "TRUNK_CONFIG")] diff --git a/src/server/mod.rs b/src/server/mod.rs index f312e07c2..38e37d60b 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -10,8 +10,7 @@ use notify::{RecommendedWatcher, Watcher}; use std::{path::PathBuf, sync::Arc}; use tower_http::services::ServeDir; -use crate::Result; -use crate::{builder, serve::Serve, CrateConfig}; +use crate::{builder, serve::Serve, CrateConfig, Result}; use tokio::sync::broadcast; struct WsRelodState { From 936fefbbf8da475d4b1a915c1d040161b9daee3c Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Fri, 11 Feb 2022 16:54:35 +0800 Subject: [PATCH 10/13] feat: commit code --- src/builder.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 1458d52ba..c1e9fc0a7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -5,6 +5,7 @@ use crate::{ }; use std::{ fs::{copy, create_dir_all, remove_dir_all}, + panic, path::PathBuf, process::Command, }; @@ -62,9 +63,6 @@ pub fn build(config: &CrateConfig) -> Result<()> { // [2] Establish the output directory structure let bindgen_outdir = out_dir.join("assets").join("dioxus"); - // [3] Bindgen the final binary for use easy linking - let mut bindgen_builder = Bindgen::new(); - let release_type = match config.release { true => "release", false => "debug", @@ -80,16 +78,25 @@ pub fn build(config: &CrateConfig) -> Result<()> { .join(format!("{}.wasm", name)), }; - bindgen_builder - .input_path(input_path) - .web(true)? - .debug(true) - .demangle(true) - .keep_debug(true) - .remove_name_section(false) - .remove_producers_section(false) - .out_name(&dioxus_config.application.name) - .generate(&bindgen_outdir)?; + let bindgen_result = panic::catch_unwind(move || { + // [3] Bindgen the final binary for use easy linking + let mut bindgen_builder = Bindgen::new(); + + bindgen_builder + .input_path(input_path) + .web(true).unwrap() + .debug(true) + .demangle(true) + .keep_debug(true) + .remove_name_section(false) + .remove_producers_section(false) + .out_name(&dioxus_config.application.name) + .generate(&bindgen_outdir).unwrap(); + }); + if bindgen_result.is_err() { + panic!("Bindgen build failed"); + } + // this code will copy all public file to the output dir let copy_options = fs_extra::dir::CopyOptions { From c3ba5c287decc50d82748ee502de3bc863be04e8 Mon Sep 17 00:00:00 2001 From: YuKun Liu <41265098+mrxiaozhuox@users.noreply.github.com> Date: Thu, 17 Feb 2022 19:28:54 +0800 Subject: [PATCH 11/13] feat: change public to `asset_dir` --- src/assets/dioxus.toml | 2 +- src/builder.rs | 10 +++++----- src/config.rs | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/assets/dioxus.toml b/src/assets/dioxus.toml index 31e306079..d3f160242 100644 --- a/src/assets/dioxus.toml +++ b/src/assets/dioxus.toml @@ -12,7 +12,7 @@ default_platform = "web" out_dir = "dist" # resource (static) file folder -public_dir = "public" +asset_dir = "public" [web.app] diff --git a/src/builder.rs b/src/builder.rs index efc5a915a..afd551dd3 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -22,7 +22,7 @@ pub fn build(config: &CrateConfig) -> Result<()> { out_dir, crate_dir, target_dir, - public_dir, + asset_dir, executable, dioxus_config, .. @@ -105,8 +105,8 @@ pub fn build(config: &CrateConfig) -> Result<()> { content_only: false, depth: 0, }; - if public_dir.is_dir() { - for entry in std::fs::read_dir(&public_dir)? { + if asset_dir.is_dir() { + for entry in std::fs::read_dir(&asset_dir)? { let path = entry?.path(); if path.is_file() { std::fs::copy(&path, out_dir.join(path.file_name().unwrap()))?; @@ -195,7 +195,7 @@ pub fn build_desktop(config: &CrateConfig, is_serve: bool) -> Result<()> { copy(res_path, &config.out_dir.join(target_file))?; // this code will copy all public file to the output dir - if config.public_dir.is_dir() { + if config.asset_dir.is_dir() { let copy_options = fs_extra::dir::CopyOptions { overwrite: true, skip_exist: false, @@ -205,7 +205,7 @@ pub fn build_desktop(config: &CrateConfig, is_serve: bool) -> Result<()> { depth: 0, }; - for entry in std::fs::read_dir(&config.public_dir)? { + for entry in std::fs::read_dir(&config.asset_dir)? { let path = entry?.path(); if path.is_file() { std::fs::copy(&path, &config.out_dir.join(path.file_name().unwrap()))?; diff --git a/src/config.rs b/src/config.rs index 5949310dd..ba0427191 100644 --- a/src/config.rs +++ b/src/config.rs @@ -33,7 +33,7 @@ impl Default for DioxusConfig { name: "dioxus".into(), default_platform: "web".to_string(), out_dir: Some(PathBuf::from("dist")), - public_dir: Some(PathBuf::from("public")), + asset_dir: Some(PathBuf::from("public")), }, web: WebConfig { app: WebAppConfing { @@ -61,7 +61,7 @@ pub struct ApplicationConfig { pub name: String, pub default_platform: String, pub out_dir: Option, - pub public_dir: Option, + pub asset_dir: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -101,7 +101,7 @@ pub struct CrateConfig { pub crate_dir: PathBuf, pub workspace_dir: PathBuf, pub target_dir: PathBuf, - pub public_dir: PathBuf, + pub asset_dir: PathBuf, pub manifest: cargo_toml::Manifest, pub executable: ExecutableType, pub dioxus_config: DioxusConfig, @@ -130,7 +130,7 @@ impl CrateConfig { let cargo_def = &crate_dir.join("Cargo.toml"); - let public_dir = match dioxus_config.application.public_dir { + let asset_dir = match dioxus_config.application.asset_dir { Some(ref v) => crate_dir.join(v), None => crate_dir.join("public"), }; @@ -154,7 +154,7 @@ impl CrateConfig { crate_dir, workspace_dir, target_dir, - public_dir, + asset_dir, manifest, executable, release, From e7acc4d88de55792606014c28c9c235bdb860f41 Mon Sep 17 00:00:00 2001 From: YuKun Liu <41265098+mrxiaozhuox@users.noreply.github.com> Date: Thu, 17 Feb 2022 19:32:56 +0800 Subject: [PATCH 12/13] feat: add `log info` --- src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index afd551dd3..708e1ce69 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -92,7 +92,7 @@ pub fn build(config: &CrateConfig) -> Result<()> { .generate(&bindgen_outdir).unwrap(); }); if bindgen_result.is_err() { - panic!("Bindgen build failed"); + log::error!("Bindgen build failed! \nThis is probably due to the Bindgen version, dioxus-cli using `0.2.79` Bindgen crate."); } From 8a0abec82865daf78c5783d897c4d8375c0fbb6c Mon Sep 17 00:00:00 2001 From: YuKun Liu Date: Fri, 18 Feb 2022 09:50:26 +0800 Subject: [PATCH 13/13] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 33d1d4932..a939dfcaf 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ dioxus 0.1.2 Build, bundle, & ship your Dioxus app USAGE: - dioxus.exe [FLAGS] + dioxus [FLAGS] FLAGS: -h, --help Prints help information @@ -42,10 +42,10 @@ SUBCOMMANDS: ## Get Started -You can use the `dioxus crate project_name` to init a dioxus project, its will be clone from the [dioxus-template](https://github.com/DioxusLabs/dioxus-template). +You can use the `dioxus create project_name` to init a dioxus project, its will be clone from the [dioxus-template](https://github.com/DioxusLabs/dioxus-template). or you can assign the template path: ``` dioxus create hello --template gh:dioxuslabs/dioxus-template -``` \ No newline at end of file +```