MesProFace / patch-workspace-base.py
Forge
fix: use separate Python script for vite base patch (Docker heredoc unsupported)
a45aec5
Raw
History Blame Contribute Delete
666 Bytes
#!/usr/bin/env python3
"""Patch vite.config.ts to set base: '/workspace/' for HF Spaces deployment."""
import sys
path = sys.argv[1] if len(sys.argv) > 1 else 'vite.config.ts'
with open(path, 'r') as f:
content = f.read()
needle = " return {"
replacement = " return {\n base: '/workspace/',"
if "base: '/workspace/'" in content:
print(f"Already patched: {path}")
sys.exit(0)
new_content = content.replace(needle, replacement, 1)
if new_content == content:
print(f"ERROR: Could not find '{needle}' in {path}", file=sys.stderr)
sys.exit(1)
with open(path, 'w') as f:
f.write(new_content)
print(f"Patched {path}: base=/workspace/")