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: 3cca87899255b392cd94ad750a1d4fb46530b22e (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
#!/usr/bin/env bash

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

if [ -z "$TARGET" ] || [ -z "$VER" ]; then
  echo "Usage: $0 <target> <ver>"
  echo "Either <target> or <ver> is missing. Exiting."
  exit 1
fi

if ! [ -d "$TARGET" ]; then
  echo "Target directory $TARGET does not exist. Exiting."
  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
    echo "minify binary not found in PATH. Exiting."
    exit 1
  fi
fi

# Minify assets
printf "Optimizing assets..."

printf "HTML..."; $MINIFY_BIN "${MINIFY_FLAGS[@]}" --type=html --match="\.html$" -o "${TARGET}/${VER}/" "${TARGET}/${VER}" || true
printf "CSS..." ; $MINIFY_BIN "${MINIFY_FLAGS[@]}" --type=css  --match="\.css$"  -o "${TARGET}/${VER}/" "${TARGET}/${VER}" || true
printf "JSON..."; $MINIFY_BIN "${MINIFY_FLAGS[@]}" --type=json --match="\.json$" -o "${TARGET}/${VER}/" "${TARGET}/${VER}" || true
printf "SVG..." ; $MINIFY_BIN "${MINIFY_FLAGS[@]}" --type=svg  --match="\.svg$"  -o "${TARGET}/${VER}/" "${TARGET}/${VER}" || true

echo "Done"