Compile openapi client in background when django runserver is reloading

This commit is contained in:
2025-03-05 11:20:27 +01:00
parent 98175e397c
commit 05edf33062
4 changed files with 23 additions and 9 deletions

View File

@ -95,7 +95,7 @@ class JSBundler:
def compile():
"""Bundle js files with the javascript bundler for production."""
process = subprocess.Popen(["npm", "run", "compile"])
process.wait()
_ = process.wait()
if process.returncode:
raise RuntimeError(f"Bundler failed with returncode {process.returncode}")
@ -163,7 +163,7 @@ class OpenApi:
OPENAPI_DIR = GENERATED_ROOT / "openapi"
@classmethod
def compile(cls):
def compile(cls) -> subprocess.Popen[bytes] | None:
"""Compile a TS client for the sith API. Only generates it if it changed."""
logging.getLogger("django").info("Compiling open api typescript client")
out = cls.OPENAPI_DIR / "schema.json"
@ -191,4 +191,4 @@ class OpenApi:
with open(out, "w") as f:
_ = f.write(schema)
subprocess.run(["npx", "openapi-ts"], check=True)
return subprocess.Popen(["npm", "run", "openapi"])