33 lines
845 B
Python
Executable file
33 lines
845 B
Python
Executable file
#!/usr/bin/env python3
|
|
"""Minify CSS, JS, and HTML files in the deploy directory in-place."""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import minify_html
|
|
|
|
DEPLOY_DIR = Path("./deploy")
|
|
|
|
|
|
def minify_files():
|
|
for file in DEPLOY_DIR.rglob("*"):
|
|
if file.suffix not in {".html", ".css", ".js"}:
|
|
continue
|
|
content = file.read_text(encoding="utf-8")
|
|
minified = minify_html.minify(
|
|
content,
|
|
minify_js=True,
|
|
minify_css=True,
|
|
)
|
|
file.write_text(minified, encoding="utf-8")
|
|
print(f"{file.suffix.upper().rjust(5)}: {file}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if not DEPLOY_DIR.exists():
|
|
print(f"Error: deploy directory not found at {DEPLOY_DIR}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
print("Minifying assets...")
|
|
minify_files()
|
|
print("Done.")
|