Files
musadaq-saas/scripts/aggregate_project.py

52 lines
2.3 KiB
Python

import os
def aggregate_project(root_dir, output_file, exclude_dirs=None, exclude_files=None, extensions=None):
if exclude_dirs is None:
exclude_dirs = {'.git', 'vendor', 'node_modules', 'storage', '.gemini', 'artifacts', 'brain', 'scratch'}
if exclude_files is None:
exclude_files = {'composer.lock', 'package-lock.json', 'aggregate_project.py', output_file}
if extensions is None:
extensions = {'.php', '.js', '.css', '.html', '.sql', '.json', '.md', '.py', '.env.example', '.xml', '.env'}
with open(output_file, 'w', encoding='utf-8') as f:
f.write("# مُصادَق — ملخص كود المشروع الكامل\n\n")
f.write("هذا الملف يحتوي على كافة ملفات المصدر للمشروع مجمعة لتسهيل المراجعة.\n\n")
for root, dirs, files in os.walk(root_dir):
# Exclude directories
dirs[:] = [d for d in dirs if d not in exclude_dirs]
for file in files:
if file in exclude_files:
continue
_, ext = os.path.splitext(file)
# Include specific files or extensions
if ext not in extensions and file not in {'.env', 'phpunit.xml'}:
continue
full_path = os.path.join(root, file)
rel_path = os.path.relpath(full_path, root_dir)
f.write(f"## الملف: `{rel_path}`\n\n")
# Determine language for markdown block
lang = ext.replace('.', '')
if lang == 'php': lang = 'php'
elif lang == 'js': lang = 'javascript'
elif lang == 'sql': lang = 'sql'
else: lang = ''
f.write(f"```{lang}\n")
try:
with open(full_path, 'r', encoding='utf-8') as src:
f.write(src.read())
except Exception as e:
f.write(f"// تعذر قراءة الملف: {str(e)}")
f.write("\n```\n\n")
f.write("---\n\n")
if __name__ == "__main__":
aggregate_project('.', 'musadaq_full_code.md')
print("تم تجميع الكود بنجاح في: musadaq_full_code.md")