diff --git a/backend/src/main.rs b/backend/src/main.rs index 49b72a4..5db30d0 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -1,5 +1,7 @@ #[macro_use] mod macros; +mod generator; +mod utils; use std::convert::Infallible; use std::{env, fs}; @@ -11,12 +13,16 @@ use serde::{Deserialize, Serialize}; use path_clean::{clean}; use macros::StringExt; use crate::macros::PathExt; +use generator::*; + +extern crate pretty_env_logger; +#[macro_use] extern crate log; #[tokio::main] async fn main() { let cwd = env::current_dir().unwrap(); let addr = SocketAddr::from(([127, 0, 0, 1], 3029)); - println!("Serving {} started on http://127.0.0.1:3029", cwd.display()); + info!("Serving {} started on http://127.0.0.1:3029", cwd.display()); // A `Service` is needed for every connection, so this // creates one from our `hello_world` function. diff --git a/backend/src/utils.rs b/backend/src/utils.rs new file mode 100644 index 0000000..9bfedbd --- /dev/null +++ b/backend/src/utils.rs @@ -0,0 +1,11 @@ +use std::{fs, io}; +use std::path::{PathBuf}; + +pub fn write_sf>(path: &PathBuf, contents: C) -> io::Result<()> { + // Create parent if it has parent + if let Some(p) = path.parent() { + fs::create_dir_all(p)? + } + + fs::write(path, contents) +}