def handle(self, **options) -> None:
output_dir = options['output']
if output_dir is None:
output_dir = self._get_static_files_dir() / 'django_spire' / 'css'
django_spire_scss_source_path = self._get_django_spire_scss_source_path()
bundled_entry_file = django_spire_scss_source_path / '_theme.scss'
external_scss_source_path = self._get_static_files_dir()
external_entry_file = external_scss_source_path / 'django_spire' / 'scss' / '_theme.scss'
if not external_entry_file.exists():
external_scss_dir = external_entry_file.parent
external_scss_dir.mkdir(parents=True, exist_ok=True)
self.stdout.write(
f'No project "_theme.scss" file found. Creating {external_entry_file}'
)
shutil.copy2(bundled_entry_file, external_entry_file)
entry_file = external_entry_file
include_paths = [str(external_scss_source_path), str(django_spire_scss_source_path)]
self.stdout.write(f'Compiling SCSS from: {entry_file}')
output_dir.mkdir(parents=True, exist_ok=True)
try:
css_content = sass.compile(
filename=str(entry_file), output_style='expanded', include_paths=include_paths
)
except sass.CompileError as exc:
self.stderr.write(f'Sass compilation error: {exc}')
return
output_file = output_dir / 'django-spire-bootstrap.css'
output_file.write_bytes(css_content.encode('utf-8'))
self.stdout.write(self.style.SUCCESS(f'Compiled successfully: {output_file}'))