Merge branch 'master' into jk/formatting-and-extension

This commit is contained in:
Jonathan Kelley committed 2022-12-25 23:38:33 -05:00
commit fa52a8f71a
59 files changed
+6691 -252

No files matched your search

+13 -2
View File
@@ -1,3 +1,5 @@
use crate::plugin::PluginManager;
use super::*;
/// Build the Rust WASM app and all of its assets.
@@ -14,11 +16,16 @@ impl Build {
// change the release state.
crate_config.with_release(self.build.release);
crate_config.with_verbose(self.build.verbose);
if self.build.example.is_some() {
crate_config.as_example(self.build.example.unwrap());
}
if self.build.profile.is_some() {
crate_config.set_profile(self.build.profile.unwrap());
}
let platform = self.build.platform.unwrap_or_else(|| {
crate_config
.dioxus_config
@@ -27,15 +34,17 @@ impl Build {
.clone()
});
let _ = PluginManager::on_build_start(&crate_config, &platform);
match platform.as_str() {
"web" => {
crate::builder::build(&crate_config)?;
crate::builder::build(&crate_config, false)?;
}
"desktop" => {
crate::builder::build_desktop(&crate_config, false)?;
}
_ => {
return custom_error!("Unsoppurt platform target.");
return custom_error!("Unsupported platform target.");
}
}
@@ -56,6 +65,8 @@ impl Build {
)?;
file.write_all(temp.as_bytes())?;
let _ = PluginManager::on_build_finish(&crate_config, &platform);
Ok(())
}
}
+36
View File
@@ -12,13 +12,26 @@ pub struct ConfigOptsBuild {
#[serde(default)]
pub release: bool,
// Use verbose output [default: false]
#[clap(long)]
#[serde(default)]
pub verbose: bool,
/// Build a example [default: ""]
#[clap(long)]
pub example: Option<String>,
/// Build with custom profile
#[clap(long)]
pub profile: Option<String>,
/// Build platform: support Web & Desktop [default: "default_platform"]
#[clap(long)]
pub platform: Option<String>,
/// Space separated list of features to activate
#[clap(long)]
pub features: Option<Vec<String>>,
}
#[derive(Clone, Debug, Default, Deserialize, Parser)]
@@ -27,6 +40,11 @@ pub struct ConfigOptsServe {
#[clap(parse(from_os_str))]
pub target: Option<PathBuf>,
/// Port of dev server
#[clap(long)]
#[clap(default_value_t = 8080)]
pub port: u16,
/// Build a example [default: ""]
#[clap(long)]
pub example: Option<String>,
@@ -36,9 +54,27 @@ pub struct ConfigOptsServe {
#[serde(default)]
pub release: bool,
// Use verbose output [default: false]
#[clap(long)]
#[serde(default)]
pub verbose: bool,
/// Build with custom profile
#[clap(long)]
pub profile: Option<String>,
/// Build platform: support Web & Desktop [default: "default_platform"]
#[clap(long)]
pub platform: Option<String>,
/// Build with hot reloading rsx [default: false]
#[clap(long)]
#[serde(default)]
pub hot_reload: bool,
/// Space separated list of features to activate
#[clap(long)]
pub features: Option<Vec<String>>,
}
/// Ensure the given value for `--public-url` is formatted correctly.
+1 -2
View File
@@ -16,8 +16,7 @@ impl Clean {
.output()?;
if !output.status.success() {
log::error!("Cargo clean failed.");
return Ok(());
return custom_error!("Cargo clean failed.");
}
let out_dir = crate_config
+3 -2
View File
@@ -17,8 +17,7 @@ pub struct Create {
impl Create {
pub fn create(self) -> Result<()> {
if Self::name_vaild_check(self.name.clone()) {
log::error!("❗Unsupported project name.");
return Ok(());
return custom_error!("❗Unsupported project name.");
}
let project_path = PathBuf::from(&self.name);
@@ -54,6 +53,7 @@ impl Create {
.arg(&self.template)
.arg("--name")
.arg(&self.name)
.arg("--force")
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.output()?;
@@ -66,6 +66,7 @@ impl Create {
let mut meta_file = String::new();
dioxus_file.read_to_string(&mut meta_file)?;
meta_file = meta_file.replace("{{project-name}}", &self.name);
meta_file = meta_file.replace("{{default-platform}}", "web");
File::create(project_path.join("Dioxus.toml"))?.write_all(meta_file.as_bytes())?;
println!();
+21 -10
View File
@@ -4,8 +4,8 @@ pub mod cfg;
pub mod clean;
pub mod config;
pub mod create;
pub mod plugin;
pub mod serve;
pub mod tool;
pub mod translate;
pub mod version;
@@ -24,12 +24,12 @@ use std::{
fs::{remove_dir_all, File},
io::{Read, Write},
path::PathBuf,
process::{exit, Command, Stdio},
process::{Command, Stdio},
};
/// Build, bundle, & ship your Dioxus app.
/// Build, Bundle & Ship Dioxus Apps.
#[derive(Parser)]
#[clap(name = "dioxus")]
#[clap(name = "dioxus", version)]
pub struct Cli {
#[clap(subcommand)]
pub action: Commands,
@@ -37,10 +37,6 @@ pub struct Cli {
/// Enable verbose logging.
#[clap(short)]
pub v: bool,
// // note: dioxus is still roughly compatible with trunk
// /// Path to the Trunk config file [default: Trunk.toml]
// #[clap(long, parse(from_os_str), env = "TRUNK_CONFIG")]
// pub config: Option<PathBuf>,
}
#[derive(Parser)]
@@ -72,7 +68,22 @@ pub enum Commands {
#[clap(subcommand)]
Config(config::Config),
/// Install & Manage tools for Dioxus-cli.
/// Manage plugins for dioxus cli
#[clap(subcommand)]
Tool(tool::Tool),
Plugin(plugin::Plugin),
}
impl Commands {
pub fn to_string(&self) -> String {
match self {
Commands::Build(_) => "build",
Commands::Translate(_) => "translate",
Commands::Serve(_) => "sevre",
Commands::Create(_) => "create",
Commands::Clean(_) => "clean",
Commands::Config(_) => "config",
Commands::Plugin(_) => "plugin",
}
.to_string()
}
}
+36
View File
@@ -0,0 +1,36 @@
use super::*;
/// Build the Rust WASM app and all of its assets.
#[derive(Clone, Debug, Deserialize, Subcommand)]
#[clap(name = "plugin")]
pub enum Plugin {
/// Return all dioxus-cli support tools.
List {},
/// Get default app install path.
AppPath {},
/// Install a new tool.
Add { name: String },
}
impl Plugin {
pub async fn plugin(self) -> Result<()> {
match self {
Plugin::List {} => {
for item in crate::plugin::PluginManager::plugin_list() {
println!("- {item}");
}
}
Plugin::AppPath {} => {
if let Some(v) = crate::plugin::PluginManager::init_plugin_dir().to_str() {
println!("{}", v);
} else {
log::error!("Plugin path get failed.");
}
}
Plugin::Add { name: _ } => {
log::info!("You can use `dioxus plugin app-path` to get Installation position");
}
}
Ok(())
}
}
+35 -34
View File
@@ -1,5 +1,6 @@
use super::*;
use std::{
fs::create_dir_all,
io::Write,
path::PathBuf,
process::{Command, Stdio},
@@ -18,12 +19,18 @@ impl Serve {
let mut crate_config = crate::CrateConfig::new()?;
// change the relase state.
crate_config.with_hot_reload(self.serve.hot_reload);
crate_config.with_release(self.serve.release);
crate_config.with_verbose(self.serve.verbose);
if self.serve.example.is_some() {
crate_config.as_example(self.serve.example.unwrap());
}
if self.serve.profile.is_some() {
crate_config.set_profile(self.serve.profile.unwrap());
}
let platform = self.serve.platform.unwrap_or_else(|| {
crate_config
.dioxus_config
@@ -32,38 +39,32 @@ impl Serve {
.clone()
});
match platform.as_str() {
"web" => {
crate::builder::build(&crate_config)?;
}
"desktop" => {
crate::builder::build_desktop(&crate_config, true)?;
if platform.as_str() == "desktop" {
crate::builder::build_desktop(&crate_config, true)?;
match &crate_config.executable {
crate::ExecutableType::Binary(name)
| crate::ExecutableType::Lib(name)
| crate::ExecutableType::Example(name) => {
let mut file = crate_config.out_dir.join(name);
if cfg!(windows) {
file.set_extension("exe");
}
Command::new(crate_config.out_dir.join(file).to_str().unwrap())
.stdout(Stdio::inherit())
.output()?;
match &crate_config.executable {
crate::ExecutableType::Binary(name)
| crate::ExecutableType::Lib(name)
| crate::ExecutableType::Example(name) => {
let mut file = crate_config.out_dir.join(name);
if cfg!(windows) {
file.set_extension("exe");
}
Command::new(file.to_str().unwrap())
.stdout(Stdio::inherit())
.output()?;
}
return Ok(());
}
_ => {
return custom_error!("Unsoppurt platform target.");
}
return Ok(());
} else if platform != "web" {
return custom_error!("Unsupported platform target.");
}
// generate dev-index page
Serve::regen_dev_page(&crate_config)?;
// start the develop server
server::startup(crate_config.clone()).await?;
server::startup(self.serve.port, crate_config.clone()).await?;
Ok(())
}
@@ -71,19 +72,19 @@ impl Serve {
pub fn regen_dev_page(crate_config: &CrateConfig) -> Result<()> {
let serve_html = gen_page(&crate_config.dioxus_config, true);
let mut file = std::fs::File::create(
let dist_path = crate_config.crate_dir.join(
crate_config
.crate_dir
.join(
crate_config
.dioxus_config
.application
.out_dir
.clone()
.unwrap_or_else(|| PathBuf::from("dist")),
)
.join("index.html"),
)?;
.dioxus_config
.application
.out_dir
.clone()
.unwrap_or_else(|| PathBuf::from("dist")),
);
if !dist_path.is_dir() {
create_dir_all(&dist_path)?;
}
let index_path = dist_path.join("index.html");
let mut file = std::fs::File::create(index_path)?;
file.write_all(serve_html.as_bytes())?;
Ok(())
+11 -11
View File
@@ -20,21 +20,24 @@ impl Tool {
Tool::List {} => {
for item in tools::tool_list() {
if tools::Tool::from_str(item).unwrap().is_installed() {
println!("{item} [installed]");
println!("- {item} [installed]");
} else {
println!("{item}");
println!("- {item}");
}
}
}
Tool::AppPath {} => {
println!("{}", tools::tools_path().to_str().unwrap());
if let Some(v) = tools::tools_path().to_str() {
println!("{}", v);
} else {
return custom_error!("Tools path get failed.");
}
}
Tool::Add { name } => {
let tool_list = tools::tool_list();
if !tool_list.contains(&name.as_str()) {
log::error!("Tool {name} not found.");
return Ok(());
return custom_error!("Tool {name} not found.");
}
let target_tool = tools::Tool::from_str(&name).unwrap();
@@ -45,20 +48,17 @@ impl Tool {
log::info!("Start to download tool package...");
if let Err(e) = target_tool.download_package().await {
log::error!("Tool download failed: {e}");
return Ok(());
return custom_error!("Tool download failed: {e}");
}
log::info!("Start to install tool package...");
if let Err(e) = target_tool.install_package().await {
log::error!("Tool install failed: {e}");
return Ok(());
return custom_error!("Tool install failed: {e}");
}
log::info!("Tool {name} install successfully!");
log::info!("Tool {name} installed successfully!");
}
}
Ok(())
}
}
+1 -2
View File
@@ -43,8 +43,7 @@ impl Translate {
}
(None, None) => {
if atty::is(atty::Stream::Stdin) {
log::error!("No input file, source, or stdin to translate from.");
exit(0);
return custom_error!("No input file, source, or stdin to translate from.");
}
let mut buffer = String::new();