ui0_components/
lib.rs

1use proc_macro::TokenStream;
2use quote::quote;
3use std::fs;
4
5#[proc_macro]
6pub fn load(_item: proc_macro::TokenStream) -> proc_macro::TokenStream {
7    let mut components = Vec::new();
8
9    if let Ok(entries) = fs::read_dir("./components") {
10        for entry in entries {
11            if let Ok(entry) = entry {
12                let path = entry.path();
13                if path.is_file() {
14                    if let Some(name) = path.file_name() {
15                        if let Some(name) = name.to_str() {
16                            println!("{}", name);
17                            if name.ends_with(".jsx") {
18                                if let Ok(content) = fs::read_to_string(&path) {
19                                    components.push((name.to_string(), content));
20                                }
21                            }
22                        }
23                    }
24                }
25            }
26        }
27    }
28
29    let component_array = components.iter().map(|(name, content)| {
30        quote! {
31            (#name, #content)
32        }
33    });
34
35    let expanded = quote! {
36        &[#(#component_array),*]
37    };
38
39    TokenStream::from(expanded)
40}