1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#!/usr/bin/env python
"""
Download htmx to django_htmx/static/htmx.min.js.
"""
from __future__ import annotations
import argparse
import subprocess
from pathlib import Path
static_dir = Path(__file__).parent.resolve() / "src/django_htmx/static/django_htmx/"
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("version", help="The version of htmx to download, e.g. 2.0.4")
args = parser.parse_args()
# Per: https://htmx.org/docs/#installing
download_file(
f"https://unpkg.com/htmx.org@{args.version}/dist/htmx.js",
static_dir / "htmx.js",
)
download_file(
f"https://unpkg.com/htmx.org@{args.version}/dist/htmx.min.js",
static_dir / "htmx.min.js",
)
print("✅")
return 0
def download_file(url: str, destination: Path) -> None:
print(f"{destination.name}...")
subprocess.run(
[
"curl",
"--fail",
"--location",
url,
"-o",
str(destination),
],
check=True,
)
if __name__ == "__main__":
raise SystemExit(main())
|