Skip to content

Instantly share code, notes, and snippets.

@robert-king
Last active January 26, 2023 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robert-king/3498065e5e973393341ffdc5961278f3 to your computer and use it in GitHub Desktop.
Save robert-king/3498065e5e973393341ffdc5961278f3 to your computer and use it in GitHub Desktop.
walk-dir-zod-rust-script
// youtube: https://youtu.be/dbEY6j98llw
// twitter: https://twitter.com/robertkingNZ
use std::collections::HashMap;
use std::fs;
fn main() {
let mut map = HashMap::new();
let zod_location = "/Users/rk/WebstormProjects/thred-cloud/tauri/node_modules/zod";
use walkdir::WalkDir;
for entry in WalkDir::new(zod_location).into_iter().filter_map(|e| e.ok()) {
if entry.path().display().to_string().ends_with(".d.ts") {
let path = entry.path().display().to_string().replace("/Users/rk/WebstormProjects/thred-cloud/tauri/", "");
let path = "file:///".to_string() + path.as_str();
println!("{path}");
let contents = fs::read_to_string(entry.path()).expect("error reading file");
map.insert(path, contents);
}
}
let json_string = serde_json::to_string(&map).unwrap();
println!("{json_string}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment