build(cargo): adding the models & database to build

This commit is contained in:
Raphael 2026-02-13 12:14:28 +01:00 committed by Raphaël
parent 4752488a7f
commit e66348c308

View file

@ -8,6 +8,7 @@ use std::{
const COMMAND_DIR: &str = "./src/commands/";
const EVENT_DIR: &str = "./src/events/";
const MODEL_DIR: &str = "./src/models/";
const DB_DIR: &str = "./src/database/";
const MOD_PREFIX: &str = "pub mod ";
const MOD_FILE: &str = "/mod_gen.rs";
@ -107,7 +108,7 @@ fn models() -> io::Result<()> {
let root: &Path = Path::new(MODEL_DIR);
let sources: Vec<String> = read_dir(root);
let mut modules: String = String::new();
println!("'modules'");
println!("'models'");
for source in sources {
modules = modules + &String::from(MOD_PREFIX) + &source + &String::from(";\n");
println!("\t'{}'", source);
@ -117,6 +118,20 @@ fn models() -> io::Result<()> {
Ok(())
}
fn database_helper() -> io::Result<()> {
let root: &Path = Path::new(DB_DIR);
let sources: Vec<String> = read_dir(root);
let mut modules: String = String::new();
println!("'database_helper'");
for source in sources {
modules = modules + &String::from(MOD_PREFIX) + &source + &String::from(";\n");
println!("\t'{}'", source);
}
write(String::from(DB_DIR) + &String::from(MOD_FILE), modules)?;
Ok(())
}
fn main() {
if let Err(e) = commands() {
panic!("Error when writing the commands \n{}", e)
@ -127,4 +142,7 @@ fn main() {
if let Err(e) = models() {
panic!("Error when writing the models:\n{}", e)
}
if let Err(e) = database_helper() {
panic!("Error when writing the database_helper:\n{}", e)
}
}