mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-30 17:53:31 -04:00 
			
		
		
		
	
		
			
	
	
		
			59 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
		
		
			
		
	
	
			59 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
|  | from pathlib import Path | ||
|  | 
 | ||
|  | from jinja2 import Template | ||
|  | 
 | ||
|  | template = """// This Code is auto generated by gen_global_componenets.py
 | ||
|  | {% for name in global %} import {{ name }} from "@/components/global/{{ name }}.vue"; | ||
|  | {% endfor %} | ||
|  | {% for name in layout %} import {{ name }} from "@/components/layout/{{ name }}.vue"; | ||
|  | {% endfor %} | ||
|  | 
 | ||
|  | declare module "vue" { | ||
|  |   export interface GlobalComponents { | ||
|  |     // Global Components | ||
|  |     {% for name in global %} {{ name }}: typeof {{ name }}; | ||
|  |     {% endfor %} // Layout Components | ||
|  |     {% for name in layout %} {{ name }}: typeof {{ name }}; | ||
|  |     {% endfor %} | ||
|  |   } | ||
|  | } | ||
|  | 
 | ||
|  | export {}; | ||
|  | """
 | ||
|  | 
 | ||
|  | project_dir = Path(__file__).parent.parent.parent | ||
|  | 
 | ||
|  | destination_file = project_dir / "frontend" / "types" / "components.d.ts" | ||
|  | 
 | ||
|  | component_paths = { | ||
|  |     "global": project_dir / "frontend" / "components" / "global", | ||
|  |     "layout": project_dir / "frontend" / "components" / "Layout", | ||
|  | } | ||
|  | 
 | ||
|  | 
 | ||
|  | def render_template(template: str, data: dict) -> None: | ||
|  |     template = Template(template) | ||
|  | 
 | ||
|  |     return template.render(**data) | ||
|  | 
 | ||
|  | 
 | ||
|  | def build_data(component_paths: dict) -> dict: | ||
|  |     data = {} | ||
|  |     for name, path in component_paths.items(): | ||
|  |         components = [] | ||
|  |         for component in path.glob("*.vue"): | ||
|  |             components.append(component.stem) | ||
|  |         data[name] = components | ||
|  | 
 | ||
|  |     return data | ||
|  | 
 | ||
|  | 
 | ||
|  | def write_template(text: str) -> None: | ||
|  |     destination_file.write_text(text) | ||
|  | 
 | ||
|  | 
 | ||
|  | if __name__ == "__main__": | ||
|  |     data = build_data(component_paths) | ||
|  |     text = render_template(template, build_data(component_paths)) | ||
|  |     write_template(text) |