From 52d38ef4b7715c386a1d0ec07decf1c834ccade1 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Tue, 17 Jan 2023 15:58:14 -0500 Subject: [PATCH 01/20] refactor: build: reimplement `compile_sass` as a shell script TODO details Part of https://github.com/openedx/wg-developer-experience/issues/150 --- scripts/compile-sass.sh | 105 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 scripts/compile-sass.sh diff --git a/scripts/compile-sass.sh b/scripts/compile-sass.sh new file mode 100755 index 000000000000..7a691212533a --- /dev/null +++ b/scripts/compile-sass.sh @@ -0,0 +1,105 @@ +#!/bin/sh +# +# Compile sass files. +# +# Run this from the root of edx-platform, after ... TOOD +# but before ... TODO + +USAGE="\ +USAGE:\n\ + $0 [OPTIONS]\n\ +\n\ +OPTIONS:\n\ + -n, --node_modules Path to installed node_modules directory.\n\ + Defaults to ./node_modules.\n\ + --skip-lms Don't compile LMS-specific sass.\n\ + --skip-cms Don't compile CMS-specific sass.\n\ + -h, --help Display this.\n\ +" + +# By default, we look for node_modules in the current directory. +# Some Open edX distributions may want node_modules to be located somewhere +# else, so we let this be configured with -n|--node-modules. +NODE_MODULES_PATH="./node_modules" + +# Source direcotires for LMS and CMS. +SASS_LOOKUP_PATHS_LMS="\ +common/static \ +common/static/sass \ +$NODE_MODULES_PATH \ +$NODE_MODULES_PATH/@edx" + +SASS_LOOKUP_PATHS_CMS="\ +$SASS_LOOKUP_PATHS_LMS \ +lms/static/sass/partials" + +# Flags for LMS and CMS compliation. +# Nonempty string (-n) means True. +# Empty string (-z) means False. +COMPILE_LMS="true" +COMPILE_CMS="true" + +# Enable stricter sh behavior. +set -eu + +# Parse options. +while [ $# -gt 0 ]; do + case $1 in + -n|--node-modules) + shift + if [ $# -eq 0 ]; then + echo "Error: Missing value for -n/--node-modules" + echo "$USAGE" + exit 1 + fi + NODE_MODULES_PATH="$1" + shift + ;; + --skip-lms) + COMPILE_LMS="" + shift + ;; + --skip-cms) + COMPILE_CMS="" + shift + ;; + -h|--help) + echo "$USAGE" + exit 0 + ;; + *) + echo "Error: Unrecognized option: $1" + echo "$USAGE" + exit 1 + ;; + esac +done + +echo "-------------------------------------------------------------------------" +echo "Compiling sass..." +echo " Working directory : $(pwd)" +echo " SASS_LOOKUP_PATHS_LMS : $SASS_LOOKUP_PATHS_LMS" +echo " SASS_LOOKUP_PATHS_CMS : $SASS_LOOKUP_PATHS_CMS" +echo " COMPILE_LMS : ${COMPILE_LMS:-false}" +echo " COMPILE_CMS : ${COMPILE_CMS:-false}" +echo "-------------------------------------------------------------------------" + +# Input validation +for lookup_path in $SASS_LOOKUP_PATHS_CMS $SASS_LOOKUP_PATHS_LMS ; do + if ! [ -d "$lookup_path" ]; then + echo "Error: not a directory: $lookup_path" + exit 1 + fi +done + +# Echo lines back to user. +set -x + +echo TODO: implement + +# Stop echoing. +set +x + +echo "-------------------------------------------------------------------------" +echo "Done compiling sass." +echo "-------------------------------------------------------------------------" From 9128cf03cd4ad9c675bd294db9042f2cd9f3fa82 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Fri, 20 Jan 2023 15:44:38 -0500 Subject: [PATCH 02/20] squash: add sh command to paver; move sh into assets folder --- pavelib/assets.py | 9 +++++++++ scripts/{ => assets}/compile-sass.sh | 0 2 files changed, 9 insertions(+) rename scripts/{ => assets}/compile-sass.sh (100%) diff --git a/pavelib/assets.py b/pavelib/assets.py index ad933de19596..e2f721e27496 100644 --- a/pavelib/assets.py +++ b/pavelib/assets.py @@ -508,6 +508,15 @@ def _compile_sass(system, theme, debug, force, timing_info): :param force: boolean showing whether to remove existing css files before generating new files :param timing_info: list variable to keep track of timing for sass compilation """ + shell_command = ["/bin/sh", "scripts/assets/compile-sass.sh", system] + if force: + shell_command.append("--force") + if force: + shell_command.append("--debug") + if system != "common": + shell_command.append(theme) + sh(" ".join(shell_command)) + return True # Note: import sass only when it is needed and not at the top of the file. # This allows other paver commands to operate even without libsass being diff --git a/scripts/compile-sass.sh b/scripts/assets/compile-sass.sh similarity index 100% rename from scripts/compile-sass.sh rename to scripts/assets/compile-sass.sh From 6a93016b4e159cb18792140888f653d25642e788 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Fri, 20 Jan 2023 16:18:48 -0500 Subject: [PATCH 03/20] squash: more arguments for compile-sass.sh --- scripts/assets/compile-sass.sh | 124 +++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 38 deletions(-) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index 7a691212533a..e6638e538067 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -5,44 +5,45 @@ # Run this from the root of edx-platform, after ... TOOD # but before ... TODO +# Enable stricter sh behavior. +set -eu + USAGE="\ USAGE:\n\ - $0 [OPTIONS]\n\ + $0 [OPTIONS] common\n\ + $0 [OPTIONS] lms []\n\ + $0 [OPTIONS] cms []\n\ \n\ OPTIONS:\n\ -n, --node_modules Path to installed node_modules directory.\n\ Defaults to ./node_modules.\n\ - --skip-lms Don't compile LMS-specific sass.\n\ - --skip-cms Don't compile CMS-specific sass.\n\ + -f, --force Remove existing css before generating new css\n\ + -d, --debug Whether to show source comments in resulting css\n\ -h, --help Display this.\n\ " # By default, we look for node_modules in the current directory. # Some Open edX distributions may want node_modules to be located somewhere # else, so we let this be configured with -n|--node-modules. -NODE_MODULES_PATH="./node_modules" +node_modules_path="./node_modules" -# Source direcotires for LMS and CMS. -SASS_LOOKUP_PATHS_LMS="\ -common/static \ -common/static/sass \ -$NODE_MODULES_PATH \ -$NODE_MODULES_PATH/@edx" +# system can be: lms, cms, or common. +# theme_dir can be a path, or empty. +# If sytem="common", then theme_dir should be empty. +system="" +theme_dir="" -SASS_LOOKUP_PATHS_CMS="\ -$SASS_LOOKUP_PATHS_LMS \ -lms/static/sass/partials" +# Should we delete css first? Default is false. +# Empty string (-z) => false +# Nonempty string (-n) => true +force="" -# Flags for LMS and CMS compliation. -# Nonempty string (-n) means True. -# Empty string (-z) means False. -COMPILE_LMS="true" -COMPILE_CMS="true" +# Output style arguments, to be passed to underlying +# libsass complition command. +source_comments="False" +output_style="compressed" -# Enable stricter sh behavior. -set -eu - -# Parse options. +# Parse arguments and options. while [ $# -gt 0 ]; do case $1 in -n|--node-modules) @@ -52,46 +53,93 @@ while [ $# -gt 0 ]; do echo "$USAGE" exit 1 fi - NODE_MODULES_PATH="$1" + node_modules_path="$1" shift ;; - --skip-lms) - COMPILE_LMS="" + -f|--force) + source_comments="True" + output_style="nested" shift ;; - --skip-cms) - COMPILE_CMS="" + -d|--debug) + source_comments="True" + output_style="nested" shift ;; -h|--help) echo "$USAGE" exit 0 ;; - *) + -*) echo "Error: Unrecognized option: $1" echo "$USAGE" exit 1 ;; + *) # Positional arguments. Can be supplied before, after, or between options. + # First argument: system + if [ -z "$system" ] ; then + if [ "$1" = "lms" ] || [ "$1" = "cms" ] || [ "$1" = "common" ]; then + system="$1" + else + echo "Error: expected lms, cms, or common: $1" + echo "$USAGE" + exit 1 + fi + # Second argument: theme_dir + elif [ -z "$theme_dir" ] ; then + if [ "$system" = "common" ]; then + echo "Error: cannot provide a theme when compiling common scss" + echo "$USAGE" + exit 1 + fi + theme_dir="$1" + # Three or more arguments is an error. + else + echo "Error: unexpected argument: $1" + echo "$USAGE" + exit 1 + fi + shift + ;; esac done -echo "-------------------------------------------------------------------------" -echo "Compiling sass..." -echo " Working directory : $(pwd)" -echo " SASS_LOOKUP_PATHS_LMS : $SASS_LOOKUP_PATHS_LMS" -echo " SASS_LOOKUP_PATHS_CMS : $SASS_LOOKUP_PATHS_CMS" -echo " COMPILE_LMS : ${COMPILE_LMS:-false}" -echo " COMPILE_CMS : ${COMPILE_CMS:-false}" -echo "-------------------------------------------------------------------------" +# Define source directories for LMS and CMS. +sass_lookup_paths_common="\ + common/static\ + common/static/sass\ + $node_modules_path\ + $node_modules_path/@edx" +sass_lookup_paths_cms="$sass_lookup_paths_common" +sass_lookup_paths_lms="$sass_lookup_paths_common lms/static/sass/partials" # Input validation -for lookup_path in $SASS_LOOKUP_PATHS_CMS $SASS_LOOKUP_PATHS_LMS ; do +if [ -z "$system" ]; then + echo "Error: must specify lms, cms, or common." + echo "$USAGE" + exit 1 +fi +if [ -n "$theme_dir" ] && ! [ -d "$theme_dir" ]; then + echo "Error: provided theme directory is not a directory: $theme_dir" + echo "$USAGE" + exit 1 +fi +for lookup_path in $sass_lookup_paths_lms $sass_lookup_paths_cms; do if ! [ -d "$lookup_path" ]; then echo "Error: not a directory: $lookup_path" exit 1 fi done +echo "-------------------------------------------------------------------------" +echo "Compiling $system sass..." +echo " Working directory : $(pwd)" +echo " sass_lookup_paths_lms :$sass_lookup_paths_lms" +echo " sass_lookup_paths_cms :$sass_lookup_paths_cms" +echo " node_modules_path : $node_modules_path" +echo " theme_dir : $theme_dir" +echo "-------------------------------------------------------------------------" + # Echo lines back to user. set -x @@ -101,5 +149,5 @@ echo TODO: implement set +x echo "-------------------------------------------------------------------------" -echo "Done compiling sass." +echo "Done compiling $system sass." echo "-------------------------------------------------------------------------" From 458453569e3ec95859ecb781b34533a5e3942264 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Sun, 22 Jan 2023 16:11:24 -0500 Subject: [PATCH 04/20] squash: more flags, generalizing to watchers (wip) --- scripts/assets/compile-sass.sh | 37 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index e6638e538067..9780cf9a24d6 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -18,7 +18,8 @@ OPTIONS:\n\ -n, --node_modules Path to installed node_modules directory.\n\ Defaults to ./node_modules.\n\ -f, --force Remove existing css before generating new css\n\ - -d, --debug Whether to show source comments in resulting css\n\ + -d, --dev Dev mode: whether to show source comments in resulting css\n\ + -w, --watch Watch sass directories and compile and recompile whenever changed\n\ -h, --help Display this.\n\ " @@ -33,10 +34,11 @@ node_modules_path="./node_modules" system="" theme_dir="" -# Should we delete css first? Default is false. +# Flags. # Empty string (-z) => false # Nonempty string (-n) => true force="" +watch="" # Output style arguments, to be passed to underlying # libsass complition command. @@ -56,6 +58,10 @@ while [ $# -gt 0 ]; do node_modules_path="$1" shift ;; + -w|--watch) + watch="True" + shift + ;; -f|--force) source_comments="True" output_style="nested" @@ -105,13 +111,16 @@ while [ $# -gt 0 ]; do done # Define source directories for LMS and CMS. -sass_lookup_paths_common="\ - common/static\ +sass_lookup_paths_common=\ +"common/static\ common/static/sass\ $node_modules_path\ $node_modules_path/@edx" -sass_lookup_paths_cms="$sass_lookup_paths_common" -sass_lookup_paths_lms="$sass_lookup_paths_common lms/static/sass/partials" +sass_lookup_paths_lms=\" +"$sass_lookup_paths_common\ + lms/static/sass/partials" +sass_lookup_paths_cms=\ +"$sass_lookup_paths_common" # Input validation if [ -z "$system" ]; then @@ -131,8 +140,21 @@ for lookup_path in $sass_lookup_paths_lms $sass_lookup_paths_cms; do fi done +# TODO: This seems too complicated. +# TODO: just kidding, we can use sassc on the command line! +run_sass ( ) { + sass_src="$1" + css_dest="$2" + lookup_dirs="$3" + python -c "sass.compile(dirname=(\"$1\", \"$2\", +} + echo "-------------------------------------------------------------------------" -echo "Compiling $system sass..." +if [ -n "$watch" ] ; then + echo "Compiling $system sass..." +else + echo "Watching $system sass for changes..." +fi echo " Working directory : $(pwd)" echo " sass_lookup_paths_lms :$sass_lookup_paths_lms" echo " sass_lookup_paths_cms :$sass_lookup_paths_cms" @@ -143,6 +165,7 @@ echo "-------------------------------------------------------------------------" # Echo lines back to user. set -x + echo TODO: implement # Stop echoing. From 728d7e0be53b2b4b2be8734a58b8874fe9f090fa Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Tue, 24 Jan 2023 17:27:25 -0500 Subject: [PATCH 05/20] squash: use find+xargs+sassc; write most of the logic; passes shellcheck --- scripts/assets/compile-sass.sh | 152 ++++++++++++++++++++++++--------- 1 file changed, 110 insertions(+), 42 deletions(-) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index 9780cf9a24d6..6fbaa842824d 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -15,14 +15,21 @@ USAGE:\n\ $0 [OPTIONS] cms []\n\ \n\ OPTIONS:\n\ - -n, --node_modules Path to installed node_modules directory.\n\ + -n, --node-modules Path to installed node_modules directory.\n\ Defaults to ./node_modules.\n\ + -w, --watch Watch sass directories and compile and recompile whenever changed\n\ -f, --force Remove existing css before generating new css\n\ -d, --dev Dev mode: whether to show source comments in resulting css\n\ - -w, --watch Watch sass directories and compile and recompile whenever changed\n\ + --dry Dry run: don't do anything; just print what _would_ be done.\n\ -h, --help Display this.\n\ " +# Commands we use. +# In --dry mode, these are overriden to 'echo ' +rm='rm' +sassc='sassc' +rtlcss='rtlcss' + # By default, we look for node_modules in the current directory. # Some Open edX distributions may want node_modules to be located somewhere # else, so we let this be configured with -n|--node-modules. @@ -42,8 +49,7 @@ watch="" # Output style arguments, to be passed to underlying # libsass complition command. -source_comments="False" -output_style="compressed" +output_options="--style=compressed" # Parse arguments and options. while [ $# -gt 0 ]; do @@ -59,17 +65,21 @@ while [ $# -gt 0 ]; do shift ;; -w|--watch) - watch="True" + watch="T" shift ;; -f|--force) - source_comments="True" - output_style="nested" + force="T" shift ;; -d|--debug) - source_comments="True" - output_style="nested" + output_options="--style=nested --source-comments" + shift + ;; + --dry) + rm="echo rm" + sassc="echo sassc" + rtlcss="echo rtlcss" shift ;; -h|--help) @@ -110,17 +120,13 @@ while [ $# -gt 0 ]; do esac done -# Define source directories for LMS and CMS. -sass_lookup_paths_common=\ -"common/static\ - common/static/sass\ - $node_modules_path\ - $node_modules_path/@edx" -sass_lookup_paths_lms=\" -"$sass_lookup_paths_common\ - lms/static/sass/partials" -sass_lookup_paths_cms=\ -"$sass_lookup_paths_common" +# Sass import roots common to all Sass compliations. +common_include_paths=\ +"--include-path='common/static'\ + --include-path='common/static/sass'\ + --include-path='$node_modules_path'\ + --include-path='$node_modules_path/@edx'\ +" # Input validation if [ -z "$system" ]; then @@ -133,43 +139,105 @@ if [ -n "$theme_dir" ] && ! [ -d "$theme_dir" ]; then echo "$USAGE" exit 1 fi -for lookup_path in $sass_lookup_paths_lms $sass_lookup_paths_cms; do - if ! [ -d "$lookup_path" ]; then - echo "Error: not a directory: $lookup_path" - exit 1 - fi -done -# TODO: This seems too complicated. -# TODO: just kidding, we can use sassc on the command line! -run_sass ( ) { - sass_src="$1" +compile_dir ( ) { + scss_src="$1" css_dest="$2" - lookup_dirs="$3" - python -c "sass.compile(dirname=(\"$1\", \"$2\", -} + include_path_options="$3" + + # Echo lines back to user. + #set -x + + if [ -n "$force" ] ; then + $rm -f "$css_dest/*.css" + fi + # cd into sass_src and recursively print out relative paths + # to all files ending in '.scss' and NOT starting with '_'. + # For each file path, run sass. + # Use \0 (NUL) as a delimiter and {} as the path placeholder. + # Note that sassc's $..._options arguments are not quoted, + # because they may contain multiple arguments, which we want to + # split apart rather than passed as one big argument. + # Shellcheck is not a fan of this, so: + # shellcheck disable=2086 + (cd "$scss_src" && find . \( -name \*.scss -and \! -name _\* \) -print0) | \ + xargs -0 -I{} \ + $sassc $output_options $include_path_options "$scss_src"/{} "$css_dest"/{} + + # Stop echoing. + #set +x +} echo "-------------------------------------------------------------------------" if [ -n "$watch" ] ; then echo "Compiling $system sass..." + echo "ERROR: watching is not yet implemented" + exit 1 else echo "Watching $system sass for changes..." fi echo " Working directory : $(pwd)" -echo " sass_lookup_paths_lms :$sass_lookup_paths_lms" -echo " sass_lookup_paths_cms :$sass_lookup_paths_cms" -echo " node_modules_path : $node_modules_path" +echo " common_include_paths : $common_include_paths" echo " theme_dir : $theme_dir" echo "-------------------------------------------------------------------------" -# Echo lines back to user. -set -x - +system_include_paths=\ +"$common_include_paths\ + --include-path='$system/static/sass'\ + --include-path='$system/static/sass/partials'\ +" +theme_system_include_paths=\ +"$system_include_paths\ + --include-path='$theme_dir/$system/static/sass/partials'\ +" +theme_certificate_include_paths=\ +"$common_include_paths\ + --include-path='$theme_dir/lms/static/sass'\ + --include-path='$theme_dir/lms/static/sass/partials'\ +" -echo TODO: implement +if [ "$system" = "common" ] ; then + # Compile SCSS that is common to LMS+CMS and all themes. + compile_dir \ + "common/static/sass" \ + "common/static/css" \ + "$common_include_paths" +elif [ -n "$theme_dir" ] ; then + # Compile built-in SCSS into theme's CSS dir. + compile_dir \ + "$system/static/sass" \ + "$theme_dir/$system/static/css" \ + "$theme_system_include_paths" + # Now override some or all of the built-in CSS by compiling the + # theme's SCSS into its CSS dir. + compile_dir \ + "$theme_dir/$system/static/sass" \ + "$theme_dir/$system/static/css" \ + "$theme_system_include_paths" + if [ "$system" = "lms" ] ; then + # Finally, for LMS only, compile the theme's certificates + # SCSS into its certificates CSS dir. + compile_dir \ + "$theme_dir/lms/static/certificates/sass" \ + "$theme_dir/lms/static/certificates/css" \ + "$theme_certificate_include_paths" + fi +else + # Compile built-in SCSS into CSS dir. + compile_dir \ + "$system/static/sass" \ + "$system/static/css" \ + "$system_include_paths" + if [ "$system" = "lms" ] ; then + # For LMS only, compile built-in certificate SCSS. + compile_dir \ + "lms/static/certificates/sass" \ + "lms/static/certificates/css" \ + "$system_include_paths" + fi +fi -# Stop echoing. -set +x +echo TODO!!! rtlcss stuff. echo "$rtlcss" echo "-------------------------------------------------------------------------" echo "Done compiling $system sass." From 3b8f11a4dd8c5c411a3985b9ab9534d5d081e417 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Wed, 25 Jan 2023 00:00:57 -0500 Subject: [PATCH 06/20] squash: remove unused 'common' code paths --- scripts/assets/compile-sass.sh | 49 +++++++++++----------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index 6fbaa842824d..97412304f489 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -10,7 +10,6 @@ set -eu USAGE="\ USAGE:\n\ - $0 [OPTIONS] common\n\ $0 [OPTIONS] lms []\n\ $0 [OPTIONS] cms []\n\ \n\ @@ -35,9 +34,8 @@ rtlcss='rtlcss' # else, so we let this be configured with -n|--node-modules. node_modules_path="./node_modules" -# system can be: lms, cms, or common. -# theme_dir can be a path, or empty. -# If sytem="common", then theme_dir should be empty. +# system can be: lms or cms +# theme_dir can be: a path, or empty system="" theme_dir="" @@ -94,20 +92,15 @@ while [ $# -gt 0 ]; do *) # Positional arguments. Can be supplied before, after, or between options. # First argument: system if [ -z "$system" ] ; then - if [ "$1" = "lms" ] || [ "$1" = "cms" ] || [ "$1" = "common" ]; then + if [ "$1" = "lms" ] || [ "$1" = "cms" ] ; then system="$1" else - echo "Error: expected lms, cms, or common: $1" + echo "Error: expected 'lms' or 'cms' $1" echo "$USAGE" exit 1 fi # Second argument: theme_dir elif [ -z "$theme_dir" ] ; then - if [ "$system" = "common" ]; then - echo "Error: cannot provide a theme when compiling common scss" - echo "$USAGE" - exit 1 - fi theme_dir="$1" # Three or more arguments is an error. else @@ -120,17 +113,9 @@ while [ $# -gt 0 ]; do esac done -# Sass import roots common to all Sass compliations. -common_include_paths=\ -"--include-path='common/static'\ - --include-path='common/static/sass'\ - --include-path='$node_modules_path'\ - --include-path='$node_modules_path/@edx'\ -" - # Input validation if [ -z "$system" ]; then - echo "Error: must specify lms, cms, or common." + echo "Error: must specify 'lms' or 'cms'" echo "$USAGE" exit 1 fi @@ -146,7 +131,7 @@ compile_dir ( ) { include_path_options="$3" # Echo lines back to user. - #set -x + set -x if [ -n "$force" ] ; then $rm -f "$css_dest/*.css" @@ -166,21 +151,25 @@ compile_dir ( ) { $sassc $output_options $include_path_options "$scss_src"/{} "$css_dest"/{} # Stop echoing. - #set +x + set +x } echo "-------------------------------------------------------------------------" if [ -n "$watch" ] ; then - echo "Compiling $system sass..." + echo "Watching $system sass for changes..." echo "ERROR: watching is not yet implemented" exit 1 else - echo "Watching $system sass for changes..." + echo "Compiling $system sass..." fi echo " Working directory : $(pwd)" -echo " common_include_paths : $common_include_paths" -echo " theme_dir : $theme_dir" echo "-------------------------------------------------------------------------" +common_include_paths=\ +"--include-path='common/static'\ + --include-path='common/static/sass'\ + --include-path='$node_modules_path'\ + --include-path='$node_modules_path/@edx'\ +" system_include_paths=\ "$common_include_paths\ --include-path='$system/static/sass'\ @@ -196,13 +185,7 @@ theme_certificate_include_paths=\ --include-path='$theme_dir/lms/static/sass/partials'\ " -if [ "$system" = "common" ] ; then - # Compile SCSS that is common to LMS+CMS and all themes. - compile_dir \ - "common/static/sass" \ - "common/static/css" \ - "$common_include_paths" -elif [ -n "$theme_dir" ] ; then +if [ -n "$theme_dir" ] ; then # Compile built-in SCSS into theme's CSS dir. compile_dir \ "$system/static/sass" \ From 8b59c606832df06b4c188937a872ab058f80e93a Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Wed, 25 Jan 2023 00:18:36 -0500 Subject: [PATCH 07/20] squash: fix: no quotes around include-path --- scripts/assets/compile-sass.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index 97412304f489..d88a4caaad8c 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -165,24 +165,24 @@ echo " Working directory : $(pwd)" echo "-------------------------------------------------------------------------" common_include_paths=\ -"--include-path='common/static'\ - --include-path='common/static/sass'\ - --include-path='$node_modules_path'\ - --include-path='$node_modules_path/@edx'\ +"--include-path=common/static\ + --include-path=common/static/sass\ + --include-path=$node_modules_path\ + --include-path=$node_modules_path/@edx\ " system_include_paths=\ "$common_include_paths\ - --include-path='$system/static/sass'\ - --include-path='$system/static/sass/partials'\ + --include-path=$system/static/sass\ + --include-path=$system/static/sass/partials\ " theme_system_include_paths=\ "$system_include_paths\ - --include-path='$theme_dir/$system/static/sass/partials'\ + --include-path=$theme_dir/$system/static/sass/partials\ " theme_certificate_include_paths=\ "$common_include_paths\ - --include-path='$theme_dir/lms/static/sass'\ - --include-path='$theme_dir/lms/static/sass/partials'\ + --include-path=$theme_dir/lms/static/sass\ + --include-path=$theme_dir/lms/static/sass/partials\ " if [ -n "$theme_dir" ] ; then From 175157e1a571a5f3fa49cb59ccd8cb671f5b6451 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Wed, 25 Jan 2023 00:58:52 -0500 Subject: [PATCH 08/20] squash: rtl support (WIP) --- scripts/assets/compile-sass.sh | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index d88a4caaad8c..1a3fd8e3d900 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -130,9 +130,6 @@ compile_dir ( ) { css_dest="$2" include_path_options="$3" - # Echo lines back to user. - set -x - if [ -n "$force" ] ; then $rm -f "$css_dest/*.css" fi @@ -146,12 +143,24 @@ compile_dir ( ) { # split apart rather than passed as one big argument. # Shellcheck is not a fan of this, so: # shellcheck disable=2086 - (cd "$scss_src" && find . \( -name \*.scss -and \! -name _\* \) -print0) | \ - xargs -0 -I{} \ - $sassc $output_options $include_path_options "$scss_src"/{} "$css_dest"/{} - - # Stop echoing. - set +x + for relpath in $(cd "$scss_src" && find . \( -name \*.scss -and \! -name _\* \)) ; do + + # Compile one SCSS file into a CSS file. + $sassc $output_options $include_path_options "$scss_src/$relpath" "$css_dest/$relpath" + + # Generate converted RTL css too, if relevant. + reldir="$(dirname relpath)" + filename_no_ext="$(basename relpath | sed -n 's/.scss$//p')" + case "$filename_no_ext" in + *-rtl) + # SCSS is already RTL; no need to generate extra RTL file. + ;; + *) + # shellcheck disable=2086 + $rtlcss "$css_dest/$reldir/${filename_no_ext}.css" "$css_dest/$reldir/{$filename_no_ext}-rtl.css" + ;; + esac + done } echo "-------------------------------------------------------------------------" if [ -n "$watch" ] ; then @@ -220,7 +229,6 @@ else fi fi -echo TODO!!! rtlcss stuff. echo "$rtlcss" echo "-------------------------------------------------------------------------" echo "Done compiling $system sass." From cf0182c59ca3aaf0f61fcd49f3d7b2d1b5c8aef2 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Wed, 25 Jan 2023 09:37:00 -0500 Subject: [PATCH 09/20] squash: remove --source-comments so we can use libsass==0.10 --- scripts/assets/compile-sass.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index 1a3fd8e3d900..b9e8d91070b6 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -47,7 +47,7 @@ watch="" # Output style arguments, to be passed to underlying # libsass complition command. -output_options="--style=compressed" +output_options="--output-style=compressed" # Parse arguments and options. while [ $# -gt 0 ]; do @@ -71,7 +71,11 @@ while [ $# -gt 0 ]; do shift ;; -d|--debug) - output_options="--style=nested --source-comments" + output_options="--output-style=nested" + # TODO: When moving from `sass.compile(...)` to `sassc`, we had to drop + # the " --source-comments" option here because it is not available + # in libsass==0.10. After upgrading to libsass>=0.11, we should + # add back " --source-comments" here. shift ;; --dry) @@ -134,19 +138,18 @@ compile_dir ( ) { $rm -f "$css_dest/*.css" fi - # cd into sass_src and recursively print out relative paths - # to all files ending in '.scss' and NOT starting with '_'. - # For each file path, run sass. - # Use \0 (NUL) as a delimiter and {} as the path placeholder. - # Note that sassc's $..._options arguments are not quoted, - # because they may contain multiple arguments, which we want to - # split apart rather than passed as one big argument. - # Shellcheck is not a fan of this, so: - # shellcheck disable=2086 + # Navigate into sass_src and recursively print out relative paths for all SCSS + # files, excluding underscore-prefixed ones. for relpath in $(cd "$scss_src" && find . \( -name \*.scss -and \! -name _\* \)) ; do # Compile one SCSS file into a CSS file. + # Note that sassc's $..._options arguments are not quoted, because they + # may contain multiple arguments, which we want to split apart rather than + # pass as one big argument. Shellcheck is not a fan of this, so: + # shellcheck disable=2086 + set -x $sassc $output_options $include_path_options "$scss_src/$relpath" "$css_dest/$relpath" + set +x # Generate converted RTL css too, if relevant. reldir="$(dirname relpath)" @@ -157,7 +160,7 @@ compile_dir ( ) { ;; *) # shellcheck disable=2086 - $rtlcss "$css_dest/$reldir/${filename_no_ext}.css" "$css_dest/$reldir/{$filename_no_ext}-rtl.css" + echo TODO $rtlcss "$css_dest/$reldir/${filename_no_ext}.css" "$css_dest/$reldir/{$filename_no_ext}-rtl.css" ;; esac done @@ -183,6 +186,7 @@ system_include_paths=\ "$common_include_paths\ --include-path=$system/static/sass\ --include-path=$system/static/sass/partials\ + --include-path=lms/static/sass/partials\ " theme_system_include_paths=\ "$system_include_paths\ From ccaf14af4381937335530298233123c29e29376f Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Wed, 25 Jan 2023 12:33:06 -0500 Subject: [PATCH 10/20] squash: make script work on multiple themes + systems currently failing on the red-theme --- scripts/assets/compile-sass.sh | 237 +++++++++++++++++++-------------- 1 file changed, 137 insertions(+), 100 deletions(-) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index b9e8d91070b6..f2ef152a52aa 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -1,6 +1,5 @@ #!/bin/sh -# -# Compile sass files. +HELP="Compile SCSS files for LMS and CMS, including SCSS for zero or more themes." # # Run this from the root of edx-platform, after ... TOOD # but before ... TODO @@ -10,16 +9,19 @@ set -eu USAGE="\ USAGE:\n\ - $0 [OPTIONS] lms []\n\ - $0 [OPTIONS] cms []\n\ + $0 [OPTIONS]\n\ \n\ OPTIONS:\n\ + -t, --theme Path to a custom theme. Can be provided multiple times.\n\ -n, --node-modules Path to installed node_modules directory.\n\ Defaults to ./node_modules.\n\ - -w, --watch Watch sass directories and compile and recompile whenever changed\n\ + -w, --watch Watch SCSS directories and compile and recompile whenever changed\n\ + -L, --skip-lms Don't compile LMS-specific SCSS.\n\ + -C, --skip-cms Don't compile CMS-specific SCSS.\n\ + -D, --skip-default-theme Don't compile SCSS for the default theme.\n\ -f, --force Remove existing css before generating new css\n\ -d, --dev Dev mode: whether to show source comments in resulting css\n\ - --dry Dry run: don't do anything; just print what _would_ be done.\n\ + -r, --dry Dry run: don't do anything; just print what _would_ be done.\n\ -h, --help Display this.\n\ " @@ -27,23 +29,25 @@ OPTIONS:\n\ # In --dry mode, these are overriden to 'echo ' rm='rm' sassc='sassc' -rtlcss='rtlcss' +rtlcss='echo rtlcss' # TODO change # By default, we look for node_modules in the current directory. # Some Open edX distributions may want node_modules to be located somewhere # else, so we let this be configured with -n|--node-modules. node_modules_path="./node_modules" -# system can be: lms or cms -# theme_dir can be: a path, or empty -system="" -theme_dir="" +# List of paths to custom themes, newline-separated. +theme_paths="" # Flags. # Empty string (-z) => false # Nonempty string (-n) => true +skip_lms="" +skip_cms="" +skip_default_theme="" force="" watch="" +echo_script_lines="T" # Output style arguments, to be passed to underlying # libsass complition command. @@ -52,10 +56,22 @@ output_options="--output-style=compressed" # Parse arguments and options. while [ $# -gt 0 ]; do case $1 in + -t|--theme) + shift + if [ $# -eq 0 ] || [ ! -d "$1" ]; then + echo "Error: provided theme path is not a directory: ${1:-}" + echo + echo "$USAGE" + exit 1 + fi + theme_paths="$theme_paths\n$1" + shift + ;; -n|--node-modules) shift if [ $# -eq 0 ]; then echo "Error: Missing value for -n/--node-modules" + echo echo "$USAGE" exit 1 fi @@ -66,69 +82,52 @@ while [ $# -gt 0 ]; do watch="T" shift ;; + -L|--skip-lms) + skip_lms="T" + shift + ;; + -C|--skip-cms) + skip_cms="T" + shift + ;; + -D|--skip-default-theme) + skip_default_theme="T" + shift + ;; -f|--force) force="T" shift ;; - -d|--debug) + -d|--dev) output_options="--output-style=nested" - # TODO: When moving from `sass.compile(...)` to `sassc`, we had to drop - # the " --source-comments" option here because it is not available - # in libsass==0.10. After upgrading to libsass>=0.11, we should - # add back " --source-comments" here. + # TODO: When moving from `sass.compile(...)` to `sassc`, we had to stop using + # the " --source-comments" option because it is not available + # in the `sassc` CLI under libsass==0.10. After upgrading to libsass>=0.11, + # we should add back " --source-comments" when in --dev mode. shift ;; - --dry) + -r|-dry) rm="echo rm" sassc="echo sassc" rtlcss="echo rtlcss" + echo_script_lines="" shift ;; -h|--help) + echo "$HELP" + echo echo "$USAGE" exit 0 ;; - -*) + *) echo "Error: Unrecognized option: $1" + echo echo "$USAGE" exit 1 ;; - *) # Positional arguments. Can be supplied before, after, or between options. - # First argument: system - if [ -z "$system" ] ; then - if [ "$1" = "lms" ] || [ "$1" = "cms" ] ; then - system="$1" - else - echo "Error: expected 'lms' or 'cms' $1" - echo "$USAGE" - exit 1 - fi - # Second argument: theme_dir - elif [ -z "$theme_dir" ] ; then - theme_dir="$1" - # Three or more arguments is an error. - else - echo "Error: unexpected argument: $1" - echo "$USAGE" - exit 1 - fi - shift - ;; esac done -# Input validation -if [ -z "$system" ]; then - echo "Error: must specify 'lms' or 'cms'" - echo "$USAGE" - exit 1 -fi -if [ -n "$theme_dir" ] && ! [ -d "$theme_dir" ]; then - echo "Error: provided theme directory is not a directory: $theme_dir" - echo "$USAGE" - exit 1 -fi - compile_dir ( ) { scss_src="$1" css_dest="$2" @@ -138,40 +137,38 @@ compile_dir ( ) { $rm -f "$css_dest/*.css" fi - # Navigate into sass_src and recursively print out relative paths for all SCSS + # Navigate into scss_src and recursively print out relative paths for all SCSS # files, excluding underscore-prefixed ones. for relpath in $(cd "$scss_src" && find . \( -name \*.scss -and \! -name _\* \)) ; do # Compile one SCSS file into a CSS file. - # Note that sassc's $..._options arguments are not quoted, because they + # Note that scssc's $..._options arguments are not quoted, because they # may contain multiple arguments, which we want to split apart rather than - # pass as one big argument. Shellcheck is not a fan of this, so: - # shellcheck disable=2086 - set -x + # pass as one big argument. Hence the shellcheck disable directive. + # shellcheck disable=2086 $sassc $output_options $include_path_options "$scss_src/$relpath" "$css_dest/$relpath" - set +x # Generate converted RTL css too, if relevant. reldir="$(dirname relpath)" - filename_no_ext="$(basename relpath | sed -n 's/.scss$//p')" + filename_no_ext="$(basename "$relpath" | sed -n 's/.scss$//p')" case "$filename_no_ext" in *-rtl) # SCSS is already RTL; no need to generate extra RTL file. ;; *) # shellcheck disable=2086 - echo TODO $rtlcss "$css_dest/$reldir/${filename_no_ext}.css" "$css_dest/$reldir/{$filename_no_ext}-rtl.css" + $rtlcss "$css_dest/$reldir/$filename_no_ext.css" "$css_dest/$reldir/$filename_no_ext-rtl.css" ;; esac done } echo "-------------------------------------------------------------------------" if [ -n "$watch" ] ; then - echo "Watching $system sass for changes..." + echo "Watching SCSS for changes..." echo "ERROR: watching is not yet implemented" exit 1 else - echo "Compiling $system sass..." + echo "Compiling SCSS..." fi echo " Working directory : $(pwd)" echo "-------------------------------------------------------------------------" @@ -182,58 +179,98 @@ common_include_paths=\ --include-path=$node_modules_path\ --include-path=$node_modules_path/@edx\ " -system_include_paths=\ +lms_include_paths=\ "$common_include_paths\ - --include-path=$system/static/sass\ - --include-path=$system/static/sass/partials\ + --include-path=lms/static/sass\ --include-path=lms/static/sass/partials\ " -theme_system_include_paths=\ -"$system_include_paths\ - --include-path=$theme_dir/$system/static/sass/partials\ -" -theme_certificate_include_paths=\ +cms_include_paths=\ "$common_include_paths\ - --include-path=$theme_dir/lms/static/sass\ - --include-path=$theme_dir/lms/static/sass/partials\ + --include-path=cms/static/sass\ + --include-path=cms/static/sass/partials\ + --include-path=lms/static/sass/partials\ " -if [ -n "$theme_dir" ] ; then - # Compile built-in SCSS into theme's CSS dir. - compile_dir \ - "$system/static/sass" \ - "$theme_dir/$system/static/css" \ - "$theme_system_include_paths" - # Now override some or all of the built-in CSS by compiling the - # theme's SCSS into its CSS dir. - compile_dir \ - "$theme_dir/$system/static/sass" \ - "$theme_dir/$system/static/css" \ - "$theme_system_include_paths" - if [ "$system" = "lms" ] ; then - # Finally, for LMS only, compile the theme's certificates - # SCSS into its certificates CSS dir. +if [ -n "$echo_script_lines" ] ; then + set -x +fi + +if [ -z "$skip_default_theme" ] ; then + echo "Compiling SCSS for default theme..." + if [ -z "$skip_lms" ] ; then compile_dir \ - "$theme_dir/lms/static/certificates/sass" \ - "$theme_dir/lms/static/certificates/css" \ - "$theme_certificate_include_paths" - fi -else - # Compile built-in SCSS into CSS dir. - compile_dir \ - "$system/static/sass" \ - "$system/static/css" \ - "$system_include_paths" - if [ "$system" = "lms" ] ; then - # For LMS only, compile built-in certificate SCSS. + "lms/static/sass" \ + "lms/static/css" \ + "$lms_include_paths" compile_dir \ "lms/static/certificates/sass" \ "lms/static/certificates/css" \ - "$system_include_paths" + "$lms_include_paths" fi + if [ -z "$skip_cms" ] ; then + compile_dir \ + "cms/static/sass" \ + "cms/static/css" \ + "$cms_include_paths" + fi + echo "Default theme SCSS compiled." fi +echo "$theme_paths" | while read -r theme_path ; do + + if [ -z "$theme_path" ] ; then + continue + fi + + echo "Compiling SCSS for custom theme at $theme_path..." + + theme_lms_include_paths=\ +"$lms_include_paths\ + --include-path=$theme_path/lms/static/sass/partials\ +" + theme_certificate_include_paths=\ +"$common_include_paths\ + --include-path=$theme_path/lms/static/sass\ + --include-path=$theme_path/lms/static/sass/partials\ +" + theme_cms_include_paths=\ +"$cms_include_paths\ + --include-path=$theme_path/cms/static/sass/partials\ +" + if [ -z "$skip_lms" ] ; then + # First, compile default LMS SCSS into theme's LMS CSS dir. + compile_dir \ + "lms/static/sass" \ + "$theme_path/lms/static/css" \ + "$theme_lms_include_paths" + # Then, override some/all default LMS CSS by compiling theme's LMS SCSS. + compile_dir \ + "$theme_path/lms/static/sass" \ + "$theme_path/lms/static/css" \ + "$theme_lms_include_paths" + # Finally, compile the themed certificate SCSS into certificate CSS dir. + compile_dir \ + "$theme_path/lms/static/certificates/sass" \ + "$theme_path/lms/static/certificates/css" \ + "$theme_certificate_include_paths" + fi + if [ -z "$skip_cms" ] ; then + # Process for CMS is same as LMS, except no certificates. + compile_dir \ + "cms/static/sass" \ + "$theme_path/cms/static/css" \ + "$theme_cms_include_paths" + compile_dir \ + "$theme_path/cms/static/sass" \ + "$theme_path/cms/static/css" \ + "$theme_cms_include_paths" + fi + + echo "Done compiling SCSS for custom theme at $theme_path." +done + + echo "-------------------------------------------------------------------------" -echo "Done compiling $system sass." +echo "Done compiling SCSS." echo "-------------------------------------------------------------------------" From 9ac58f94fbd8719d36c7be9d4edcbfec8c779a5f Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Thu, 26 Jan 2023 11:02:53 -0500 Subject: [PATCH 11/20] squash: fix compile_dir logic --- scripts/assets/compile-sass.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index f2ef152a52aa..16b518cfe462 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -137,27 +137,33 @@ compile_dir ( ) { $rm -f "$css_dest/*.css" fi - # Navigate into scss_src and recursively print out relative paths for all SCSS - # files, excluding underscore-prefixed ones. - for relpath in $(cd "$scss_src" && find . \( -name \*.scss -and \! -name _\* \)) ; do + # Navigate into `scss_src` and recursively print out relative paths for all SCSS + # files, excluding underscore-prefixed ones, using `sed` to chop off the file extension. + # For each filepath, run `sassc` and, if appropriate, `rtlcss`. + # TODO: Unlike its Python API, libsass-python's CLI does not support compiling entire + # directories, so we must implement that logic ourselves. After we upgrade + # to node-sass or dart-sass, though, this logic might be able to be simplified. + for rel_path in $(cd "$scss_src" && find . \( -name \*.scss -and \! -name _\* \) | sed -n 's/.scss$//p') ; do + # Make sure the destination directory exists. + mkdir -p "$(dirname "$css_dest/$rel_path")" + # Compile one SCSS file into a CSS file. # Note that scssc's $..._options arguments are not quoted, because they # may contain multiple arguments, which we want to split apart rather than # pass as one big argument. Hence the shellcheck disable directive. # shellcheck disable=2086 - $sassc $output_options $include_path_options "$scss_src/$relpath" "$css_dest/$relpath" + $sassc $output_options $include_path_options "$scss_src/$rel_path.scss" "$css_dest/$rel_path.css" # Generate converted RTL css too, if relevant. - reldir="$(dirname relpath)" - filename_no_ext="$(basename "$relpath" | sed -n 's/.scss$//p')" - case "$filename_no_ext" in + case "$rel_path" in *-rtl) # SCSS is already RTL; no need to generate extra RTL file. ;; *) + # Generate RTL CSS from LTR CSS, appending -rtl to file name. # shellcheck disable=2086 - $rtlcss "$css_dest/$reldir/$filename_no_ext.css" "$css_dest/$reldir/$filename_no_ext-rtl.css" + $rtlcss "$css_dest/$rel_path.css" "$css_dest/$rel_path-rtl.css" ;; esac done From 6356865717683d4939023c6e4c5910d67946a258 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Thu, 26 Jan 2023 11:26:46 -0500 Subject: [PATCH 12/20] squash: improve output --- scripts/assets/compile-sass.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index 16b518cfe462..4275d6f4a4e1 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -22,6 +22,7 @@ OPTIONS:\n\ -f, --force Remove existing css before generating new css\n\ -d, --dev Dev mode: whether to show source comments in resulting css\n\ -r, --dry Dry run: don't do anything; just print what _would_ be done.\n\ + -v, --verbose Print commands as they are executed.\n\ -h, --help Display this.\n\ " @@ -47,7 +48,7 @@ skip_cms="" skip_default_theme="" force="" watch="" -echo_script_lines="T" +verbose="" # Output style arguments, to be passed to underlying # libsass complition command. @@ -110,7 +111,10 @@ while [ $# -gt 0 ]; do rm="echo rm" sassc="echo sassc" rtlcss="echo rtlcss" - echo_script_lines="" + shift + ;; + -v|--verbose) + verbose="T" shift ;; -h|--help) @@ -133,7 +137,14 @@ compile_dir ( ) { css_dest="$2" include_path_options="$3" + echo "Compiling: $scss_src -> $css_dest ..." + if [ ! -d "$scss_src" ] ; then + echo "Directory $scss_src does not exist; skipping." + return + fi + if [ -n "$force" ] ; then + echo " Removing old contents of $css_dest." $rm -f "$css_dest/*.css" fi @@ -167,6 +178,8 @@ compile_dir ( ) { ;; esac done + + echo " Compiled: $scss_src -> $css_dest." } echo "-------------------------------------------------------------------------" if [ -n "$watch" ] ; then @@ -197,7 +210,7 @@ cms_include_paths=\ --include-path=lms/static/sass/partials\ " -if [ -n "$echo_script_lines" ] ; then +if [ -n "$verbose" ] ; then set -x fi From 546e9630ded4f0c48b21efdf045aa4f1f2bfc6e8 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Thu, 26 Jan 2023 11:54:16 -0500 Subject: [PATCH 13/20] squash: more output improvements && rtlcss enable --- scripts/assets/compile-sass.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index 4275d6f4a4e1..0f2936dc5827 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -22,7 +22,7 @@ OPTIONS:\n\ -f, --force Remove existing css before generating new css\n\ -d, --dev Dev mode: whether to show source comments in resulting css\n\ -r, --dry Dry run: don't do anything; just print what _would_ be done.\n\ - -v, --verbose Print commands as they are executed.\n\ + -v, --verbose Print commands as they are executed.\n\ -h, --help Display this.\n\ " @@ -30,7 +30,7 @@ OPTIONS:\n\ # In --dry mode, these are overriden to 'echo ' rm='rm' sassc='sassc' -rtlcss='echo rtlcss' # TODO change +rtlcss='rtlcss' # By default, we look for node_modules in the current directory. # Some Open edX distributions may want node_modules to be located somewhere @@ -137,9 +137,9 @@ compile_dir ( ) { css_dest="$2" include_path_options="$3" - echo "Compiling: $scss_src -> $css_dest ..." + echo "Compiling directory: $scss_src -> $css_dest ..." if [ ! -d "$scss_src" ] ; then - echo "Directory $scss_src does not exist; skipping." + echo " Directory $scss_src does not exist; skipping." return fi @@ -179,7 +179,7 @@ compile_dir ( ) { esac done - echo " Compiled: $scss_src -> $css_dest." + echo " Compiled directory: $scss_src -> $css_dest." } echo "-------------------------------------------------------------------------" if [ -n "$watch" ] ; then From 6e005c94d795f5f1d47fb6d8fda18226952dc45a Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Thu, 26 Jan 2023 15:33:07 -0500 Subject: [PATCH 14/20] squash: extract dir compilation into script --- scripts/assets/compile-sass.sh | 193 ++++++++++++++--------------- scripts/assets/compile-scss-dir.sh | 122 ++++++++++++++++++ 2 files changed, 212 insertions(+), 103 deletions(-) create mode 100755 scripts/assets/compile-scss-dir.sh diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-sass.sh index 0f2936dc5827..102a4e39c670 100755 --- a/scripts/assets/compile-sass.sh +++ b/scripts/assets/compile-sass.sh @@ -12,51 +12,47 @@ USAGE:\n\ $0 [OPTIONS]\n\ \n\ OPTIONS:\n\ + -w, --watch Watch SCSS directories and compile and recompile whenever changed\n\ -t, --theme Path to a custom theme. Can be provided multiple times.\n\ - -n, --node-modules Path to installed node_modules directory.\n\ Defaults to ./node_modules.\n\ - -w, --watch Watch SCSS directories and compile and recompile whenever changed\n\ -L, --skip-lms Don't compile LMS-specific SCSS.\n\ -C, --skip-cms Don't compile CMS-specific SCSS.\n\ -D, --skip-default-theme Don't compile SCSS for the default theme.\n\ + -n, --node-modules Path to installed node_modules directory.\n\ -f, --force Remove existing css before generating new css\n\ - -d, --dev Dev mode: whether to show source comments in resulting css\n\ + -d, --dev Dev mode: Don't compress output CSS\n\ -r, --dry Dry run: don't do anything; just print what _would_ be done.\n\ -v, --verbose Print commands as they are executed.\n\ -h, --help Display this.\n\ " -# Commands we use. -# In --dry mode, these are overriden to 'echo ' -rm='rm' -sassc='sassc' -rtlcss='rtlcss' +# List of paths to custom themes, newline-separated. +theme_paths="" # By default, we look for node_modules in the current directory. # Some Open edX distributions may want node_modules to be located somewhere # else, so we let this be configured with -n|--node-modules. node_modules_path="./node_modules" -# List of paths to custom themes, newline-separated. -theme_paths="" - # Flags. # Empty string (-z) => false # Nonempty string (-n) => true +watch="" skip_lms="" skip_cms="" skip_default_theme="" force="" -watch="" +dev="" verbose="" - -# Output style arguments, to be passed to underlying -# libsass complition command. -output_options="--output-style=compressed" +dry="" # Parse arguments and options. while [ $# -gt 0 ]; do case $1 in + -w|--watch) + watch="T" + shift + ;; -t|--theme) shift if [ $# -eq 0 ] || [ ! -d "$1" ]; then @@ -68,21 +64,6 @@ while [ $# -gt 0 ]; do theme_paths="$theme_paths\n$1" shift ;; - -n|--node-modules) - shift - if [ $# -eq 0 ]; then - echo "Error: Missing value for -n/--node-modules" - echo - echo "$USAGE" - exit 1 - fi - node_modules_path="$1" - shift - ;; - -w|--watch) - watch="T" - shift - ;; -L|--skip-lms) skip_lms="T" shift @@ -95,28 +76,33 @@ while [ $# -gt 0 ]; do skip_default_theme="T" shift ;; + -n|--node-modules) + shift + if [ $# -eq 0 ]; then + echo "Error: Missing value for -n/--node-modules" + echo + echo "$USAGE" + exit 1 + fi + node_modules_path="$1" + shift + ;; -f|--force) force="T" shift ;; -d|--dev) - output_options="--output-style=nested" - # TODO: When moving from `sass.compile(...)` to `sassc`, we had to stop using - # the " --source-comments" option because it is not available - # in the `sassc` CLI under libsass==0.10. After upgrading to libsass>=0.11, - # we should add back " --source-comments" when in --dev mode. - shift - ;; - -r|-dry) - rm="echo rm" - sassc="echo sassc" - rtlcss="echo rtlcss" + dev="T" shift ;; -v|--verbose) verbose="T" shift ;; + -r|-dry) + dry="T" + shift + ;; -h|--help) echo "$HELP" echo @@ -132,60 +118,61 @@ while [ $# -gt 0 ]; do esac done -compile_dir ( ) { - scss_src="$1" - css_dest="$2" - include_path_options="$3" +compile_or_watch_dir ( ) { + + scss_src="$1" # Dir containing SCSS input files. + css_dest="$2" # Target dir for CSS output, to mirror input dir structure. + include_paths="$3" # List of SCSS import root paths, colon-separated. - echo "Compiling directory: $scss_src -> $css_dest ..." if [ ! -d "$scss_src" ] ; then - echo " Directory $scss_src does not exist; skipping." + echo "Directory $scss_src does not exist; skipping." return fi - if [ -n "$force" ] ; then - echo " Removing old contents of $css_dest." - $rm -f "$css_dest/*.css" + # TODO: This will fail if any of the paths have spaces in them, because such a path + # would be parsed as multiple arguments rather than one argument with a space + # inside it. + compile_scss_dir_command="/bin/sh scripts/assets/compile-scss-dir.sh $scss_src $css_dest $include_paths" + if [ -n "$dev" ] ; then + compile_scss_dir_command="$compile_scss_dir_command --dev" + fi + if [ -n "$verbose" ] ; then + compile_scss_dir_command="$compile_scss_dir_command --verbose" fi - # Navigate into `scss_src` and recursively print out relative paths for all SCSS - # files, excluding underscore-prefixed ones, using `sed` to chop off the file extension. - # For each filepath, run `sassc` and, if appropriate, `rtlcss`. - # TODO: Unlike its Python API, libsass-python's CLI does not support compiling entire - # directories, so we must implement that logic ourselves. After we upgrade - # to node-sass or dart-sass, though, this logic might be able to be simplified. - for rel_path in $(cd "$scss_src" && find . \( -name \*.scss -and \! -name _\* \) | sed -n 's/.scss$//p') ; do + if [ -n "$watch" ] ; then - # Make sure the destination directory exists. - mkdir -p "$(dirname "$css_dest/$rel_path")" - - # Compile one SCSS file into a CSS file. - # Note that scssc's $..._options arguments are not quoted, because they - # may contain multiple arguments, which we want to split apart rather than - # pass as one big argument. Hence the shellcheck disable directive. - # shellcheck disable=2086 - $sassc $output_options $include_path_options "$scss_src/$rel_path.scss" "$css_dest/$rel_path.css" + echo "Watching directories for compilation: $scss_src -> $css_dest ..." + [ -z "$dry" ] && + (echo "$scss_src" && echo "$css_dest" && (echo "$include_paths" | tr ':' '\n')) | \ + # TODO: watchmedo is part of the Python watchdog library. We should switch to something + # Python-free. + xargs \ + watchmedo shell-command \ + --patterns="*.scss" \ + --recursive \ + --command="/bin/sh scripts/assets/compile-scss-dir.sh $scss_src $css_dest $include_paths" + # TODO: The --command="..." above will split any paths with spaces in them into multiple + # arguments. This is difficult to resolve in POSIX shell. + echo "Watchers set up." - # Generate converted RTL css too, if relevant. - case "$rel_path" in - *-rtl) - # SCSS is already RTL; no need to generate extra RTL file. - ;; - *) - # Generate RTL CSS from LTR CSS, appending -rtl to file name. - # shellcheck disable=2086 - $rtlcss "$css_dest/$rel_path.css" "$css_dest/$rel_path-rtl.css" - ;; - esac - done + else - echo " Compiled directory: $scss_src -> $css_dest." + echo "Compiling directory: $scss_src -> $css_dest ..." + if [ -z "$watch" ] && [ -n "$force" ] ; then + echo " Removing old contents of $css_dest." + [ -z "$dry" ] && rm -f "$css_dest/*.css" + fi + # shellcheck disable=2086 + [ -z "$dry" ] && \ + $compile_scss_dir_command + echo " Compiled directory: $scss_src -> $css_dest." + + fi } echo "-------------------------------------------------------------------------" if [ -n "$watch" ] ; then echo "Watching SCSS for changes..." - echo "ERROR: watching is not yet implemented" - exit 1 else echo "Compiling SCSS..." fi @@ -193,21 +180,21 @@ echo " Working directory : $(pwd)" echo "-------------------------------------------------------------------------" common_include_paths=\ -"--include-path=common/static\ - --include-path=common/static/sass\ - --include-path=$node_modules_path\ - --include-path=$node_modules_path/@edx\ +"common/static\ +:common/static/sass\ +:$node_modules_path\ +:$node_modules_path/@edx\ " lms_include_paths=\ "$common_include_paths\ - --include-path=lms/static/sass\ - --include-path=lms/static/sass/partials\ +:lms/static/sass\ +:lms/static/sass/partials\ " cms_include_paths=\ "$common_include_paths\ - --include-path=cms/static/sass\ - --include-path=cms/static/sass/partials\ - --include-path=lms/static/sass/partials\ +:cms/static/sass\ +:cms/static/sass/partials\ +:lms/static/sass/partials\ " if [ -n "$verbose" ] ; then @@ -217,17 +204,17 @@ fi if [ -z "$skip_default_theme" ] ; then echo "Compiling SCSS for default theme..." if [ -z "$skip_lms" ] ; then - compile_dir \ + compile_or_watch_dir \ "lms/static/sass" \ "lms/static/css" \ "$lms_include_paths" - compile_dir \ + compile_or_watch_dir \ "lms/static/certificates/sass" \ "lms/static/certificates/css" \ "$lms_include_paths" fi if [ -z "$skip_cms" ] ; then - compile_dir \ + compile_or_watch_dir \ "cms/static/sass" \ "cms/static/css" \ "$cms_include_paths" @@ -245,41 +232,41 @@ echo "$theme_paths" | while read -r theme_path ; do theme_lms_include_paths=\ "$lms_include_paths\ - --include-path=$theme_path/lms/static/sass/partials\ +:$theme_path/lms/static/sass/partials\ " theme_certificate_include_paths=\ "$common_include_paths\ - --include-path=$theme_path/lms/static/sass\ - --include-path=$theme_path/lms/static/sass/partials\ +:$theme_path/lms/static/sass\ +:$theme_path/lms/static/sass/partials\ " theme_cms_include_paths=\ "$cms_include_paths\ - --include-path=$theme_path/cms/static/sass/partials\ +:$theme_path/cms/static/sass/partials\ " if [ -z "$skip_lms" ] ; then # First, compile default LMS SCSS into theme's LMS CSS dir. - compile_dir \ + compile_or_watch_dir \ "lms/static/sass" \ "$theme_path/lms/static/css" \ "$theme_lms_include_paths" # Then, override some/all default LMS CSS by compiling theme's LMS SCSS. - compile_dir \ + compile_or_watch_dir \ "$theme_path/lms/static/sass" \ "$theme_path/lms/static/css" \ "$theme_lms_include_paths" # Finally, compile the themed certificate SCSS into certificate CSS dir. - compile_dir \ + compile_or_watch_dir \ "$theme_path/lms/static/certificates/sass" \ "$theme_path/lms/static/certificates/css" \ "$theme_certificate_include_paths" fi if [ -z "$skip_cms" ] ; then # Process for CMS is same as LMS, except no certificates. - compile_dir \ + compile_or_watch_dir \ "cms/static/sass" \ "$theme_path/cms/static/css" \ "$theme_cms_include_paths" - compile_dir \ + compile_or_watch_dir \ "$theme_path/cms/static/sass" \ "$theme_path/cms/static/css" \ "$theme_cms_include_paths" diff --git a/scripts/assets/compile-scss-dir.sh b/scripts/assets/compile-scss-dir.sh new file mode 100755 index 000000000000..d0a8ccbb2f67 --- /dev/null +++ b/scripts/assets/compile-scss-dir.sh @@ -0,0 +1,122 @@ +#!/bin/sh +HELP="Recursively compile SCSS in one directory." + +# Enable stricter sh behavior. +set -eu + +USAGE="\ +USAGE:\n\ + $0 [OPTIONS] [] [OPTIONS]\n\ +\n\ +ARGUMENTS:\n\ + SCSS_SRC Source directory with SCSS\n\ + CSS_DEST Target directory for output CSS\n\ + INCLUDE_PATHS Colon-separated list of SCSS import roots\n\ +\n\ +OPTIONS:\n\ + -d, --dev Dev mode: don't compress output CSS\n\ + -h, --help Display this.\n\ + -v, --verbose Print commands as they are executed.\n\ +" + +scss_src="" +css_dest="" +include_paths="" +output_options="--output-style=compressed" + +# Flags. +# Empty string (-z) => false +# Nonempty string (-n) => true +verbose="" + +# Parse arguments and options. +while [ $# -gt 0 ]; do + case $1 in + -d|--dev) + output_options="--output-style=nested" + # TODO: When moving from `sass.compile(...)` to `sassc`, we had to stop using + # the " --source-comments" option because it is not available + # in the `sassc` CLI under libsass==0.10. After upgrading to libsass>=0.11, + # we should add back " --source-comments" when in --dev mode. + shift + ;; + -v|--verbose) + verbose="T" + shift + ;; + -h|--help) + echo "$HELP" + echo + echo "$USAGE" + exit 0 + ;; + -*) + echo "Error: Unrecognized option: $1" + echo + echo "$USAGE" + exit 1 + ;; + *) + if [ -z "$scss_src" ] ; then + scss_src="$1" + elif [ -z "$css_dest" ] ; then + css_dest="$1" + elif [ -z "$include_paths" ] ; then + include_paths="$1" + else + echo "Error: unexpected argument: $1" + echo "$USAGE" + exit 1 + fi + shift + ;; + esac +done + +if [ -n "$verbose" ] ; then + set -x +fi + +if [ -z "$scss_src" ] || [ -z "$css_dest" ] ; then + echo "Error: SCSS source dir and CSS destination dir are required." + echo "$USAGE" + exit 1 +fi + +# Convert include paths into string of options. +# Include paths are colon-separated, so we can replace the colons with ' --include-path=' +# and then prepend one more '--include_path=' to the entire string, if nonempty. +include_path_options="$(echo "$include_paths" | sed -n 's/:/ --include-path=/pg')" +if [ -n "$include_path_options" ] ; then + include_path_options="--include-path=$include_path_options" +fi + +# Navigate into `scss_src` and recursively print out relative paths for all SCSS +# files, excluding underscore-prefixed ones, using `sed` to chop off the file extension. +# For each filepath, run `sassc` and, if appropriate, `rtlcss`. +# TODO: Unlike its Python API, libsass-python's CLI does not support compiling entire +# directories, so we must implement that logic ourselves. After we upgrade +# to node-sass or dart-sass, though, this logic might be able to be simplified. +for rel_path in $(cd "$scss_src" && find . \( -name \*.scss -and \! -name _\* \) | sed -n 's/.scss$//p') ; do + + # Make sure the destination directory exists. + mkdir -p "$(dirname "$css_dest/$rel_path")" + + # Compile one SCSS file into a CSS file. + # Note that scssc's $..._options arguments are not quoted, because they + # may contain multiple arguments, which we want to split apart rather than + # pass as one big argument. Hence the shellcheck disable directive. + # shellcheck disable=2086 + sassc $output_options $include_path_options "$scss_src/$rel_path.scss" "$css_dest/$rel_path.css" + + # Generate converted RTL css too, if relevant. + case "$rel_path" in + *-rtl) + # SCSS is already RTL; no need to generate extra RTL file. + ;; + *) + # Generate RTL CSS from LTR CSS, appending -rtl to file name. + rtlcss "$css_dest/$rel_path.css" "$css_dest/$rel_path-rtl.css" + ;; + esac +done From ee2e87fe337d53de9047fc384f5943f0671b3962 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Thu, 26 Jan 2023 15:33:39 -0500 Subject: [PATCH 15/20] squash: compile-sass -> compile-scss --- scripts/assets/{compile-sass.sh => compile-scss.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/assets/{compile-sass.sh => compile-scss.sh} (100%) diff --git a/scripts/assets/compile-sass.sh b/scripts/assets/compile-scss.sh similarity index 100% rename from scripts/assets/compile-sass.sh rename to scripts/assets/compile-scss.sh From 21ffb657cc907a026842627a79cace4d43535895 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Thu, 26 Jan 2023 16:17:04 -0500 Subject: [PATCH 16/20] squash: work on output & watching --- scripts/assets/compile-scss.sh | 46 +++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/scripts/assets/compile-scss.sh b/scripts/assets/compile-scss.sh index 102a4e39c670..541309a17d3b 100755 --- a/scripts/assets/compile-scss.sh +++ b/scripts/assets/compile-scss.sh @@ -149,12 +149,10 @@ compile_or_watch_dir ( ) { # Python-free. xargs \ watchmedo shell-command \ - --patterns="*.scss" \ + --patterns=*.scss \ --recursive \ - --command="/bin/sh scripts/assets/compile-scss-dir.sh $scss_src $css_dest $include_paths" - # TODO: The --command="..." above will split any paths with spaces in them into multiple - # arguments. This is difficult to resolve in POSIX shell. - echo "Watchers set up." + "--command=$compile_scss_dir_command" & + echo " Watchers set up." else @@ -166,16 +164,21 @@ compile_or_watch_dir ( ) { # shellcheck disable=2086 [ -z "$dry" ] && \ $compile_scss_dir_command - echo " Compiled directory: $scss_src -> $css_dest." + echo " Done compiling: $scss_src -> $css_dest." fi } -echo "-------------------------------------------------------------------------" + +action="Compiling SCSS" +action_lower="compiling SCSS" if [ -n "$watch" ] ; then - echo "Watching SCSS for changes..." -else - echo "Compiling SCSS..." + action="Starting watchers for SCSS" + action_lower="starting watchers for SCSS" fi + +echo "-------------------------------------------------------------------------" +echo " $action..." +echo echo " Working directory : $(pwd)" echo "-------------------------------------------------------------------------" @@ -202,7 +205,7 @@ if [ -n "$verbose" ] ; then fi if [ -z "$skip_default_theme" ] ; then - echo "Compiling SCSS for default theme..." + echo "$action for default theme..." if [ -z "$skip_lms" ] ; then compile_or_watch_dir \ "lms/static/sass" \ @@ -219,7 +222,7 @@ if [ -z "$skip_default_theme" ] ; then "cms/static/css" \ "$cms_include_paths" fi - echo "Default theme SCSS compiled." + echo "Done $action_lower for default theme." fi echo "$theme_paths" | while read -r theme_path ; do @@ -228,7 +231,7 @@ echo "$theme_paths" | while read -r theme_path ; do continue fi - echo "Compiling SCSS for custom theme at $theme_path..." + echo "$action for custom theme at $theme_path..." theme_lms_include_paths=\ "$lms_include_paths\ @@ -272,11 +275,20 @@ echo "$theme_paths" | while read -r theme_path ; do "$theme_cms_include_paths" fi - echo "Done compiling SCSS for custom theme at $theme_path." + echo "Done $action_lower for custom theme at $theme_path." done - - echo "-------------------------------------------------------------------------" -echo "Done compiling SCSS." +echo " Done $action_lower." echo "-------------------------------------------------------------------------" + +if [ -n "$watch" ] ; then + # Kill all child processes (the SCSS watchers) upon exit. + #trap 'trap - TERM && kill -- -$$' INT TERM EXIT + trap "exit" INT TERM + trap "kill 0" EXIT + + echo "Use Ctrl+c to stop watchers." + sleep infinity +fi + From e02a4e58579cb397230d5af2058ccaf8454aebba Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Thu, 26 Jan 2023 18:44:52 -0500 Subject: [PATCH 17/20] squash: wip: updating pavelib/assets.py --- pavelib/assets.py | 177 ++++++++-------------------------------------- 1 file changed, 30 insertions(+), 147 deletions(-) diff --git a/pavelib/assets.py b/pavelib/assets.py index e2f721e27496..2e31f65b03ef 100644 --- a/pavelib/assets.py +++ b/pavelib/assets.py @@ -436,8 +436,6 @@ def compile_sass(options): '/edx/app/edxapp/edx-platform/themes' and '/edx/app/edxapp/edx-platform/common/test/'. """ - debug = options.get('debug') - force = options.get('force') systems = get_parsed_option(options, 'system', ALL_SYSTEMS) themes = get_parsed_option(options, 'themes', []) theme_dirs = get_parsed_option(options, 'theme_dirs', []) @@ -449,53 +447,20 @@ def compile_sass(options): if themes and theme_dirs: themes = get_theme_paths(themes=themes, theme_dirs=theme_dirs) - # Compile sass for OpenEdx theme after comprehensive themes - if None not in themes: - themes.append(None) - - timing_info = [] - dry_run = tasks.environment.dry_run - compilation_results = {'success': [], 'failure': []} - - print("\t\tStarted compiling Sass:") - - # compile common sass files - is_successful = _compile_sass('common', None, debug, force, timing_info) - if is_successful: - print("Finished compiling 'common' sass.") - compilation_results['success' if is_successful else 'failure'].append('"common" sass files.') - - for system in systems: - for theme in themes: - print("Started compiling '{system}' Sass for '{theme}'.".format(system=system, theme=theme or 'system')) - - # Compile sass files - is_successful = _compile_sass( - system=system, - theme=path(theme) if theme else None, - debug=debug, - force=force, - timing_info=timing_info - ) - - if is_successful: - print("Finished compiling '{system}' Sass for '{theme}'.".format( - system=system, theme=theme or 'system' - )) - - compilation_results['success' if is_successful else 'failure'].append('{system} sass for {theme}.'.format( - system=system, theme=theme or 'system', - )) - - print("\t\tFinished compiling Sass:") - if not dry_run: - for sass_dir, css_dir, duration in timing_info: - print(f">> {sass_dir} -> {css_dir} in {duration}s") - - if compilation_results['success']: - print("\033[92m\nSuccessful compilations:\n--- " + "\n--- ".join(compilation_results['success']) + "\n\033[00m") - if compilation_results['failure']: - print("\033[91m\nFailed compilations:\n--- " + "\n--- ".join(compilation_results['failure']) + "\n\033[00m") + command = ["scripts/assets/compile-scss.sh"] + for theme in themes: + command += ["--theme", path(theme)] + if "lms" not in systems: + command += ["--skip-lms"] + if "cms" not in systems: + command += ["--skip-cms"] + if options.get("debug"): + command += ["--dev"] + if options.get("force"): + command += ["--force"] + if tasks.environment.dry_run: + command += ["--dry"] + sh(" ".join(command)) def _compile_sass(system, theme, debug, force, timing_info): @@ -506,106 +471,24 @@ def _compile_sass(system, theme, debug, force, timing_info): :param theme: absolute path of the theme to compile sass for. :param debug: boolean showing whether to display source comments in resulted css :param force: boolean showing whether to remove existing css files before generating new files - :param timing_info: list variable to keep track of timing for sass compilation - """ - shell_command = ["/bin/sh", "scripts/assets/compile-sass.sh", system] - if force: - shell_command.append("--force") - if force: - shell_command.append("--debug") - if system != "common": - shell_command.append(theme) - sh(" ".join(shell_command)) - return True - - # Note: import sass only when it is needed and not at the top of the file. - # This allows other paver commands to operate even without libsass being - # installed. In particular, this allows the install_prereqs command to be - # used to install the dependency. - import sass - if system == "common": - sass_dirs = get_common_sass_directories() + :param timing_info: no longer supported; no effect. + """ + command = ["scripts/assets/compile-scss.sh"] + if system == "lms": + command += ["--skip-cms"] + elif system == "lms": + command += ["--skip-cms"] + elif system = "common": + pass # There is no longer any 'common' scss else: - sass_dirs = get_sass_directories(system, theme) - - dry_run = tasks.environment.dry_run - - # determine css out put style and source comments enabling + raise # TODO + if theme: + command += ["--theme", theme] if debug: - source_comments = True - output_style = 'nested' - else: - source_comments = False - output_style = 'compressed' - - for dirs in sass_dirs: - start = datetime.now() - css_dir = dirs['css_destination_dir'] - sass_source_dir = dirs['sass_source_dir'] - lookup_paths = dirs['lookup_paths'] - - if not sass_source_dir.isdir(): - print("\033[91m Sass dir '{dir}' does not exists, skipping sass compilation for '{theme}' \033[00m".format( - dir=sass_source_dir, theme=theme or system, - )) - # theme doesn't override sass directory, so skip it - continue - - if force: - if dry_run: - tasks.environment.info("rm -rf {css_dir}/*.css".format( - css_dir=css_dir, - )) - else: - sh(f"rm -rf {css_dir}/*.css") - - if dry_run: - tasks.environment.info("libsass {sass_dir}".format( - sass_dir=sass_source_dir, - )) - else: - sass.compile( - dirname=(sass_source_dir, css_dir), - include_paths=COMMON_LOOKUP_PATHS + lookup_paths, - source_comments=source_comments, - output_style=output_style, - ) - - # For Sass files without explicit RTL versions, generate - # an RTL version of the CSS using the rtlcss library. - for sass_file in glob.glob(sass_source_dir + '/**/*.scss'): - if should_generate_rtl_css_file(sass_file): - source_css_file = sass_file.replace(sass_source_dir, css_dir).replace('.scss', '.css') - target_css_file = source_css_file.replace('.css', '-rtl.css') - sh("rtlcss {source_file} {target_file}".format( - source_file=source_css_file, - target_file=target_css_file, - )) - - # Capture the time taken - if not dry_run: - duration = datetime.now() - start - timing_info.append((sass_source_dir, css_dir, duration)) - return True - - -def should_generate_rtl_css_file(sass_file): - """ - Returns true if a Sass file should have an RTL version generated. - """ - # Don't generate RTL CSS for partials - if path(sass_file).name.startswith('_'): - return False - - # Don't generate RTL CSS if the file is itself an RTL version - if sass_file.endswith('-rtl.scss'): - return False - - # Don't generate RTL CSS if there is an explicit Sass version for RTL - rtl_sass_file = path(sass_file.replace('.scss', '-rtl.scss')) - if rtl_sass_file.exists(): - return False - + command += ["--dev"] + if force: + command += ["--force"] + sh(" ".join(command)) return True From 760f9b3ea4fbb28797cadd87aea23f1af9ccdfda Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Thu, 26 Jan 2023 20:38:17 -0500 Subject: [PATCH 18/20] squash: make pavelib/assets wrapper more concise --- pavelib/assets.py | 50 +++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/pavelib/assets.py b/pavelib/assets.py index 2e31f65b03ef..7569d97baff3 100644 --- a/pavelib/assets.py +++ b/pavelib/assets.py @@ -447,49 +447,35 @@ def compile_sass(options): if themes and theme_dirs: themes = get_theme_paths(themes=themes, theme_dirs=theme_dirs) - command = ["scripts/assets/compile-scss.sh"] - for theme in themes: - command += ["--theme", path(theme)] - if "lms" not in systems: - command += ["--skip-lms"] - if "cms" not in systems: - command += ["--skip-cms"] - if options.get("debug"): - command += ["--dev"] - if options.get("force"): - command += ["--force"] - if tasks.environment.dry_run: - command += ["--dry"] - sh(" ".join(command)) + sh( + "scripts/assets/compile-scss.sh" + + ("".join(f" --theme {path(theme_dir)}" for theme in themes)) + + (" --skip-lms" if "lms" not in systems else "") + + (" --skip-cms" if "cms" not in systems else "") + + (" --dev" if options.get("debug") else "") + + (" --force" if options.get("force") else "") + + (" --dry" if tasks.environment.dry_run else "") + ) def _compile_sass(system, theme, debug, force, timing_info): """ Compile sass files for the given system and theme. - :param system: system to compile sass for e.g. 'lms', 'cms', 'common' + :param system: system to compile sass for: 'lms' or 'cms'; any other value is a no-op. :param theme: absolute path of the theme to compile sass for. :param debug: boolean showing whether to display source comments in resulted css :param force: boolean showing whether to remove existing css files before generating new files :param timing_info: no longer supported; no effect. """ - command = ["scripts/assets/compile-scss.sh"] - if system == "lms": - command += ["--skip-cms"] - elif system == "lms": - command += ["--skip-cms"] - elif system = "common": - pass # There is no longer any 'common' scss - else: - raise # TODO - if theme: - command += ["--theme", theme] - if debug: - command += ["--dev"] - if force: - command += ["--force"] - sh(" ".join(command)) - return True + sh( + "scripts/assets/compile-scss.sh" + + (f" --theme {theme} --skip-default-theme" if theme else "") + + (" --skip-lms" if system != "lms") + + (" --skip-cms" if system != "cms") + + (" --dev" if debug else "") + + (" --force" if force else "") + ) def process_npm_assets(): From b2ca4e4044be8ffb68e3c1a62fa08bdd6baa71b1 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Thu, 26 Jan 2023 20:59:27 -0500 Subject: [PATCH 19/20] squash: remove watch from compile-scss --- scripts/assets/compile-scss.sh | 87 +++++++++------------------------- 1 file changed, 23 insertions(+), 64 deletions(-) diff --git a/scripts/assets/compile-scss.sh b/scripts/assets/compile-scss.sh index 541309a17d3b..53b5ad234877 100755 --- a/scripts/assets/compile-scss.sh +++ b/scripts/assets/compile-scss.sh @@ -12,7 +12,6 @@ USAGE:\n\ $0 [OPTIONS]\n\ \n\ OPTIONS:\n\ - -w, --watch Watch SCSS directories and compile and recompile whenever changed\n\ -t, --theme Path to a custom theme. Can be provided multiple times.\n\ Defaults to ./node_modules.\n\ -L, --skip-lms Don't compile LMS-specific SCSS.\n\ @@ -37,7 +36,6 @@ node_modules_path="./node_modules" # Flags. # Empty string (-z) => false # Nonempty string (-n) => true -watch="" skip_lms="" skip_cms="" skip_default_theme="" @@ -49,10 +47,6 @@ dry="" # Parse arguments and options. while [ $# -gt 0 ]; do case $1 in - -w|--watch) - watch="T" - shift - ;; -t|--theme) shift if [ $# -eq 0 ] || [ ! -d "$1" ]; then @@ -118,7 +112,7 @@ while [ $# -gt 0 ]; do esac done -compile_or_watch_dir ( ) { +compile_dir ( ) { scss_src="$1" # Dir containing SCSS input files. css_dest="$2" # Target dir for CSS output, to mirror input dir structure. @@ -140,44 +134,19 @@ compile_or_watch_dir ( ) { compile_scss_dir_command="$compile_scss_dir_command --verbose" fi - if [ -n "$watch" ] ; then - - echo "Watching directories for compilation: $scss_src -> $css_dest ..." - [ -z "$dry" ] && - (echo "$scss_src" && echo "$css_dest" && (echo "$include_paths" | tr ':' '\n')) | \ - # TODO: watchmedo is part of the Python watchdog library. We should switch to something - # Python-free. - xargs \ - watchmedo shell-command \ - --patterns=*.scss \ - --recursive \ - "--command=$compile_scss_dir_command" & - echo " Watchers set up." - - else - - echo "Compiling directory: $scss_src -> $css_dest ..." - if [ -z "$watch" ] && [ -n "$force" ] ; then - echo " Removing old contents of $css_dest." - [ -z "$dry" ] && rm -f "$css_dest/*.css" - fi - # shellcheck disable=2086 - [ -z "$dry" ] && \ - $compile_scss_dir_command - echo " Done compiling: $scss_src -> $css_dest." - + echo "Compiling directory: $scss_src -> $css_dest ..." + if [ -n "$force" ] ; then + echo " Removing old contents of $css_dest." + [ -z "$dry" ] && rm -f "$css_dest/*.css" fi + # shellcheck disable=2086 + [ -z "$dry" ] && \ + $compile_scss_dir_command + echo " Done compiling: $scss_src -> $css_dest." } -action="Compiling SCSS" -action_lower="compiling SCSS" -if [ -n "$watch" ] ; then - action="Starting watchers for SCSS" - action_lower="starting watchers for SCSS" -fi - echo "-------------------------------------------------------------------------" -echo " $action..." +echo " Compiling SCSS..." echo echo " Working directory : $(pwd)" echo "-------------------------------------------------------------------------" @@ -205,24 +174,24 @@ if [ -n "$verbose" ] ; then fi if [ -z "$skip_default_theme" ] ; then - echo "$action for default theme..." + echo "Compiling SCSS for default theme..." if [ -z "$skip_lms" ] ; then - compile_or_watch_dir \ + compile_dir \ "lms/static/sass" \ "lms/static/css" \ "$lms_include_paths" - compile_or_watch_dir \ + compile_dir \ "lms/static/certificates/sass" \ "lms/static/certificates/css" \ "$lms_include_paths" fi if [ -z "$skip_cms" ] ; then - compile_or_watch_dir \ + compile_dir \ "cms/static/sass" \ "cms/static/css" \ "$cms_include_paths" fi - echo "Done $action_lower for default theme." + echo "Done compiling SCSS for default theme." fi echo "$theme_paths" | while read -r theme_path ; do @@ -231,7 +200,7 @@ echo "$theme_paths" | while read -r theme_path ; do continue fi - echo "$action for custom theme at $theme_path..." + echo "Compiling SCSS for custom theme at $theme_path..." theme_lms_include_paths=\ "$lms_include_paths\ @@ -248,47 +217,37 @@ echo "$theme_paths" | while read -r theme_path ; do " if [ -z "$skip_lms" ] ; then # First, compile default LMS SCSS into theme's LMS CSS dir. - compile_or_watch_dir \ + compile_dir \ "lms/static/sass" \ "$theme_path/lms/static/css" \ "$theme_lms_include_paths" # Then, override some/all default LMS CSS by compiling theme's LMS SCSS. - compile_or_watch_dir \ + compile_dir \ "$theme_path/lms/static/sass" \ "$theme_path/lms/static/css" \ "$theme_lms_include_paths" # Finally, compile the themed certificate SCSS into certificate CSS dir. - compile_or_watch_dir \ + compile_dir \ "$theme_path/lms/static/certificates/sass" \ "$theme_path/lms/static/certificates/css" \ "$theme_certificate_include_paths" fi if [ -z "$skip_cms" ] ; then # Process for CMS is same as LMS, except no certificates. - compile_or_watch_dir \ + compile_dir \ "cms/static/sass" \ "$theme_path/cms/static/css" \ "$theme_cms_include_paths" - compile_or_watch_dir \ + compile_dir \ "$theme_path/cms/static/sass" \ "$theme_path/cms/static/css" \ "$theme_cms_include_paths" fi - echo "Done $action_lower for custom theme at $theme_path." + echo "Done compiling SCSS for custom theme at $theme_path." done echo "-------------------------------------------------------------------------" -echo " Done $action_lower." +echo " Done compiling SCSS." echo "-------------------------------------------------------------------------" -if [ -n "$watch" ] ; then - # Kill all child processes (the SCSS watchers) upon exit. - #trap 'trap - TERM && kill -- -$$' INT TERM EXIT - trap "exit" INT TERM - trap "kill 0" EXIT - - echo "Use Ctrl+c to stop watchers." - sleep infinity -fi - From bf8281a2b742552234d133c06176b31882ee8fac Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Thu, 26 Jan 2023 23:05:48 -0500 Subject: [PATCH 20/20] squash: clean up scss scripts. I think they works? --- scripts/assets/compile-scss-dir.sh | 17 ++- scripts/assets/compile-scss.sh | 204 +++++++++++++---------------- 2 files changed, 108 insertions(+), 113 deletions(-) diff --git a/scripts/assets/compile-scss-dir.sh b/scripts/assets/compile-scss-dir.sh index d0a8ccbb2f67..6e029ee3d304 100755 --- a/scripts/assets/compile-scss-dir.sh +++ b/scripts/assets/compile-scss-dir.sh @@ -15,8 +15,9 @@ ARGUMENTS:\n\ \n\ OPTIONS:\n\ -d, --dev Dev mode: don't compress output CSS\n\ - -h, --help Display this.\n\ + -r, --dry Dry run: don't execute commands (pairs well with -v)\n\ -v, --verbose Print commands as they are executed.\n\ + -h, --help Display this.\n\ " scss_src="" @@ -28,6 +29,7 @@ output_options="--output-style=compressed" # Empty string (-z) => false # Nonempty string (-n) => true verbose="" +dry="" # Parse arguments and options. while [ $# -gt 0 ]; do @@ -44,6 +46,10 @@ while [ $# -gt 0 ]; do verbose="T" shift ;; + -r|--dry) + dry="T" + shift + ;; -h|--help) echo "$HELP" echo @@ -107,7 +113,12 @@ for rel_path in $(cd "$scss_src" && find . \( -name \*.scss -and \! -name _\* \) # may contain multiple arguments, which we want to split apart rather than # pass as one big argument. Hence the shellcheck disable directive. # shellcheck disable=2086 - sassc $output_options $include_path_options "$scss_src/$rel_path.scss" "$css_dest/$rel_path.css" + [ -n "$dry" ] || \ + sassc \ + $output_options \ + $include_path_options \ + "$scss_src/$rel_path.scss" \ + "$css_dest/$rel_path.css" # Generate converted RTL css too, if relevant. case "$rel_path" in @@ -116,7 +127,7 @@ for rel_path in $(cd "$scss_src" && find . \( -name \*.scss -and \! -name _\* \) ;; *) # Generate RTL CSS from LTR CSS, appending -rtl to file name. - rtlcss "$css_dest/$rel_path.css" "$css_dest/$rel_path-rtl.css" + [ -n "$dry" ] || rtlcss "$css_dest/$rel_path.css" "$css_dest/$rel_path-rtl.css" ;; esac done diff --git a/scripts/assets/compile-scss.sh b/scripts/assets/compile-scss.sh index 53b5ad234877..2ea44d3d8a70 100755 --- a/scripts/assets/compile-scss.sh +++ b/scripts/assets/compile-scss.sh @@ -1,5 +1,5 @@ #!/bin/sh -HELP="Compile SCSS files for LMS and CMS, including SCSS for zero or more themes." +HELP="Compile SCSS files for LMS and CMS, for default and/or custom themes." # # Run this from the root of edx-platform, after ... TOOD # but before ... TODO @@ -12,17 +12,17 @@ USAGE:\n\ $0 [OPTIONS]\n\ \n\ OPTIONS:\n\ - -t, --theme Path to a custom theme. Can be provided multiple times.\n\ - Defaults to ./node_modules.\n\ - -L, --skip-lms Don't compile LMS-specific SCSS.\n\ - -C, --skip-cms Don't compile CMS-specific SCSS.\n\ - -D, --skip-default-theme Don't compile SCSS for the default theme.\n\ - -n, --node-modules Path to installed node_modules directory.\n\ + -t, --theme Path to a custom theme; can be provided multiple times\n\ + -L, --skip-lms Don't compile LMS-specific SCSS\n\ + -C, --skip-cms Don't compile CMS-specific SCSS\n\ + -D, --skip-default-theme Don't compile SCSS for the default theme\n\ + -n, --node-modules Path to installed node_modules directory\n\ + Defaults to ./node_modules\n\ -f, --force Remove existing css before generating new css\n\ -d, --dev Dev mode: Don't compress output CSS\n\ - -r, --dry Dry run: don't do anything; just print what _would_ be done.\n\ - -v, --verbose Print commands as they are executed.\n\ - -h, --help Display this.\n\ + -r, --dry Dry run: don't actually execute any changes\n\ + -v, --verbose Print commands as they are executed\n\ + -h, --help Display this\n\ " # List of paths to custom themes, newline-separated. @@ -41,8 +41,8 @@ skip_cms="" skip_default_theme="" force="" dev="" -verbose="" dry="" +verbose="" # Parse arguments and options. while [ $# -gt 0 ]; do @@ -89,12 +89,12 @@ while [ $# -gt 0 ]; do dev="T" shift ;; - -v|--verbose) - verbose="T" + -r|--dry) + dry="T" shift ;; - -r|-dry) - dry="T" + -v|--verbose) + verbose="T" shift ;; -h|--help) @@ -112,37 +112,22 @@ while [ $# -gt 0 ]; do esac done +compile_dir_opts="" +if [ -n "$dev" ] ; then + compile_dir_opts="$compile_dir_opts --dev" +fi +if [ -n "$dry" ] ; then + compile_dir_opts="$compile_dir_opts --dry" +fi +if [ -n "$verbose" ] ; then + compile_dir_opts="$compile_dir_opts --verbose" +fi compile_dir ( ) { - - scss_src="$1" # Dir containing SCSS input files. - css_dest="$2" # Target dir for CSS output, to mirror input dir structure. - include_paths="$3" # List of SCSS import root paths, colon-separated. - - if [ ! -d "$scss_src" ] ; then - echo "Directory $scss_src does not exist; skipping." - return - fi - - # TODO: This will fail if any of the paths have spaces in them, because such a path - # would be parsed as multiple arguments rather than one argument with a space - # inside it. - compile_scss_dir_command="/bin/sh scripts/assets/compile-scss-dir.sh $scss_src $css_dest $include_paths" - if [ -n "$dev" ] ; then - compile_scss_dir_command="$compile_scss_dir_command --dev" - fi - if [ -n "$verbose" ] ; then - compile_scss_dir_command="$compile_scss_dir_command --verbose" - fi - - echo "Compiling directory: $scss_src -> $css_dest ..." - if [ -n "$force" ] ; then - echo " Removing old contents of $css_dest." - [ -z "$dry" ] && rm -f "$css_dest/*.css" - fi + # Shellcheck will complain that $compile_dir_opts is unquoted. + # It's intentional: we want $compile_dir_opts to be split on spaces and + # passed as multiple arguments. Quoting it would pass it as a single argument. # shellcheck disable=2086 - [ -z "$dry" ] && \ - $compile_scss_dir_command - echo " Done compiling: $scss_src -> $css_dest." + scripts/assets/compile-scss-dir.sh $compile_dir_opts "$1" "$2" "$3" } echo "-------------------------------------------------------------------------" @@ -151,23 +136,21 @@ echo echo " Working directory : $(pwd)" echo "-------------------------------------------------------------------------" -common_include_paths=\ -"common/static\ -:common/static/sass\ -:$node_modules_path\ -:$node_modules_path/@edx\ -" -lms_include_paths=\ -"$common_include_paths\ -:lms/static/sass\ -:lms/static/sass/partials\ -" -cms_include_paths=\ -"$common_include_paths\ -:cms/static/sass\ -:cms/static/sass/partials\ -:lms/static/sass/partials\ -" + +lms_scss="lms/static/sass" +lms_partials="lms/static/sass/partials" +cms_scss="cms/static/sass" +cms_partials="cms/static/sass/partials" +certs_scss="lms/static/certificates/sass" + +lms_css="lms/static/css" +cms_css="cms/static/css" +certs_css="lms/static/certificates/css" + +common_includes="common/static:common/static/sass:$node_modules_path:$node_modules_path/@edx" +lms_includes="$common_includes:$lms_scss:$lms_partials" +cms_includes="$common_includes:$cms_scss:$cms_partials:$lms_partials" +certs_includes="$lms_includes" if [ -n "$verbose" ] ; then set -x @@ -175,21 +158,19 @@ fi if [ -z "$skip_default_theme" ] ; then echo "Compiling SCSS for default theme..." + if [ -n "$force" ] ; then + echo " Removing existing generated CSS first." + [ -n "$dry" ] || rm -rf "$lms_css" "$cms_css" "$certs_css" + fi if [ -z "$skip_lms" ] ; then - compile_dir \ - "lms/static/sass" \ - "lms/static/css" \ - "$lms_include_paths" - compile_dir \ - "lms/static/certificates/sass" \ - "lms/static/certificates/css" \ - "$lms_include_paths" + echo " Compiling default LMS SCSS." + compile_dir "$lms_scss" "$lms_css" "$lms_includes" + echo " Compiling default certificates SCSS." + compile_dir "$certs_scss" "$certs_css" "$certs_includes" fi if [ -z "$skip_cms" ] ; then - compile_dir \ - "cms/static/sass" \ - "cms/static/css" \ - "$cms_include_paths" + echo " Compiling default CMS SCSS." + compile_dir "$cms_scss" "$cms_css" "$cms_includes" fi echo "Done compiling SCSS for default theme." fi @@ -200,48 +181,51 @@ echo "$theme_paths" | while read -r theme_path ; do continue fi + theme_lms_scss="$theme_path/lms/static/sass" + theme_lms_partials="$theme_path/lms/static/sass/partials" + theme_cms_scss="$theme_path/cms/static/sass" + theme_cms_partials="$theme_path/cms/static/sass/partials" + theme_certs_scss="$theme_path/lms/static/certificates/sass" + + theme_lms_css="$theme_path/lms/static/css" + theme_cms_css="$theme_path/cms/static/css" + theme_certs_css="$theme_path/lms/static/certificates/css" + + theme_lms_includes="$lms_includes:$theme_lms_partials" + theme_cms_includes="$cms_includes:$theme_cms_partials" + theme_certs_includes="$common_includes:$theme_lms_scss:$theme_lms_partials" + echo "Compiling SCSS for custom theme at $theme_path..." + if [ -n "$force" ] ; then + echo " Removing theme's existing generated CSS first." + [ -n "$dry" ] || rm -rf "$theme_lms_css" "$theme_cms_css" "$theme_certs_css" + fi - theme_lms_include_paths=\ -"$lms_include_paths\ -:$theme_path/lms/static/sass/partials\ -" - theme_certificate_include_paths=\ -"$common_include_paths\ -:$theme_path/lms/static/sass\ -:$theme_path/lms/static/sass/partials\ -" - theme_cms_include_paths=\ -"$cms_include_paths\ -:$theme_path/cms/static/sass/partials\ -" if [ -z "$skip_lms" ] ; then - # First, compile default LMS SCSS into theme's LMS CSS dir. - compile_dir \ - "lms/static/sass" \ - "$theme_path/lms/static/css" \ - "$theme_lms_include_paths" - # Then, override some/all default LMS CSS by compiling theme's LMS SCSS. - compile_dir \ - "$theme_path/lms/static/sass" \ - "$theme_path/lms/static/css" \ - "$theme_lms_include_paths" - # Finally, compile the themed certificate SCSS into certificate CSS dir. - compile_dir \ - "$theme_path/lms/static/certificates/sass" \ - "$theme_path/lms/static/certificates/css" \ - "$theme_certificate_include_paths" + echo " Compiling default LMS SCSS into theme's CSS directory." + compile_dir "$lms_scss" "$theme_lms_css" "$theme_lms_includes" + if [ -d "$theme_lms_scss" ] ; then + echo " Compiling theme's LMS SCSS into theme's CSS directory." + compile_dir "$theme_lms_scss" "$theme_lms_css" "$theme_lms_includes" + else + echo " Theme has no LMS SCSS; skipping." + fi + if [ -d "$theme_certs_scss" ] ; then + echo " Compiling theme's certificate SCSS into theme's CSS directory." + compile_dir "$theme_certs_scss" "$theme_certs_css" "$theme_certs_includes" + else + echo " Theme has no certificate SCSS; skipping." + fi fi if [ -z "$skip_cms" ] ; then - # Process for CMS is same as LMS, except no certificates. - compile_dir \ - "cms/static/sass" \ - "$theme_path/cms/static/css" \ - "$theme_cms_include_paths" - compile_dir \ - "$theme_path/cms/static/sass" \ - "$theme_path/cms/static/css" \ - "$theme_cms_include_paths" + echo " Compiling default CMS SCSS into theme's CSS directory." + compile_dir "$cms_scss" "$theme_cms_css" "$theme_cms_includes" + if [ -d "$theme_cms_scss" ] ; then + echo " Compiling theme's CMS SCSS into theme's CSS directory." + compile_dir "$theme_cms_scss" "$theme_cms_css" "$theme_cms_includes" + else + echo " Theme has no CMS SCSS; skipping." + fi fi echo "Done compiling SCSS for custom theme at $theme_path."