32 lines
1 KiB
Python
32 lines
1 KiB
Python
from django.core.management.base import BaseCommand
|
|
from django.core.management import call_command
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Build and compress static assets for production"
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
"--force",
|
|
action="store_true",
|
|
help="Force compression even if files exist",
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
self.stdout.write("Building static assets...")
|
|
|
|
# Compress CSS and JS files
|
|
self.stdout.write("Compressing CSS and JavaScript...")
|
|
call_command(
|
|
"compress",
|
|
force=options.get("force", False),
|
|
verbosity=options.get("verbosity", 1),
|
|
)
|
|
|
|
# Collect all static files
|
|
self.stdout.write("Collecting static files...")
|
|
call_command(
|
|
"collectstatic", interactive=False, verbosity=options.get("verbosity", 1)
|
|
)
|
|
|
|
self.stdout.write(self.style.SUCCESS("Successfully built static assets"))
|