92 lines
3.2 KiB
Python
92 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
===============================================================================
|
|
FILE: scripts/diagnostics/make_web_snapshot.py
|
|
ROLE: Динамическая автоматическая генерация слепка Web API, фронтенда и LLM.
|
|
Исключает временный кэш, авто-обнаруживает новые модули sidebar и роутеры.
|
|
===============================================================================
|
|
"""
|
|
|
|
import os
|
|
|
|
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
WEB_API_DIR = os.path.join(ROOT_DIR, "modules", "web_api")
|
|
OUTPUT_FILE = os.path.join(ROOT_DIR, "web_api_code_snapshot.md")
|
|
|
|
ALLOWED_EXTENSIONS = {
|
|
".py": "py",
|
|
".js": "js",
|
|
".html": "html",
|
|
".css": "css",
|
|
".json": "json"
|
|
}
|
|
|
|
IGNORE_DIRS = {
|
|
"__pycache__", ".git", "venv", ".venv", "uploads", "logs",
|
|
"node_modules", ".idea", ".vscode"
|
|
}
|
|
|
|
IGNORE_FILES = {
|
|
"web_api_code_snapshot.md",
|
|
"favicon.ico"
|
|
}
|
|
|
|
|
|
def collect_web_files():
|
|
"""Рекурсивно собирает все исходники web_api без необходимости хардкода."""
|
|
target_files = []
|
|
|
|
if not os.path.exists(WEB_API_DIR):
|
|
print(f"[❌] Директория не найдена: {WEB_API_DIR}")
|
|
return []
|
|
|
|
for root, dirs, files in os.walk(WEB_API_DIR):
|
|
# Исключаем служебные папки
|
|
dirs[:] = [d for d in dirs if d not in IGNORE_DIRS and not d.startswith(".")]
|
|
|
|
for file in sorted(files):
|
|
if file in IGNORE_FILES or file.startswith("."):
|
|
continue
|
|
|
|
_, ext = os.path.splitext(file)
|
|
if ext.lower() in ALLOWED_EXTENSIONS:
|
|
full_path = os.path.join(root, file)
|
|
|
|
# Пропускаем пустые __init__.py (0 байт)
|
|
if file == "__init__.py" and os.path.getsize(full_path) == 0:
|
|
continue
|
|
|
|
rel_path = os.path.relpath(full_path, ROOT_DIR)
|
|
target_files.append(rel_path)
|
|
|
|
return sorted(target_files)
|
|
|
|
|
|
def create_web_snapshot():
|
|
files_to_pack = collect_web_files()
|
|
content = ["# 🌐 WEB API & FRONTEND CODE SNAPSHOT (AUTO-DISCOVERY)\n"]
|
|
included_count = 0
|
|
|
|
for rel_path in files_to_pack:
|
|
full_path = os.path.join(ROOT_DIR, rel_path)
|
|
ext = os.path.splitext(rel_path)[1].lower()
|
|
lang = ALLOWED_EXTENSIONS.get(ext, "text")
|
|
|
|
try:
|
|
with open(full_path, "r", encoding="utf-8") as f:
|
|
file_text = f.read()
|
|
content.append(f"## File: `./{rel_path}`\n```{lang}\n{file_text}\n```\n")
|
|
included_count += 1
|
|
except Exception as e:
|
|
print(f"[⚠️] Ошибка чтения {rel_path}: {e}")
|
|
|
|
with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
|
|
f.write("\n".join(content))
|
|
|
|
size_kb = os.path.getsize(OUTPUT_FILE) / 1024
|
|
print(f"\n[✓] Web API + Фронтенд слепок успешно создан: {OUTPUT_FILE}")
|
|
print(f" Включено файлов: {included_count} | Размер: {size_kb:.1f} KB\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
create_web_snapshot() |