use std::{collections::BTreeMap, fs, path::Path};
pub(crate) fn write_changeset(dir: &Path, file_name: &str, bump: &str, summary: &str) {
let changeset_dir = dir.join(".changeset");
fs::create_dir_all(&changeset_dir).unwrap();
fs::write(
changeset_dir.join(file_name),
format!("---\n\"ublacklist\": {bump}\n---\n\n{summary}\n"),
)
.unwrap();
}
pub(crate) fn dir_snapshot(dir: &Path) -> BTreeMap<String, Vec<u8>> {
fn walk(root: &Path, dir: &Path, files: &mut BTreeMap<String, Vec<u8>>) {
for entry in fs::read_dir(dir).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if entry.file_type().unwrap().is_dir() {
walk(root, &path, files);
} else {
files.insert(
path.strip_prefix(root)
.unwrap()
.to_string_lossy()
.into_owned(),
fs::read(&path).unwrap(),
);
}
}
}
let mut files = BTreeMap::new();
walk(dir, dir, &mut files);
files
}