-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathvendor_app_stuff.py
More file actions
40 lines (32 loc) · 1.17 KB
/
vendor_app_stuff.py
File metadata and controls
40 lines (32 loc) · 1.17 KB
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
import pathlib
import shutil
import requests
STUFF = {
"htmx.org@2.0.8": ["dist/htmx.min.js"],
"htmx-ext-response-targets@2.0.4": ["dist/response-targets.min.js"],
"bootstrap@5.3.8": [
"dist/css/bootstrap.min.css",
"dist/js/bootstrap.bundle.min.js",
],
"bootstrap-icons@1.13.1": [
"font/bootstrap-icons.min.css",
"font/fonts/bootstrap-icons.woff",
"font/fonts/bootstrap-icons.woff2",
],
}
self_path = pathlib.Path(__file__)
root_dir = self_path.parent.parent
vendor_dir = root_dir / "src/reader/_app/static/vendor"
url_fmt = "https://cdn.jsdelivr.net/npm/{package}/{path}"
shutil.rmtree(vendor_dir, ignore_errors=True)
vendor_dir.mkdir(parents=True)
(vendor_dir / "README").write_text(f"maintained by {self_path.name}")
for package, paths in STUFF.items():
for path in paths:
src = url_fmt.format(package=package, path=path)
response = requests.get(src)
response.raise_for_status()
dst = vendor_dir.joinpath(package, *pathlib.PosixPath(path).parts)
dst.parent.mkdir(parents=True, exist_ok=True)
dst.write_bytes(response.content)
print(f"{package} {path} done")