#!/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 LESSC="$ROOT"/node_modules/.bin/lessc THEMES="light dark" TARGETS="app" INDIR= OUTDIR= TYPE= error() { >&2 echo "error: $@" } die() { error "$@" exit 1 } installed() { command -v "$1" > /dev/null return $? } usage() { cat < "$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" } [ -z "$1" ] && usage while [[ $# -gt 0 ]]; do case $1 in -o) OUTDIR="$2" shift ;; -i) INDIR="$2" shift ;; -t) case $2 in less|scss) TYPE="$2" ;; *) die "invalid type: $2" ;; esac shift ;; -h) usage ;; *) die "unexpected argument: $1" ;; esac shift done [ -z "$OUTDIR" ] && die "output directory is not specified" [ -z "$INDIR" ] && die "input directory is not specified" [ -z "$TYPE" ] && die "type is not specified" if [ ! -d "$OUTDIR" ]; then mkdir "$OUTDIR" else rm "$OUTDIR"/* fi [ -x "$CLEANCSS" ] || die "$CLEANCSS: cleancss not found" case "$TYPE" in less) [ -x "$LESSC" ] || die "$LESSC: lessc not found" ;; scss) installed sassc || die "sassc not found" ;; esac for theme in $THEMES; do for target in $TARGETS; do build "$target" "$theme" done done for target in $TARGETS; do create_dark_patch "$target" for theme in $THEMES; do cleancss "$target" "$theme" done done