| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import os
- import json
- base_dir = r"E:\workDir\web-ui"
- output_file = r"e:\workDir\webapp\web_ui_info.json"
- print(f"⏳ 正在扫描前端项目 {base_dir} ...")
- def scan_dir(path, max_depth=3, current_depth=0):
- if current_depth > max_depth:
- return {}
- res = {}
- try:
- for item in os.listdir(path):
- if item in ["node_modules", ".git", ".next", "dist", "build"]:
- continue
- item_path = os.path.join(path, item)
- if os.path.isdir(item_path):
- res[item] = scan_dir(item_path, max_depth, current_depth + 1)
- else:
- res[item] = "file"
- except Exception as e:
- res["_error"] = str(e)
- return res
- info = {
- "tree": scan_dir(base_dir),
- "package_json": None,
- "routes": None
- }
- pkg_path = os.path.join(base_dir, "package.json")
- if os.path.exists(pkg_path):
- with open(pkg_path, "r", encoding="utf-8") as f:
- try:
- info["package_json"] = json.load(f)
- except Exception:
- info["package_json"] = f.read()
- with open(output_file, "w", encoding="utf-8") as f:
- json.dump(info, f, ensure_ascii=False, indent=2)
- print(f"✅ 扫描完成,结果已保存至 {output_file}")
|