Welcome to mirror list, hosted at ThFree Co, Russian Federation.

minify-assets.sh « scripts - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aa27512e1c278b71f50c0050c1c90fffc1783c70 (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
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
# shellcheck disable=SC2059

TARGET="$1"
VER="$2"
MINIFY_FLAGS=("--html-keep-document-tags" "--html-keep-whitespace" "--recursive")

COLOR_RED="\e[31m"
COLOR_GREEN="\e[32m"
COLOR_RESET="\e[39m"

if [ -z "$TARGET" ] || [ -z "$VER" ]; then
  echo "Usage: $0 <target> <ver>"
    printf "${COLOR_RED}ERROR: Either <target> or <ver> is missing.${COLOR_RESET}\n"
  exit 1
fi

if ! [ -d "$TARGET" ]; then
    printf "${COLOR_RED}ERROR: Target directory $TARGET does not exist.${COLOR_RESET}\n"
  exit 1
fi

# Check if minify is in the PATH
if which minify > /dev/null 2>&1
then
  MINIFY_BIN=$(which minify)
else
  # Backwards compatibility
  if [ -f /scripts/minify ]
  then
    MINIFY_BIN=/scripts/minify
  else
        printf "${COLOR_RED}ERROR: minify not found in PATH. Run 'make setup'.${COLOR_RESET}\n"
    exit 1
  fi
fi

# Minify assets
printf "${COLOR_GREEN}INFO: Minifying HTML...${COLOR_RESET}\n"
if $MINIFY_BIN "${MINIFY_FLAGS[@]}" --type=html --match="\.html$" -o "${TARGET}/${VER}/" "${TARGET}/${VER}"; then
    printf "${COLOR_GREEN}INFO: HTML minified!${COLOR_RESET}\n"
else
    printf "${COLOR_RED}ERROR: Couldn't minify HTML${COLOR_RESET}\n"
  exit 1
fi

printf "${COLOR_GREEN}INFO: Minifying CSS...${COLOR_RESET}\n"
if $MINIFY_BIN "${MINIFY_FLAGS[@]}" --type=css  --match="\.css$"  -o "${TARGET}/${VER}/" "${TARGET}/${VER}"; then
    printf "${COLOR_GREEN}INFO: CSS minified!${COLOR_RESET}\n"
else
    printf "${COLOR_RED}ERROR: Couldn't minify CSS${COLOR_RESET}\n"
  exit 1
fi


printf "${COLOR_GREEN}INFO: Minifying JSON...${COLOR_RESET}\n"
if $MINIFY_BIN "${MINIFY_FLAGS[@]}" --type=json --match="\.json$" -o "${TARGET}/${VER}/" "${TARGET}/${VER}"; then
    printf "${COLOR_GREEN}INFO: JSON minified!${COLOR_RESET}\n"
else
    printf "${COLOR_RED}ERROR: Couldn't minify JSON${COLOR_RESET}\n"
  exit 1
fi

printf "${COLOR_GREEN}INFO: Minifying SVGs...${COLOR_RESET}\n"
if $MINIFY_BIN "${MINIFY_FLAGS[@]}" --type=svg  --match="\.svg$"  -o "${TARGET}/${VER}/" "${TARGET}/${VER}"; then
    printf "${COLOR_GREEN}INFO: SVGs minified!${COLOR_RESET}\n"
else
    printf "${COLOR_RED}ERROR: Couldn't minify SVGs${COLOR_RESET}\n"
  exit 1
fi