From 352b452b1707428f690deae3f32573a0c3468ee8 Mon Sep 17 00:00:00 2001 From: Tipragot Date: Sat, 3 Feb 2024 13:36:24 +0100 Subject: [PATCH] =?UTF-8?q?D=C3=A9t=C3=A9ction=20du=20nom=20du=20projet=20?= =?UTF-8?q?pour=20le=20build=20du=20projet=20dioxus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8edcbad..0c7e7b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,9 +8,10 @@ pub use dioxus_fullstack::prelude::*; /// Compile le site en webassembly et génaire le fichier de style avec tailwind. fn build_app() { use std::fs; + use std::io::{BufRead, BufReader}; use std::path::{Path, PathBuf}; - use dioxus_cli::CrateConfig; + use dioxus_cli::{CrateConfig, ExecutableType}; use railwind::{CollectionOptions, SourceOptions}; use regex::Regex; use walkdir::WalkDir; @@ -18,6 +19,18 @@ fn build_app() { let project_folder = Path::new(env!("CARGO_MANIFEST_DIR")); let output_folder = project_folder.join("web"); + // Get the project name + let cargo_file = + fs::File::open(project_folder.join("Cargo.toml")).expect("unable to open Cargo.toml"); + let project_name = BufReader::new(cargo_file) + .lines() + .map_while(Result::ok) + .find(|l| l.starts_with("name = ")) + .expect("unable to find project name"); + let project_name = project_name + .trim_start_matches("name = \"") + .trim_end_matches('"'); + // Build WASM let mut config = CrateConfig::new(Some(project_folder.to_path_buf())) .expect("unable to load the project configuration"); @@ -25,6 +38,7 @@ fn build_app() { config.asset_dir = project_folder.join("assets"); config.out_dir = output_folder.clone(); config.dioxus_config.web.resource.style = Some(vec![PathBuf::from("style.css")]); + config.executable = ExecutableType::Binary(project_name.to_string()); dioxus_cli::build(&config, false).expect("unable to build webassembly"); let index_content = dioxus_cli::gen_page(&config.dioxus_config, false); fs::write(output_folder.join("index.html"), index_content).expect("unable to write index.html");