aboutsummaryrefslogtreecommitdiff
path: root/deploy/build_css.sh
blob: 2129ea22e04cfc606799334030076a5dabd8eb9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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