Commit e2f97cd1 authored by shadMod's avatar shadMod 💬

now build_scss takes all .scss files contained inside assets and build and...

now build_scss takes all .scss files contained inside assets and build and minify them with min.css extension
parent 29d7c44d
......@@ -20,7 +20,10 @@ import os
import click
import uitwww
from pathlib import Path
from fnmatch import fnmatch
from scss.compiler import compile_file
from htmlmin import minify
from .constants import UITWWW_DIR, BASE_DIR
from .utils import ReverseProxied, GunicornInstance
......@@ -101,7 +104,29 @@ def init(data, debug):
@cli.command("build_scss")
def build_scss():
"""Compile the scss file"""
print("Start to compile the scss file")
# init PATTERN and ROOT_SCSS
PATTERN = "*.scss"
ROOT_SCSS = os.path.join(BASE_DIR, "assets/scss")
print("Get all scss")
# init css_path
css_path = []
# get all files with relative path
for path, subdir, files in os.walk(ROOT_SCSS):
for name in files:
# check if filename contain PATTERN
if fnmatch(name, PATTERN):
val = os.path.join(path, name).split("scss", 1)[1]
css_path.append(val.replace(".scss", ""))
print("Compile the scss file")
path = f"{BASE_DIR}/assets/scss/www.scss"
with open(f"{BASE_DIR}/uitwww/static/website.css", "w") as fn:
fn.write(compile_file(path))
for val in css_path:
# init path css
path = os.path.join(UITWWW_DIR, f"static/assets/{val}.min.css")
# check and mk dir if dir_ not exists
os.makedirs(os.path.dirname(path), exist_ok=True)
# open file, compile and write css
with open(path, "w") as fn:
fn.write(minify(compile_file(
Path(BASE_DIR, f"assets/scss{val}.scss")
)))
print("Write and populate css")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment