refactor: frontend preparation script with error handling

- Added a check to ensure the script is run from the project root by verifying the existence of pyproject.toml.
- Implemented a safeguard against removing the TARGET directory if it is a symlink, raising an appropriate error message.
This commit is contained in:
2025-12-01 11:06:10 -06:00
parent 9b4b8fdfeb
commit c98131f76b

View File

@@ -1,10 +1,14 @@
#!/usr/bin/env python3
from pathlib import Path from pathlib import Path
import shutil import shutil
TARGET = Path("meshchatx") / "public" TARGET = Path("meshchatx") / "public"
if not Path("pyproject.toml").exists():
raise RuntimeError("Must run from project root")
if TARGET.exists(): if TARGET.exists():
if TARGET.is_symlink():
raise RuntimeError(f"{TARGET} is a symlink, refusing to remove")
shutil.rmtree(TARGET) shutil.rmtree(TARGET)
TARGET.mkdir(parents=True, exist_ok=True) TARGET.mkdir(parents=True, exist_ok=True)