This commit is contained in:
Jonathan Kelley committed 2022-02-18 15:40:38 -05:00
commit 1e24b5b416
19 files changed
+292 -179

No files matched your search

+17 -12
View File
@@ -1,36 +1,41 @@
use std::{io::Write, path::PathBuf};
use crate::{cfg::ConfigOptsBuild, gen_page};
use structopt::StructOpt;
use super::*;
/// Build the Rust WASM app and all of its assets.
#[derive(Clone, Debug, StructOpt)]
#[structopt(name = "build")]
#[derive(Clone, Debug, Parser)]
#[clap(name = "build")]
pub struct Build {
#[structopt(flatten)]
#[clap(flatten)]
pub build: ConfigOptsBuild,
}
impl Build {
pub fn build(self) -> anyhow::Result<()> {
pub fn build(self) -> Result<()> {
let mut crate_config = crate::CrateConfig::new()?;
// change the relase state.
// change the release state.
crate_config.with_release(self.build.release);
if self.build.example.is_some() {
crate_config.as_example(self.build.example.unwrap());
}
match self.build.platform.as_str() {
let platform = self.build.platform.unwrap_or_else(|| {
crate_config
.dioxus_config
.application
.default_platform
.clone()
});
match platform.as_str() {
"web" => {
crate::builder::build(&crate_config)?;
}
"desktop" => {
crate::builder::build_desktop(&crate_config)?;
crate::builder::build_desktop(&crate_config, false)?;
}
_ => {
return Err(anyhow::anyhow!("Unsoppurt platform target."));
return custom_error!("Unsoppurt platform target.");
}
}
+15 -18
View File
@@ -1,47 +1,44 @@
use std::path::PathBuf;
use structopt::StructOpt;
use serde::Deserialize;
use super::*;
/// Config options for the build system.
#[derive(Clone, Debug, Default, Deserialize, StructOpt)]
#[derive(Clone, Debug, Default, Deserialize, Parser)]
pub struct ConfigOptsBuild {
/// The index HTML file to drive the bundling process [default: index.html]
#[structopt(parse(from_os_str))]
#[clap(parse(from_os_str))]
pub target: Option<PathBuf>,
/// Build in release mode [default: false]
#[structopt(long)]
#[clap(long)]
#[serde(default)]
pub release: bool,
/// Build a example [default: ""]
#[structopt(long)]
#[clap(long)]
pub example: Option<String>,
/// Build platform: support Web & Desktop [default: "web"]
#[structopt(long, default_value = "web")]
pub platform: String,
/// Build platform: support Web & Desktop [default: "default_platform"]
#[clap(long)]
pub platform: Option<String>,
}
#[derive(Clone, Debug, Default, Deserialize, StructOpt)]
#[derive(Clone, Debug, Default, Deserialize, Parser)]
pub struct ConfigOptsServe {
/// The index HTML file to drive the bundling process [default: index.html]
#[structopt(parse(from_os_str))]
#[clap(parse(from_os_str))]
pub target: Option<PathBuf>,
/// Build a example [default: ""]
#[structopt(long)]
#[clap(long)]
pub example: Option<String>,
/// Build in release mode [default: false]
#[structopt(long)]
#[clap(long)]
#[serde(default)]
pub release: bool,
/// Build platform: support Web & Desktop [default: "web"]
#[structopt(long, default_value = "web")]
pub platform: String,
/// Build platform: support Web & Desktop [default: "default_platform"]
#[clap(long)]
pub platform: Option<String>,
}
/// Ensure the given value for `--public-url` is formatted correctly.
+4 -10
View File
@@ -1,18 +1,12 @@
use std::{
fs::remove_dir_all,
path::PathBuf,
process::{Command, Stdio},
};
use structopt::StructOpt;
use super::*;
/// Build the Rust WASM app and all of its assets.
#[derive(Clone, Debug, StructOpt)]
#[structopt(name = "clean")]
#[derive(Clone, Debug, Parser)]
#[clap(name = "clean")]
pub struct Clean {}
impl Clean {
pub fn clean(self) -> anyhow::Result<()> {
pub fn clean(self) -> Result<()> {
let crate_config = crate::CrateConfig::new()?;
let output = Command::new("cargo")
+5 -8
View File
@@ -1,11 +1,8 @@
use std::{fs::File, io::Write};
use serde::Deserialize;
use structopt::StructOpt;
use super::*;
/// Build the Rust WASM app and all of its assets.
#[derive(Clone, Debug, Deserialize, StructOpt)]
#[structopt(name = "config")]
#[derive(Clone, Debug, Deserialize, Subcommand)]
#[clap(name = "config")]
pub enum Config {
/// Init `Dioxus.toml` for project/folder.
Init {
@@ -13,14 +10,14 @@ pub enum Config {
name: String,
/// Cover old config
#[structopt(long)]
#[clap(long)]
#[serde(default)]
force: bool,
},
}
impl Config {
pub fn config(self) -> anyhow::Result<()> {
pub fn config(self) -> Result<()> {
let crate_root = crate::cargo::crate_root()?;
match self {
Config::Init { name, force } => {
+9 -24
View File
@@ -1,26 +1,16 @@
use std::{
fs::File,
io::{Read, Write},
path::PathBuf,
process::{Command, Stdio},
};
use regex::Regex;
use serde::Deserialize;
use structopt::StructOpt;
use crate::{error::Result, Error};
use super::*;
use crate::custom_error;
/// Build the Rust WASM app and all of its assets.
#[derive(Clone, Debug, Default, Deserialize, StructOpt)]
#[structopt(name = "create")]
#[derive(Clone, Debug, Default, Deserialize, Parser)]
#[clap(name = "create")]
pub struct Create {
/// Init project name
#[structopt(default_value = ".")]
#[clap(default_value = ".")]
name: String,
/// Template path
#[structopt(default_value = "gh:dioxuslabs/dioxus-template", long)]
#[clap(default_value = "gh:dioxuslabs/dioxus-template", long)]
template: String,
}
@@ -34,10 +24,7 @@ impl Create {
let project_path = PathBuf::from(&self.name);
if project_path.join("Dioxus.toml").is_file() || project_path.join("Cargo.toml").is_file() {
return Err(Error::Other(anyhow::anyhow!(
"🧨 Folder '{}' is initialized.",
&self.name
)));
return custom_error!("🧨 Folder '{}' is initialized.", &self.name);
}
log::info!("🔧 Start to create a new project '{}'.", self.name);
@@ -58,9 +45,7 @@ impl Create {
.stderr(Stdio::inherit())
.output()?;
if !install_output.status.success() {
return Err(Error::Other(anyhow::anyhow!(
"Try to install cargo-generate failed."
)));
return custom_error!("Try to install cargo-generate failed.");
}
}
@@ -74,7 +59,7 @@ impl Create {
.output()?;
if !generate_output.status.success() {
return Err(Error::Other(anyhow::anyhow!("Generate project failed.")));
return custom_error!("Generate project failed.");
}
let mut dioxus_file = File::open(project_path.join("Dioxus.toml"))?;
+25 -11
View File
@@ -1,5 +1,3 @@
use structopt::StructOpt;
pub mod build;
pub mod cfg;
pub mod clean;
@@ -8,26 +6,41 @@ pub mod create;
pub mod serve;
pub mod translate;
use crate::{
cfg::{ConfigOptsBuild, ConfigOptsServe},
custom_error,
error::Result,
gen_page, server, CrateConfig, Error,
};
use clap::{Parser, Subcommand};
use html_parser::{Dom, Element, Node};
use regex::Regex;
use serde::Deserialize;
use std::{
fmt::{Display, Formatter},
fs::{remove_dir_all, File},
io::{Read, Write},
path::PathBuf,
process::{exit, Command, Stdio},
};
/// Build, bundle, & ship your Dioxus app.
///
///
#[derive(StructOpt)]
#[structopt(name = "dioxus")]
#[derive(Parser)]
#[clap(name = "dioxus")]
pub struct Cli {
#[structopt(subcommand)]
#[clap(subcommand)]
pub action: Commands,
/// Enable verbose logging.
#[structopt(short)]
#[clap(short)]
pub v: bool,
//
// // note: dioxus is still roughly compatible with trunk
// /// Path to the Trunk config file [default: Trunk.toml]
// #[structopt(long, parse(from_os_str), env = "TRUNK_CONFIG")]
// #[clap(long, parse(from_os_str), env = "TRUNK_CONFIG")]
// pub config: Option<PathBuf>,
}
#[derive(StructOpt)]
#[derive(Parser)]
pub enum Commands {
/// Build the Rust WASM app and all of its assets.
Build(build::Build),
@@ -40,5 +53,6 @@ pub enum Commands {
/// Clean output artifacts.
Clean(clean::Clean),
/// Dioxus config file controls.
#[clap(subcommand)]
Config(config::Config),
}
+22 -11
View File
@@ -1,17 +1,20 @@
use crate::{cfg::ConfigOptsServe, gen_page, server, CrateConfig};
use std::{io::Write, path::PathBuf, process::{Command, Stdio}};
use structopt::StructOpt;
use std::{
io::Write,
path::PathBuf,
process::{Command, Stdio},
};
use super::*;
/// Run the WASM project on dev-server
#[derive(Clone, Debug, StructOpt)]
#[structopt(name = "serve")]
#[derive(Clone, Debug, Parser)]
#[clap(name = "serve")]
pub struct Serve {
#[structopt(flatten)]
#[clap(flatten)]
pub serve: ConfigOptsServe,
}
impl Serve {
pub async fn serve(self) -> anyhow::Result<()> {
pub async fn serve(self) -> Result<()> {
let mut crate_config = crate::CrateConfig::new()?;
// change the relase state.
@@ -21,12 +24,20 @@ impl Serve {
crate_config.as_example(self.serve.example.unwrap());
}
match self.serve.platform.as_str() {
let platform = self.serve.platform.unwrap_or_else(|| {
crate_config
.dioxus_config
.application
.default_platform
.clone()
});
match platform.as_str() {
"web" => {
crate::builder::build(&crate_config)?;
}
"desktop" => {
crate::builder::build_desktop(&crate_config)?;
crate::builder::build_desktop(&crate_config, true)?;
match &crate_config.executable {
crate::ExecutableType::Binary(name)
@@ -51,7 +62,7 @@ impl Serve {
return Ok(());
}
_ => {
return Err(anyhow::anyhow!("Unsoppurt platform target."));
return custom_error!("Unsoppurt platform target.");
}
}
@@ -64,7 +75,7 @@ impl Serve {
Ok(())
}
pub fn regen_dev_page(crate_config: &CrateConfig) -> anyhow::Result<()> {
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(
+7 -16
View File
@@ -1,34 +1,25 @@
use anyhow::Result;
use html_parser::Dom;
use html_parser::Element;
use html_parser::Node;
#[allow(unused_imports)]
use std::fmt::{Display, Formatter};
use std::io::Read;
use std::path::PathBuf;
use std::process::exit;
use structopt::StructOpt;
use super::*;
/// Build the Rust WASM app and all of its assets.
#[derive(Clone, Debug, StructOpt)]
#[structopt(name = "translate")]
#[derive(Clone, Debug, Parser)]
#[clap(name = "translate")]
pub struct Translate {
/// Activate debug mode
// short and long flags (-d, --debug) will be deduced from the field's name
#[structopt(short, long)]
#[clap(short, long)]
pub component: bool,
/// Input file
#[structopt(short, long)]
#[clap(short, long)]
pub file: Option<String>,
/// Output file, stdout if not present
#[structopt(short, long)]
#[clap(parse(from_os_str))]
pub output: Option<PathBuf>,
}
impl Translate {
pub fn translate(self) -> anyhow::Result<()> {
pub fn translate(self) -> Result<()> {
let Translate {
component,
output,