diff --git a/src/main.rs b/src/main.rs index 42fe02a4..51f47744 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ mod error; mod lexing; mod parsing; mod sources; +mod pckp; fn main() { print!("\x1B[2J\x1B[1;1H"); diff --git a/src/pckp/create.rs b/src/pckp/create.rs new file mode 100644 index 00000000..fcb1e608 --- /dev/null +++ b/src/pckp/create.rs @@ -0,0 +1,40 @@ +use std::path::PathBuf; +use std::fs::{create_dir, write}; + +const PCKP_LIBRARIES_DIR: &str = "pckp_libraries"; +const VRSN_FILE: &str = ".vrsn"; + +macro_rules! create_function { + ($func_name:ident($pathbuf:expr, $create:expr $(=>($($opt:expr$(,)*)+))?, $iskind:ident, $typ:literal$(,)?)) => { + pub fn $func_name() -> PathBuf { + let output = $pathbuf; + match output.exists() { + true => { + if !output.$iskind() { panic!("🤨 `{:?}` isn't a {}", output, $typ) } + } + false => { + $create(&output $(,$($opt,)+)?).unwrap(); + } + } + output + } + }; +} + +create_function!( + create_pckp_dir( + PathBuf::from(PCKP_LIBRARIES_DIR), + create_dir, + is_dir, + "folder", + ) +); + +create_function!( + create_vrsn_file( + create_pckp_dir().join(VRSN_FILE), + write => (""), + is_file, + "file", + ) +); diff --git a/src/pckp/mod.rs b/src/pckp/mod.rs new file mode 100644 index 00000000..c5fb369c --- /dev/null +++ b/src/pckp/mod.rs @@ -0,0 +1 @@ +pub mod create;