From 69bb5ee44e86db59b9a3612debe71d4fe39be18e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Fri, 18 Mar 2022 13:21:38 +0100
Subject: [PATCH] misc: use scss for all css files (#62936)

---
 .gitignore                                    |  2 +
 MANIFEST.in                                   |  7 ++--
 debian/control                                |  2 +-
 setup.py                                      | 41 ++++++++++++++++++-
 .../manager/css/{style.css => style.scss}     |  0
 .../css/{user_import.css => user_import.scss} |  0
 .../css/{css-tabs.css => css-tabs.scss}       |  0
 .../css/{password.css => password.scss}       |  0
 .../authentic2/css/{style.css => style.scss}  |  0
 ...datetimepicker.css => datetimepicker.scss} |  0
 .../css/{fc.css => fc.scss}                   |  0
 .../css/{style.css => style.scss}             |  0
 12 files changed, 47 insertions(+), 5 deletions(-)
 rename src/authentic2/manager/static/authentic2/manager/css/{style.css => style.scss} (100%)
 rename src/authentic2/manager/static/authentic2/manager/css/{user_import.css => user_import.scss} (100%)
 rename src/authentic2/static/authentic2/css/{css-tabs.css => css-tabs.scss} (100%)
 rename src/authentic2/static/authentic2/css/{password.css => password.scss} (100%)
 rename src/authentic2/static/authentic2/css/{style.css => style.scss} (100%)
 rename src/authentic2/static/css/{datetimepicker.css => datetimepicker.scss} (100%)
 rename src/authentic2_auth_fc/static/authentic2_auth_fc/css/{fc.css => fc.scss} (100%)
 rename src/authentic2_idp_oidc/static/authentic2_idp_oidc/css/{style.css => style.scss} (100%)

diff --git a/.gitignore b/.gitignore
index 4173c1a8..79139bcb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,8 @@ authentic.egg-info
 local_settings.py
 log.log
 authentic2/locale/fr/LC_MESSAGES/django.mo
+*.css
+*.css.map
 local_settings.*
 *.egg-info
 *.mo
diff --git a/MANIFEST.in b/MANIFEST.in
index a19b3f34..3dd23bde 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -7,9 +7,10 @@ recursive-exclude tests_rbac *.pyc
 include tox.ini .coveragerc
 
 # static
-recursive-include src/authentic2/static *.css *.js *.ico *.gif *.png *.jpg
-recursive-include src/authentic2/manager/static *.css *.js *.png
-recursive-include src/authentic2_auth_fc/static/authentic2_auth_fc *.css *.js *.png *.svg
+recursive-include src/authentic2/static *.css *.scss *.js *.ico *.gif *.png *.jpg
+recursive-include src/authentic2/manager/static *.css *.scss *.js *.png
+recursive-include src/authentic2_auth_fc/static/authentic2_auth_fc *.css *.scss *.js *.png *.svg
+recursive-include src/authentic2_idp_oidc/static/authentic2_idp_oidc *.css *.scss *.js *.png *.svg
 
 # templates
 recursive-include src/authentic2/templates *.html *.txt *.xml
diff --git a/debian/control b/debian/control
index 0658c66f..921700b1 100644
--- a/debian/control
+++ b/debian/control
@@ -3,7 +3,7 @@ Section: python
 Priority: optional
 Maintainer: Benjamin Dauvergne <bdauvergne@entrouvert.com>
 Build-Depends-Indep: python3-all-dev
-Build-Depends: debhelper-compat (= 12), dh-python, python3-setuptools, python3-django
+Build-Depends: debhelper-compat (= 12), dh-python, python3-setuptools, python3-django, sassc
 Standards-Version: 3.9.6
 Homepage: http://dev.entrouvert.org/projects/authentic/
 
diff --git a/setup.py b/setup.py
index 6b66c4f7..f1c1ee2d 100755
--- a/setup.py
+++ b/setup.py
@@ -10,6 +10,8 @@ import subprocess
 import sys
 from distutils.cmd import Command
 from distutils.command.build import build as _build
+from distutils.errors import CompileError
+from distutils.spawn import find_executable
 
 from setuptools import find_packages, setup
 from setuptools.command.install_lib import install_lib as _install_lib
