#![allow(dead_code)]

use rinja::Template;
use tracing_subscriber::EnvFilter;

#[cfg(feature = "bbs")]
mod bbs;

#[cfg(feature = "ddd")]
mod ddd;

#[cfg(feature = "kh2")]
mod kh2;

#[cfg(feature = "kh3")]
mod kh3;

pub const VERSION: &str = env!("CARGO_PKG_VERSION");

#[derive(Template)]
#[template(path = "pages/index.html")]
struct IndexTemplate {}

fn main() {
	// Initialize tracing
	tracing_subscriber::fmt()
		.with_env_filter(EnvFilter::from_default_env())
		.event_format(tracing_subscriber::fmt::format().with_source_location(true))
		.init();

	tracing::info!("Generating the main menu template");
	let template = IndexTemplate {};

	std::fs::write("./out/index.html", template.render().unwrap()).unwrap();
	std::process::Command::new("cp")
		.args(["-r", "./assets", "./out"])
		.output()
		.unwrap();

	#[cfg(feature = "bbs")]
	bbs::init();

	#[cfg(feature = "ddd")]
	ddd::init();

	#[cfg(feature = "kh2")]
	kh2::init();

	#[cfg(feature = "kh3")]
	kh3::init();
}

fn create_file(dir: &str, file: &str, buf: String) -> std::io::Result<()> {
	std::fs::create_dir_all(dir)?;
	std::fs::write(format!("{}/{}.html", dir, file), buf)?;
	Ok(())
}
