2025-03-04 14:48:44 +01:00
|
|
|
import atexit
|
|
|
|
import os
|
|
|
|
|
|
|
|
from django.conf import settings
|
2024-09-17 23:42:05 +02:00
|
|
|
from django.contrib.staticfiles.management.commands.runserver import (
|
|
|
|
Command as Runserver,
|
|
|
|
)
|
2025-03-04 14:48:44 +01:00
|
|
|
from django.utils.autoreload import DJANGO_AUTORELOAD_ENV
|
2024-09-17 23:42:05 +02:00
|
|
|
|
2025-03-04 14:48:44 +01:00
|
|
|
from sith.composer import start_composer, stop_composer
|
2025-02-15 12:15:08 +01:00
|
|
|
from staticfiles.processors import OpenApi
|
2024-09-17 23:42:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Command(Runserver):
|
2024-11-18 15:36:05 +01:00
|
|
|
"""Light wrapper around default runserver that integrates javascirpt auto bundling."""
|
2024-09-17 23:42:05 +02:00
|
|
|
|
|
|
|
def run(self, **options):
|
2025-03-05 11:20:27 +01:00
|
|
|
is_django_reload = os.environ.get(DJANGO_AUTORELOAD_ENV) is not None
|
|
|
|
|
|
|
|
proc = OpenApi.compile()
|
|
|
|
# Ensure that the first runserver launch creates openapi files
|
|
|
|
# before the bundler starts so that it detects them
|
|
|
|
# When django is reloaded, we can keep this process in background
|
|
|
|
# to reduce reload time
|
|
|
|
if proc is not None and not is_django_reload:
|
|
|
|
_ = proc.wait()
|
|
|
|
|
|
|
|
if not is_django_reload and settings.PROCFILE_STATIC is not None:
|
2025-03-04 14:48:44 +01:00
|
|
|
start_composer(settings.PROCFILE_STATIC)
|
|
|
|
_ = atexit.register(stop_composer, procfile=settings.PROCFILE_STATIC)
|
2025-03-05 11:20:27 +01:00
|
|
|
|
2024-09-17 23:42:05 +02:00
|
|
|
super().run(**options)
|