Détéction du nom du projet pour le build du projet dioxus #3

Merged
tipragot merged 1 commit from fix-project-name into main 2024-02-03 12:53:12 +00:00
Showing only changes of commit 352b452b17 - Show all commits

View file

@ -8,9 +8,10 @@ pub use dioxus_fullstack::prelude::*;
/// Compile le site en webassembly et génaire le fichier de style avec tailwind. /// Compile le site en webassembly et génaire le fichier de style avec tailwind.
fn build_app() { fn build_app() {
use std::fs; use std::fs;
use std::io::{BufRead, BufReader};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use dioxus_cli::CrateConfig; use dioxus_cli::{CrateConfig, ExecutableType};
use railwind::{CollectionOptions, SourceOptions}; use railwind::{CollectionOptions, SourceOptions};
use regex::Regex; use regex::Regex;
use walkdir::WalkDir; use walkdir::WalkDir;
@ -18,6 +19,18 @@ fn build_app() {
let project_folder = Path::new(env!("CARGO_MANIFEST_DIR")); let project_folder = Path::new(env!("CARGO_MANIFEST_DIR"));
let output_folder = project_folder.join("web"); 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 // Build WASM
let mut config = CrateConfig::new(Some(project_folder.to_path_buf())) let mut config = CrateConfig::new(Some(project_folder.to_path_buf()))
.expect("unable to load the project configuration"); .expect("unable to load the project configuration");
@ -25,6 +38,7 @@ fn build_app() {
config.asset_dir = project_folder.join("assets"); config.asset_dir = project_folder.join("assets");
config.out_dir = output_folder.clone(); config.out_dir = output_folder.clone();
config.dioxus_config.web.resource.style = Some(vec![PathBuf::from("style.css")]); 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"); dioxus_cli::build(&config, false).expect("unable to build webassembly");
let index_content = dioxus_cli::gen_page(&config.dioxus_config, false); 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"); fs::write(output_folder.join("index.html"), index_content).expect("unable to write index.html");