Last active
January 26, 2023 23:33
-
-
Save robert-king/3498065e5e973393341ffdc5961278f3 to your computer and use it in GitHub Desktop.
walk-dir-zod-rust-script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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