@@ -47,8 +49,44 @@ class compile_translations(Command):
             os.chdir(curdir)
 
 
+class compile_scss(Command):
+    description = 'compile scss files into css files'
+    user_options = []
+
+    def initialize_options(self):
+        pass
+
+    def finalize_options(self):
+        pass
+
+    def run(self):
+        sass_bin = None
+        for program in ('sassc', 'sass'):
+            sass_bin = find_executable(program)
+            if sass_bin:
+                break
+        if not sass_bin:
+            raise CompileError(
+                'A sass compiler is required but none was found.  See sass-lang.com for choices.'
+            )
+
+        for path, dirnames, filenames in os.walk('src'):
+            for filename in filenames:
+                if not filename.endswith('.scss'):
+                    continue
+                if filename.startswith('_'):
+                    continue
+                subprocess.check_call(
+                    [
+                        sass_bin,
+                        '%s/%s' % (path, filename),
+                        '%s/%s' % (path, filename.replace('.scss', '.css')),
+                    ]
+                )
+
+
 class build(_build):
-    sub_commands = [('compile_translations', None)] + _build.sub_commands
+    sub_commands = [('compile_translations', None), ('compile_scss', None)] + _build.sub_commands
 
 
 class sdist(_sdist):
@@ -166,6 +204,7 @@ setup(
     cmdclass={
         'build': build,
         'install_lib': install_lib,
+        'compile_scss': compile_scss,
         'compile_translations': compile_translations,
         'sdist': sdist,
     },
diff --git a/src/authentic2/manager/static/authentic2/manager/css/style.css b/src/authentic2/manager/static/authentic2/manager/css/style.scss
similarity index 100%
rename from src/authentic2/manager/static/authentic2/manager/css/style.css
rename to src/authentic2/manager/static/authentic2/manager/css/style.scss
diff --git a/src/authentic2/manager/static/authentic2/manager/css/user_import.css b/src/authentic2/manager/static/authentic2/manager/css/user_import.scss
similarity index 100%
rename from src/authentic2/manager/static/authentic2/manager/css/user_import.css
rename to src/authentic2/manager/static/authentic2/manager/css/user_import.scss
diff --git a/src/authentic2/static/authentic2/css/css-tabs.css b/src/authentic2/static/authentic2/css/css-tabs.scss
similarity index 100%
rename from src/authentic2/static/authentic2/css/css-tabs.css
rename to src/authentic2/static/authentic2/css/css-tabs.scss
diff --git a/src/authentic2/static/authentic2/css/password.css b/src/authentic2/static/authentic2/css/password.scss
similarity index 100%
rename from src/authentic2/static/authentic2/css/password.css
rename to src/authentic2/static/authentic2/css/password.scss
diff --git a/src/authentic2/static/authentic2/css/style.css b/src/authentic2/static/authentic2/css/style.scss
similarity index 100%
rename from src/authentic2/static/authentic2/css/style.css
rename to src/authentic2/static/authentic2/css/style.scss
diff --git a/src/authentic2/static/css/datetimepicker.css b/src/authentic2/static/css/datetimepicker.scss
similarity index 100%
rename from src/authentic2/static/css/datetimepicker.css
rename to src/authentic2/static/css/datetimepicker.scss
diff --git a/src/authentic2_auth_fc/static/authentic2_auth_fc/css/fc.css b/src/authentic2_auth_fc/static/authentic2_auth_fc/css/fc.scss
similarity index 100%
rename from src/authentic2_auth_fc/static/authentic2_auth_fc/css/fc.css
rename to src/authentic2_auth_fc/static/authentic2_auth_fc/css/fc.scss
diff --git a/src/authentic2_idp_oidc/static/authentic2_idp_oidc/css/style.css b/src/authentic2_idp_oidc/static/authentic2_idp_oidc/css/style.scss
similarity index 100%
rename from src/authentic2_idp_oidc/static/authentic2_idp_oidc/css/style.css
rename to src/authentic2_idp_oidc/static/authentic2_idp_oidc/css/style.scss
-- 
2.35.1

