preprocess_css (1576B)
1 #!/usr/bin/env bash 2 3 # CSS Preprocessing Script 4 5 # Include mustache for bash as library 6 . ~/bin/mo 7 8 CSS_DST_PATH=static/dst/css 9 CSS_SRC_PATH=static/src/css 10 11 # Convert pixels to EMs 12 px_to_em () { 13 pixel_size=$1 14 pixel_context=16 15 16 if [ -n "$2" ]; then 17 pixel_context=$2 18 fi 19 20 echo "$(bc <<< "scale=4;$pixel_size/$pixel_context")em" 21 } 22 23 # Associative array with breakpoints and sizes in EMs 24 declare -A BREAKPOINTS 25 26 BREAKPOINTS=( 27 [xxs]=$(px_to_em 360) 28 [xs]=$(px_to_em 520) 29 [sm]=$(px_to_em 768) 30 [md]=$(px_to_em 992) 31 [lg]=$(px_to_em 1140) 32 ) 33 34 # You must install "Minify CLI" for running this script : 35 # <https://github.com/tdewolff/minify/tree/master/cmd/minify> 36 if hash minify 2>/dev/null; then 37 # CSS Concatenation 38 cat "$CSS_SRC_PATH/global/fonts.css" \ 39 "$CSS_SRC_PATH/global/normalize.css" \ 40 "$CSS_SRC_PATH/global/abstractions.css" \ 41 "$CSS_SRC_PATH/global/base.css" \ 42 "$CSS_SRC_PATH/global/helpers.css" \ 43 "$CSS_SRC_PATH/global/grid.css" \ 44 "$CSS_SRC_PATH/modules/"*.css \ 45 > "$CSS_DST_PATH/styles.tmp.css" 46 47 # Replace mustache tags with associative array and co. 48 mo "$CSS_DST_PATH"/styles.tmp.css > "$CSS_DST_PATH"/styles.css 49 50 # Remove the temporary stylesheet 51 rm "$CSS_DST_PATH"/styles.tmp.css 52 53 # CSS Minification 54 minify -v --mime=text/css < "$CSS_DST_PATH"/styles.css > "$CSS_DST_PATH"/styles.min.css 55 else 56 echo "- You must install Minify CLI for running this script" 57 echo "- <https://github.com/tdewolff/minify/tree/master/cmd/minify>" 58 fi