feat: config init platform arg

This commit is contained in:
mrxiaozhuox 2022-03-10 11:29:27 +08:00
parent 1e24b5b416
commit 91a8ce3169
3 changed files with 15 additions and 4 deletions

View file

@ -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();
}
};

View file

@ -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"

View file

@ -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.");
}