inspect_web_ui.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import os
  2. import json
  3. base_dir = r"E:\workDir\web-ui"
  4. output_file = r"e:\workDir\webapp\web_ui_info.json"
  5. print(f"⏳ 正在扫描前端项目 {base_dir} ...")
  6. def scan_dir(path, max_depth=3, current_depth=0):
  7. if current_depth > max_depth:
  8. return {}
  9. res = {}
  10. try:
  11. for item in os.listdir(path):
  12. if item in ["node_modules", ".git", ".next", "dist", "build"]:
  13. continue
  14. item_path = os.path.join(path, item)
  15. if os.path.isdir(item_path):
  16. res[item] = scan_dir(item_path, max_depth, current_depth + 1)
  17. else:
  18. res[item] = "file"
  19. except Exception as e:
  20. res["_error"] = str(e)
  21. return res
  22. info = {
  23. "tree": scan_dir(base_dir),
  24. "package_json": None,
  25. "routes": None
  26. }
  27. pkg_path = os.path.join(base_dir, "package.json")
  28. if os.path.exists(pkg_path):
  29. with open(pkg_path, "r", encoding="utf-8") as f:
  30. try:
  31. info["package_json"] = json.load(f)
  32. except Exception:
  33. info["package_json"] = f.read()
  34. with open(output_file, "w", encoding="utf-8") as f:
  35. json.dump(info, f, ensure_ascii=False, indent=2)
  36. print(f"✅ 扫描完成,结果已保存至 {output_file}")