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]
|
||||
|
||||
# App (Project) Name
|
||||
name = "dioxus-cli"
|
||||
name = "{{project-name}}"
|
||||
|
||||
# Dioxus App Support Platform
|
||||
# desktop, web, mobile, ssr
|
||||
@@ -12,31 +12,27 @@ out_dir = "dist"
|
||||
|
||||
[web.app]
|
||||
|
||||
# HTML title tag content
|
||||
title = "dioxus | ⛺"
|
||||
|
||||
# resource (static) file folder
|
||||
public_dir = "public"
|
||||
|
||||
[web.watcher]
|
||||
|
||||
|
||||
watch_path = ["src"]
|
||||
|
||||
# include `assets` in web platform
|
||||
[web.resource]
|
||||
|
||||
# CSS style file
|
||||
style = [
|
||||
"./my-style.css"
|
||||
]
|
||||
style = []
|
||||
|
||||
# Javascript code file
|
||||
script = [
|
||||
"./app.js"
|
||||
]
|
||||
script = []
|
||||
|
||||
[web.resource.dev]
|
||||
|
||||
# Javascript code file
|
||||
# serve: [dev-server] only
|
||||
script = [
|
||||
"./debug.js"
|
||||
]
|
||||
script = []
|
||||
@@ -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
|
||||
#[structopt(default_value = "gh:dioxuslabs/dioxus-template", long)]
|
||||
template: String,
|
||||
|
||||
/// Create a `lib` project, include a `hello-world` example.
|
||||
#[structopt(long)]
|
||||
#[serde(default)]
|
||||
pub lib: bool,
|
||||
}
|
||||
|
||||
impl Create {
|
||||
|
||||
+4
-3
@@ -3,6 +3,7 @@ use structopt::StructOpt;
|
||||
pub mod build;
|
||||
pub mod cfg;
|
||||
pub mod clean;
|
||||
pub mod config;
|
||||
pub mod create;
|
||||
pub mod serve;
|
||||
pub mod translate;
|
||||
@@ -36,8 +37,8 @@ pub enum Commands {
|
||||
Serve(serve::Serve),
|
||||
/// Init a new project for Dioxus.
|
||||
Create(create::Create),
|
||||
// /// Clean output artifacts.
|
||||
/// Clean output artifacts.
|
||||
Clean(clean::Clean),
|
||||
// /// Trunk config controls.
|
||||
// Config(config::Config),
|
||||
/// Dioxus config file controls.
|
||||
Config(config::Config),
|
||||
}
|
||||
+3
-1
@@ -13,7 +13,9 @@ impl DioxusConfig {
|
||||
let crate_dir = crate::cargo::crate_root()?;
|
||||
|
||||
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"))?;
|
||||
|
||||
@@ -39,6 +39,12 @@ async fn main() -> Result<()> {
|
||||
log::error!("create error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
Commands::Config(opts) => {
|
||||
if let Err(e) = opts.config() {
|
||||
log::error!("config error: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user