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: 6d1f9567f63c8ddd5b7b4b0b985073cfc2940840 (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
#!/bin/sh

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

if [ -z "$TARGET" -o -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

# Backwards compatibility
if [ -f /scripts/minify ]
then
  MINIFY_BIN=/scripts/minify
elif hash minify 2>/dev/null
then
  MINIFY_BIN=$(which minify)
elif hash docker 2>/dev/null
then
  MINIFY_BIN="docker run -t -v ${PWD}:/gitlab -w /gitlab --rm tdewolff/minify minify"
else
  echo "  ✖ ERROR: 'minify' not found. Install 'minify' or Docker to proceed." >&2
  exit 1
fi

# Minify assets
printf "Optimizing assets...\n"

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"