2021-09-09 08:51:29 -08:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from jinja2 import Template
|
|
|
|
|
2022-01-09 07:15:23 +01:00
|
|
|
template = """// This Code is auto generated by gen_global_components.py
|
2021-09-09 08:51:29 -08:00
|
|
|
{% 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)
|