File size: 1,171 Bytes
397ea3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python
"""Put the built site inside the package, so the wheel serves it.

`npm run build` writes `app/dist` — the pages, the hashed bundle and everything
in `app/public` (the meshes, the sounds, the stylesheets). Copied to
`arena/frontend/`, hatchling ships it as a build artefact and `arena serve` or
`workshop` finds it next to the code, wherever the package is installed. The
release workflow runs this; the Dockerfile does the same with a `COPY` of the
built dist to the same path. Nothing else writes that directory, and it is
never committed.

    uv run python scripts/bundle_frontend.py
"""

import shutil
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
DIST = ROOT / "app" / "dist"
TARGET = ROOT / "arena" / "frontend"


def bundle(dist: Path = DIST, target: Path = TARGET) -> Path:
    if not (dist / "index.html").is_file():
        print(f"{dist}: no index.html — run `npm run build` in app/ first", file=sys.stderr)
        sys.exit(2)
    if target.exists():
        shutil.rmtree(target)
    shutil.copytree(dist, target)
    return target


if __name__ == "__main__":
    print(f"bundled {bundle()}")