From 91a8ce31690d54b8df896254e58206da2816b0cd Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Thu, 10 Mar 2022 11:29:27 +0800 Subject: [PATCH] feat: config init `platform` arg --- src/assets/autoreload.js | 4 +++- src/assets/dioxus.toml | 2 +- src/cli/config/mod.rs | 13 +++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/assets/autoreload.js b/src/assets/autoreload.js index da62e5eae..fffb3e26c 100644 --- a/src/assets/autoreload.js +++ b/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(); } }; diff --git a/src/assets/dioxus.toml b/src/assets/dioxus.toml index d3f160242..af9cc886b 100644 --- a/src/assets/dioxus.toml +++ b/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" diff --git a/src/cli/config/mod.rs b/src/cli/config/mod.rs index 6d672b7a5..2a1f28fda 100644 --- a/src/cli/config/mod.rs +++ b/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."); }