-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
31 lines (24 loc) · 908 Bytes
/
run.py
File metadata and controls
31 lines (24 loc) · 908 Bytes
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
#!/usr/bin/env python3
"""Build web if needed, then start the HTTP server."""
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
DIST_INDEX = ROOT / "web" / "dist" / "index.html"
def main() -> int:
npm = "npm.cmd" if sys.platform == "win32" else "npm"
if not (ROOT / "server" / "node_modules").is_dir():
subprocess.run([npm, "install"], cwd=ROOT / "server", check=True)
if not DIST_INDEX.is_file():
subprocess.run([sys.executable, str(ROOT / "build.py")], cwd=ROOT, check=True)
env = {**os.environ}
if "PORT" not in env:
env["PORT"] = "3000"
cmd = [npm, "start"]
print(f"+ {' '.join(cmd)} (cwd={ROOT / 'server'})", flush=True)
subprocess.run(cmd, cwd=ROOT / "server", env=env, check=True)
return 0
if __name__ == "__main__":
raise SystemExit(main())