You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1005 B
37 lines
1005 B
#!/usr/bin/env python3 |
|
""" |
|
PlatformIO extra script to compress assets before building filesystem |
|
""" |
|
import subprocess |
|
import sys |
|
from pathlib import Path |
|
|
|
def before_buildfs(source, target, env): |
|
"""Hook called before building filesystem image.""" |
|
project_dir = Path(env.get("PROJECT_DIR")) |
|
data_dir = project_dir / "data" |
|
|
|
# Get the script path |
|
script_path = project_dir / "compress_assets.py" |
|
|
|
if not script_path.exists(): |
|
print(f"Warning: {script_path} not found") |
|
return |
|
|
|
print("\n" + "="*60) |
|
print("Compressing web assets (CSS, JS, HTML)...") |
|
print("="*60 + "\n") |
|
|
|
try: |
|
result = subprocess.run( |
|
[sys.executable, str(script_path), str(data_dir)], |
|
check=True, |
|
cwd=str(project_dir) |
|
) |
|
except subprocess.CalledProcessError as e: |
|
print(f"Error compressing assets: {e}") |
|
sys.exit(1) |
|
|
|
# Register the hook |
|
Import("env") |
|
env.AddPreAction("buildfs", before_buildfs)
|
|
|