2024-09-17 21:42:05 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
from django.contrib.staticfiles.management.commands.runserver import (
|
|
|
|
Command as Runserver,
|
|
|
|
)
|
|
|
|
from django.utils.autoreload import DJANGO_AUTORELOAD_ENV
|
|
|
|
|
2024-11-18 14:36:05 +00:00
|
|
|
from staticfiles.processors import JSBundler, OpenApi
|
2024-09-17 21:42:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Command(Runserver):
|
2024-11-18 14:36:05 +00:00
|
|
|
"""Light wrapper around default runserver that integrates javascirpt auto bundling."""
|
2024-09-17 21:42:05 +00:00
|
|
|
|
|
|
|
def run(self, **options):
|
2024-11-18 14:36:05 +00:00
|
|
|
# OpenApi generation needs to be before the bundler
|
2024-10-09 14:28:54 +00:00
|
|
|
OpenApi.compile()
|
2024-11-18 14:36:05 +00:00
|
|
|
# Only run the bundling server when debug is enabled
|
2024-09-17 21:42:05 +00:00
|
|
|
# Also protects from re-launching the server if django reloads it
|
|
|
|
if os.environ.get(DJANGO_AUTORELOAD_ENV) is None and settings.DEBUG:
|
2024-11-18 14:36:05 +00:00
|
|
|
with JSBundler.runserver():
|
2024-09-17 21:42:05 +00:00
|
|
|
super().run(**options)
|
|
|
|
return
|
|
|
|
super().run(**options)
|