#!/usr/bin/env python3
"""Package a self-contained Laravel deployment without secrets or personal data."""
from pathlib import Path
import zipfile

root = Path(__file__).resolve().parents[1]
out = root.parent / 'deliverables' / 'star-management-group-laravel.zip'
out.parent.mkdir(exist_ok=True)
excluded_dirs = {'.git', 'node_modules', '.idea', '.vscode'}
excluded_files = {'.env', '.phpunit.result.cache', 'database.sqlite', 'research-notes.md'}
with zipfile.ZipFile(out, 'w', zipfile.ZIP_DEFLATED, compresslevel=6) as archive:
    for path in sorted(root.rglob('*')):
        if not path.is_file():
            continue
        rel = path.relative_to(root)
        if any(p in excluded_dirs for p in rel.parts) or path.name in excluded_files:
            continue
        if path.name.startswith('.env') and path.name != '.env.example':
            continue
        if str(rel).startswith(('storage/logs/', 'storage/framework/views/', 'storage/framework/sessions/', 'storage/framework/cache/')) and path.name != '.gitignore':
            continue
        if str(rel).startswith('bootstrap/cache/') and path.name != '.gitignore':
            continue
        # Include all Composer vendor files, even package development source; no local DB.
        archive.write(path, 'star-management-group/' + str(rel))
print(str(out))
print(f'{out.stat().st_size / 1024 / 1024:.1f} MiB')
