import os import json # Define the root folder of your project PROJECT_ROOT = "dcc-viewer" # File extensions to include INCLUDE_EXTENSIONS = {".js", ".html", ".css"} # Folders to exclude EXCLUDE_FOLDERS = {"node_modules", "dist", ".git", ".idea", ".vite"} def scan_project(directory): project_data = {} for root, dirs, files in os.walk(directory): # Remove excluded folders from traversal dirs[:] = [d for d in dirs if d not in EXCLUDE_FOLDERS] for file in files: if any(file.endswith(ext) for ext in INCLUDE_EXTENSIONS): file_path = os.path.join(root, file) relative_path = os.path.relpath(file_path, directory) try: with open(file_path, "r", encoding="utf-8") as f: project_data[relative_path] = f.read() except Exception as e: print(f"Error reading {file_path}: {e}") return project_data # Run the scan and save as JSON if __name__ == "__main__": project_json = scan_project(PROJECT_ROOT) with open("project_snapshot.json", "w", encoding="utf-8") as json_file: json.dump(project_json, json_file, indent=4, ensure_ascii=False) print("✅ Project snapshot saved to project_snapshot.json")