diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-07-11 02:59:35 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-07-11 02:59:40 +0300 |
commit | 864e73cdc75a2fb0e4fad500f649dae2343c10a8 (patch) | |
tree | 6ce6762c6be72c98592a32fe0bed4f2ce751d544 /deploy/build_css.sh | |
parent | cb13ea239b9f1ca6aea43125d5694d5a55dcd287 (diff) |
rewrite css and js assets building
Diffstat (limited to 'deploy/build_css.sh')
-rwxr-xr-x | deploy/build_css.sh | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/deploy/build_css.sh b/deploy/build_css.sh new file mode 100755 index 0000000..2129ea2 --- /dev/null +++ b/deploy/build_css.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +PROGNAME="$0" +DIR="$( cd "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && pwd )" +ROOT="$(realpath "$DIR/../")" +CLEANCSS="$ROOT"/node_modules/clean-css-cli/bin/cleancss + +. $DIR/build_common.sh + +build_scss() { + local entry_name="$1" + local theme="$2" + + local input="$INDIR/entries/$entry_name/$theme.scss" + local output="$OUTDIR/$entry_name" + [ "$theme" = "dark" ] && output="${output}_dark" + output="${output}.css" + + sassc -t compressed "$input" "$output" +} + +cleancss() { + local entry_name="$1" + local theme="$2" + + local file="$OUTDIR/$entry_name" + [ "$theme" = "dark" ] && file="${file}_dark" + file="${file}.css" + + $CLEANCSS -O2 "all:on;mergeSemantically:on;restructureRules:on" "$file" > "$file.tmp" + rm "$file" + mv "$file.tmp" "$file" +} + +create_dark_patch() { + local entry_name="$1" + local light_file="$OUTDIR/$entry_name.css" + local dark_file="$OUTDIR/${entry_name}_dark.css" + + "$DIR"/gen_css_diff.js "$light_file" "$dark_file" > "$dark_file.diff" + rm "$dark_file" + mv "$dark_file.diff" "$dark_file" +} + +THEMES="light dark" +TARGETS="common admin" + +input_args "$@" +check_args + +[ -x "$CLEANCSS" ] || die "cleancss is not found" + +for theme in $THEMES; do + for target in $TARGETS; do + build_scss "$target" "$theme" + done +done + +for target in $TARGETS; do + create_dark_patch "$target" + for theme in $THEMES; do cleancss "$target" "$theme"; done +done
\ No newline at end of file |