feat: add config command
This commit is contained in:
1 parent
4cc7752adf
commit
66b832045a
6 files changed
+63
-20
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
# App (Project) Name
|
# App (Project) Name
|
||||||
name = "dioxus-cli"
|
name = "{{project-name}}"
|
||||||
|
|
||||||
# Dioxus App Support Platform
|
# Dioxus App Support Platform
|
||||||
# desktop, web, mobile, ssr
|
# desktop, web, mobile, ssr
|
||||||
@@ -12,31 +12,27 @@ out_dir = "dist"
|
|||||||
|
|
||||||
[web.app]
|
[web.app]
|
||||||
|
|
||||||
|
# HTML title tag content
|
||||||
|
title = "dioxus | ⛺"
|
||||||
|
|
||||||
# resource (static) file folder
|
# resource (static) file folder
|
||||||
public_dir = "public"
|
public_dir = "public"
|
||||||
|
|
||||||
[web.watcher]
|
[web.watcher]
|
||||||
|
|
||||||
|
|
||||||
watch_path = ["src"]
|
watch_path = ["src"]
|
||||||
|
|
||||||
# include `assets` in web platform
|
# include `assets` in web platform
|
||||||
[web.resource]
|
[web.resource]
|
||||||
|
|
||||||
# CSS style file
|
# CSS style file
|
||||||
style = [
|
style = []
|
||||||
"./my-style.css"
|
|
||||||
]
|
|
||||||
|
|
||||||
# Javascript code file
|
# Javascript code file
|
||||||
script = [
|
script = []
|
||||||
"./app.js"
|
|
||||||
]
|
|
||||||
|
|
||||||
[web.resource.dev]
|
[web.resource.dev]
|
||||||
|
|
||||||
# Javascript code file
|
# Javascript code file
|
||||||
# serve: [dev-server] only
|
# serve: [dev-server] only
|
||||||
script = [
|
script = []
|
||||||
"./debug.js"
|
|
||||||
]
|
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
use std::{fs::File, io::Write};
|
||||||
|
|
||||||
|
use serde::Deserialize;
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
/// Build the Rust WASM app and all of its assets.
|
||||||
|
#[derive(Clone, Debug, Deserialize, StructOpt)]
|
||||||
|
#[structopt(name = "config")]
|
||||||
|
pub enum Config {
|
||||||
|
/// Init `Dioxus.toml` for project/folder.
|
||||||
|
Init {
|
||||||
|
/// Init project name
|
||||||
|
name: String,
|
||||||
|
|
||||||
|
/// Cover old config
|
||||||
|
#[structopt(long)]
|
||||||
|
#[serde(default)]
|
||||||
|
force: bool,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn config(self) -> anyhow::Result<()> {
|
||||||
|
let crate_root = crate::cargo::crate_root()?;
|
||||||
|
match self {
|
||||||
|
Config::Init { name, force } => {
|
||||||
|
let conf_path = crate_root.join("Dioxus.toml");
|
||||||
|
if conf_path.is_file() && force == false {
|
||||||
|
log::warn!(
|
||||||
|
"config file `Dioxus.toml` already exist, use `--force` to overwrite it."
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let mut file = File::create(conf_path)?;
|
||||||
|
let content = String::from(include_str!("../../assets/dioxus.toml"))
|
||||||
|
.replace("{{project-name}}", &name);
|
||||||
|
file.write_all(content.as_bytes())?;
|
||||||
|
log::info!("🚩 Init config file completed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,11 +22,6 @@ pub struct Create {
|
|||||||
/// Template path
|
/// Template path
|
||||||
#[structopt(default_value = "gh:dioxuslabs/dioxus-template", long)]
|
#[structopt(default_value = "gh:dioxuslabs/dioxus-template", long)]
|
||||||
template: String,
|
template: String,
|
||||||
|
|
||||||
/// Create a `lib` project, include a `hello-world` example.
|
|
||||||
#[structopt(long)]
|
|
||||||
#[serde(default)]
|
|
||||||
pub lib: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Create {
|
impl Create {
|
||||||
|
|||||||
+4
-3
@@ -3,6 +3,7 @@ use structopt::StructOpt;
|
|||||||
pub mod build;
|
pub mod build;
|
||||||
pub mod cfg;
|
pub mod cfg;
|
||||||
pub mod clean;
|
pub mod clean;
|
||||||
|
pub mod config;
|
||||||
pub mod create;
|
pub mod create;
|
||||||
pub mod serve;
|
pub mod serve;
|
||||||
pub mod translate;
|
pub mod translate;
|
||||||
@@ -36,8 +37,8 @@ pub enum Commands {
|
|||||||
Serve(serve::Serve),
|
Serve(serve::Serve),
|
||||||
/// Init a new project for Dioxus.
|
/// Init a new project for Dioxus.
|
||||||
Create(create::Create),
|
Create(create::Create),
|
||||||
// /// Clean output artifacts.
|
/// Clean output artifacts.
|
||||||
Clean(clean::Clean),
|
Clean(clean::Clean),
|
||||||
// /// Trunk config controls.
|
/// Dioxus config file controls.
|
||||||
// Config(config::Config),
|
Config(config::Config),
|
||||||
}
|
}
|
||||||
+3
-1
@@ -13,7 +13,9 @@ impl DioxusConfig {
|
|||||||
let crate_dir = crate::cargo::crate_root()?;
|
let crate_dir = crate::cargo::crate_root()?;
|
||||||
|
|
||||||
if !crate_dir.join("Dioxus.toml").is_file() {
|
if !crate_dir.join("Dioxus.toml").is_file() {
|
||||||
return Err(crate::error::Error::Unique("Config file: `Dioxus.toml` not found.".into()));
|
return Err(crate::error::Error::Unique(
|
||||||
|
"Config file: `Dioxus.toml` not found.".into(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut dioxus_conf_file = File::open(crate_dir.join("Dioxus.toml"))?;
|
let mut dioxus_conf_file = File::open(crate_dir.join("Dioxus.toml"))?;
|
||||||
|
|||||||
@@ -39,6 +39,12 @@ async fn main() -> Result<()> {
|
|||||||
log::error!("create error: {}", e);
|
log::error!("create error: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Commands::Config(opts) => {
|
||||||
|
if let Err(e) = opts.config() {
|
||||||
|
log::error!("config error: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in new issue
Block a user