Przeglądaj źródła

Merge pull request #95 from mgbvox/mgb-dioxus-create

`dioxus create some_project` now actually creates said project
YuKun Liu 2 lat temu
rodzic
commit
90ee614ca3
5 zmienionych plików z 114 dodań i 7 usunięć
  1. 107 1
      Cargo.lock
  2. 2 1
      README.md
  3. 2 2
      src/cli/create/mod.rs
  4. 1 1
      src/config.rs
  5. 2 2
      src/main.rs

+ 107 - 1
Cargo.lock

@@ -76,6 +76,20 @@ version = "0.5.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
 
+[[package]]
+name = "assert_cmd"
+version = "2.0.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9834fcc22e0874394a010230586367d4a3e9f11b560f469262678547e1d2575e"
+dependencies = [
+ "bstr 1.1.0",
+ "doc-comment",
+ "predicates",
+ "predicates-core",
+ "predicates-tree",
+ "wait-timeout",
+]
+
 [[package]]
 name = "async-trait"
 version = "0.1.61"
@@ -250,6 +264,18 @@ dependencies = [
  "memchr",
 ]
 
+[[package]]
+name = "bstr"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b45ea9b00a7b3f2988e9a65ad3917e62123c38dba709b666506207be96d1790b"
+dependencies = [
+ "memchr",
+ "once_cell",
+ "regex-automata",
+ "serde",
+]
+
 [[package]]
 name = "bumpalo"
 version = "3.11.1"
@@ -654,6 +680,12 @@ version = "2.3.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "23d8666cb01533c39dde32bcbab8e227b4ed6679b2c925eba05feabea39508fb"
 
+[[package]]
+name = "difflib"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
+
 [[package]]
 name = "digest"
 version = "0.10.6"
@@ -684,6 +716,7 @@ name = "dioxus-cli"
 version = "0.3.0"
 dependencies = [
  "anyhow",
+ "assert_cmd",
  "atty",
  "axum",
  "binary-install",
@@ -712,6 +745,7 @@ dependencies = [
  "log",
  "mlua",
  "notify",
+ "predicates",
  "proc-macro2",
  "regex",
  "reqwest",
@@ -808,6 +842,12 @@ dependencies = [
  "winapi",
 ]
 
+[[package]]
+name = "doc-comment"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
+
 [[package]]
 name = "either"
 version = "1.8.0"
@@ -935,6 +975,15 @@ dependencies = [
  "miniz_oxide",
 ]
 
+[[package]]
+name = "float-cmp"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
+dependencies = [
+ "num-traits",
+]
+
 [[package]]
 name = "fnv"
 version = "1.0.7"
@@ -1711,7 +1760,7 @@ version = "0.8.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "2ee2ad7a9aa69056b148d9d590344bc155d3ce0d2200e3b2838f7034f6ba33c1"
 dependencies = [
- "bstr",
+ "bstr 0.2.17",
  "cc",
  "futures-core",
  "futures-task",
@@ -1770,6 +1819,12 @@ dependencies = [
  "static_assertions",
 ]
 
+[[package]]
+name = "normalize-line-endings"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
+
 [[package]]
 name = "notify"
 version = "5.0.0"
@@ -2051,6 +2106,36 @@ version = "0.2.17"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
 
+[[package]]
+name = "predicates"
+version = "2.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd"
+dependencies = [
+ "difflib",
+ "float-cmp",
+ "itertools",
+ "normalize-line-endings",
+ "predicates-core",
+ "regex",
+]
+
+[[package]]
+name = "predicates-core"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72f883590242d3c6fc5bf50299011695fa6590c2c70eac95ee1bdb9a733ad1a2"
+
+[[package]]
+name = "predicates-tree"
+version = "1.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "54ff541861505aabf6ea722d2131ee980b8276e10a1297b94e896dd8b621850d"
+dependencies = [
+ "predicates-core",
+ "termtree",
+]
+
 [[package]]
 name = "prettyplease"
 version = "0.1.15"
@@ -2186,6 +2271,12 @@ dependencies = [
  "regex-syntax",
 ]
 
+[[package]]
+name = "regex-automata"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
+
 [[package]]
 name = "regex-syntax"
 version = "0.6.28"
@@ -2653,6 +2744,12 @@ dependencies = [
  "winapi-util",
 ]
 
+[[package]]
+name = "termtree"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95059e91184749cb66be6dc994f67f182b6d897cb3df74a5bf66b5e709295fd8"
+
 [[package]]
 name = "textwrap"
 version = "0.16.0"
@@ -3095,6 +3192,15 @@ version = "0.9.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
 
+[[package]]
+name = "wait-timeout"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
+dependencies = [
+ "libc",
+]
+
 [[package]]
 name = "walkdir"
 version = "2.3.2"

+ 2 - 1
README.md

@@ -2,7 +2,8 @@
   <h1>📦✨ Dioxus CLI </h1>
   <p><strong>Tooling to supercharge Dioxus projects</strong></p>
 </div>
-**dioxus-cli** (inspired by wasm-pack and webpack) is a tool for getting Dioxus projects up and running. It handles all of the build, bundling, development and publishing to simplify web development.
+**dioxus-cli** (inspired by wasm-pack and webpack) is a tool for getting Dioxus projects up and running. 
+It handles all build, bundling, development and publishing to simplify web development.
 
 
 ## Installation

+ 2 - 2
src/cli/create/mod.rs

@@ -17,7 +17,7 @@ pub struct Create {
 impl Create {
     pub fn create(self) -> Result<()> {
         if Self::name_valid_check(self.name.clone()) {
-            return custom_error!("❗Unsupported project name.");
+            return custom_error!("❗Unsupported project name: '{}'.", &self.name);
         }
 
         let project_path = PathBuf::from(&self.name);
@@ -26,7 +26,7 @@ impl Create {
             return custom_error!("🧨 Folder '{}' is initialized.", &self.name);
         }
 
-        log::info!("🔧 Start to create a new project '{}'.", self.name);
+        log::info!("🔧 Start: Creating new project '{}'.", self.name);
 
         let output = Command::new("cargo")
             .arg("generate")

+ 1 - 1
src/config.rs

@@ -18,7 +18,7 @@ fn default_plugin() -> toml::Value {
 
 impl DioxusConfig {
     pub fn load() -> crate::error::Result<Option<DioxusConfig>> {
-        let crate_dir = crate::cargo::crate_root()?;
+        let Ok(crate_dir) = crate::cargo::crate_root() else { return Ok(None); };
 
         // we support either `Dioxus.toml` or `Cargo.toml`
         let Some(dioxus_conf_file) = acquire_dioxus_toml(crate_dir) else {

+ 2 - 2
src/main.rs

@@ -10,9 +10,9 @@ async fn main() -> anyhow::Result<()> {
     set_up_logging();
 
     let dioxus_config = DioxusConfig::load()
-        .map_err(|e| anyhow!("Failed to load `dioxus.toml` because: {e}"))?
+        .map_err(|e| anyhow!("Failed to load `Dioxus.toml` because: {e}"))?
         .unwrap_or_else(|| {
-            log::warn!("Your `dioxus.toml` could not be found. Using the default config. To set up this crate with dioxus, use `dioxus init`.");
+            log::warn!("You appear to be creating a Dioxus project from scratch; we will use the default config");
             DioxusConfig::default()
         });