#!/usr/bin/env python3

import os
import json

ROOT = os.path.join(os.getcwd(), "assets")

result = {
    "css": [],
    "js": [],
    "images": [],
    "fonts": [],
    "templates": []
}

for root, dirs, files in os.walk(ROOT):

    rel = os.path.relpath(root, ROOT)

    if rel.startswith("templates"):
        if rel not in result["templates"]:
            result["templates"].append(rel)

    for file in files:

        path = os.path.join(root, file)
        relfile = os.path.relpath(path, ROOT)

        ext = os.path.splitext(file)[1].lower()

        if ext == ".css":
            result["css"].append(relfile)

        elif ext == ".js":
            result["js"].append(relfile)

        elif ext in [".png",".jpg",".jpeg",".gif",".svg",".webp"]:
            result["images"].append(relfile)

        elif ext in [".woff",".woff2",".ttf",".eot",".otf"]:
            result["fonts"].append(relfile)

with open("assets_report.json","w") as f:
    json.dump(result,f,indent=4)

print("="*60)
print("ASSETS SCANNER")
print("="*60)
print("Templates :",len(result["templates"]))
print("CSS       :",len(result["css"]))
print("JS        :",len(result["js"]))
print("Images    :",len(result["images"]))
print("Fonts     :",len(result["fonts"]))
print()
print("Rapport : assets_report.json")
