diff --git a/src/cli/build/mod.rs b/src/cli/build/mod.rs index cbf82b339..82060b436 100644 --- a/src/cli/build/mod.rs +++ b/src/cli/build/mod.rs @@ -1,6 +1,7 @@ -use std::{io::Write, path::PathBuf}; +use std::{io::Write, path::PathBuf, process::Command, fs::copy}; use crate::{cfg::ConfigOptsBuild, gen_page}; +use std::fs::remove_dir_all; use structopt::StructOpt; /// Build the Rust WASM app and all of its assets. @@ -22,6 +23,66 @@ impl Build { crate_config.as_example(self.build.example.unwrap()); } + if self.build.platform.is_some() { + if self.build.platform.unwrap().to_uppercase() == "DESKTOP" { + log::info!("🚅 Running build command..."); + + let mut cmd = Command::new("cargo"); + cmd.current_dir(&crate_config.crate_dir) + .arg("build") + .stdout(std::process::Stdio::inherit()) + .stderr(std::process::Stdio::inherit()); + + if self.build.release { + cmd.arg("--release"); + } + + match &crate_config.executable { + crate::ExecutableType::Binary(name) => cmd.arg("--bin").arg(name), + crate::ExecutableType::Lib(name) => cmd.arg("--lib").arg(name), + crate::ExecutableType::Example(name) => cmd.arg("--example").arg(name), + }; + + let output = cmd.output()?; + + if output.status.success() { + if crate_config.out_dir.is_dir() { + + remove_dir_all(&crate_config.out_dir)?; + + let release_type = match crate_config.release { + true => "release", + false => "debug", + }; + + let mut res_path = match &crate_config.executable { + crate::ExecutableType::Binary(name) + | crate::ExecutableType::Lib(name) => crate_config + .target_dir + .join(format!("{}", release_type)) + .join(format!("{}", name)), + + crate::ExecutableType::Example(name) => crate_config + .target_dir + .join(format!("{}/examples", release_type)) + .join(format!("{}", name)), + }; + + let target_file; + if cfg!(windows) { + res_path.set_extension("exe"); + target_file = format!("{}.exe", &crate_config.dioxus_config.application.name); + } else { + target_file = crate_config.dioxus_config.application.name.clone(); + } + copy(res_path, &crate_config.out_dir.join(target_file))?; + } + } + + return Ok(()); + } + } + crate::builder::build(&crate_config)?; let temp = gen_page(&crate_config.dioxus_config, false); diff --git a/src/cli/cfg.rs b/src/cli/cfg.rs index 6a27c4890..7010d62e6 100644 --- a/src/cli/cfg.rs +++ b/src/cli/cfg.rs @@ -20,44 +20,9 @@ pub struct ConfigOptsBuild { #[structopt(long)] pub example: Option, - /// Optional pattern for the app loader script [default: None] - /// - /// Patterns should include the sequences `{base}`, `{wasm}`, and `{js}` in order to - /// properly load the application. Other sequences may be included corresponding - /// to key/value pairs provided in `pattern_params`. - /// - /// These values can only be provided via config file. - #[structopt(skip)] - #[serde(default)] - pub pattern_script: Option, - - /// Optional pattern for the app preload element [default: None] - /// - /// Patterns should include the sequences `{base}`, `{wasm}`, and `{js}` in order to - /// properly preload the application. Other sequences may be included corresponding - /// to key/value pairs provided in `pattern_params`. - /// - /// These values can only be provided via config file. - #[structopt(skip)] - #[serde(default)] - pub pattern_preload: Option, - - #[structopt(skip)] - #[serde(default)] - /// Optional replacement parameters corresponding to the patterns provided in - /// `pattern_script` and `pattern_preload`. - /// - /// When a pattern is being replaced with its corresponding value from this map, if the value is - /// prefixed with the symbol `@`, then the value is expected to be a file path, and the pattern - /// will be replaced with the contents of the target file. This allows insertion of some big JSON - /// state or even HTML files as a part of the `index.html` build. - /// - /// Trunk will automatically insert the `base`, `wasm` and `js` key/values into this map. In order - //// for the app to be loaded properly, the patterns `{base}`, `{wasm}` and `{js}` should be used - /// in `pattern_script` and `pattern_preload`. - /// - /// These values can only be provided via config file. - pub pattern_params: Option>, + /// Build platform: support Web & Desktop [default: "web"] + #[structopt(long)] + pub platform: Option, } #[derive(Clone, Debug, Default, Deserialize, StructOpt)]