ソースを参照

feat: config init `platform` arg

mrxiaozhuox 3 年 前
コミット
91a8ce3169
3 ファイル変更15 行追加4 行削除
  1. 3 1
      src/assets/autoreload.js
  2. 1 1
      src/assets/dioxus.toml
  3. 11 2
      src/cli/config/mod.rs

+ 3 - 1
src/assets/autoreload.js

@@ -1,3 +1,6 @@
+// Dioxus-CLI
+// https://github.com/DioxusLabs/cli
+
 (function () {
   var protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
   var url = protocol + '//' + window.location.host + '/_dioxus/ws';
@@ -15,7 +18,6 @@
   var ws = new WebSocket(url);
   ws.onmessage = (ev) => {
       if (ev.data == "reload") {
-        //   alert("reload!!!");
           window.location.reload();
       }
   };

+ 1 - 1
src/assets/dioxus.toml

@@ -6,7 +6,7 @@ name = "{{project-name}}"
 # default platfrom
 # you can also use `dioxus serve/build --platform XXX` to use other platform
 # value: web | desktop
-default_platform = "web"
+default_platform = "{{default-platform}}"
 
 # Web `build` & `serve` dist path
 out_dir = "dist"

+ 11 - 2
src/cli/config/mod.rs

@@ -13,6 +13,10 @@ pub enum Config {
         #[clap(long)]
         #[serde(default)]
         force: bool,
+
+        /// Project default platform
+        #[clap(long, default_value = "web")]
+        platform: String,
     },
 }
 
@@ -20,7 +24,11 @@ impl Config {
     pub fn config(self) -> Result<()> {
         let crate_root = crate::cargo::crate_root()?;
         match self {
-            Config::Init { name, force } => {
+            Config::Init {
+                name,
+                force,
+                platform,
+            } => {
                 let conf_path = crate_root.join("Dioxus.toml");
                 if conf_path.is_file() && !force {
                     log::warn!(
@@ -30,7 +38,8 @@ impl Config {
                 }
                 let mut file = File::create(conf_path)?;
                 let content = String::from(include_str!("../../assets/dioxus.toml"))
-                    .replace("{{project-name}}", &name);
+                    .replace("{{project-name}}", &name)
+                    .replace("{{default-platform}}", &platform);
                 file.write_all(content.as_bytes())?;
                 log::info!("🚩 Init config file completed.");
             }