so://phie

verbal

A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal

blob: e8cee5acf5283f324b26050ce6525e31493e4e3d (4157 bytes)[doc][blame][raw]

1#!/bin/bash

2

3declare -A config

4config=(

5 ["mode"]="dev"

6 ["twc-local"]=false

7 ["twc-watch"]=false

8)

9

10while read argument; do

11 key=$(echo "$argument" | awk '{split($0, a, "="); print a[1]}')

12 if [ -z "$key" ]; then

13 continue

14 fi

15 value=$(echo "$argument" | awk '{st = index($0, "="); print substr($0, st + 1)}')

16 config["$key"]=$value

17done <<< $(echo "$@" | tr " " "\n")

18

19print() {

20 printf "%-8s %s\n" $1 $2

21}

22

23section() {

24 echo ""

25 printf "%2s%-48s" "" $1 | tr ' ' '-'

26 printf "\n"

27}

28

29MODE="${config["mode"]}"

30

31if [[ "$MODE" != "dev" ]] && [[ "$MODE" != "prod" ]]; then

32 echo "[ERROR] invalid mode '$MODE'!"

33 exit 1

34fi

35

36section "INFO"

37print "mode" $MODE

38

39if [[ -z "$VERSION" ]]; then

40 VERSION=$(git log --format="%h" -n 1)

41fi

42

43print "version" $VERSION

44

45DIST_DIR="dist"

46

47if [[ -d "$DIST_DIR" ]]; then

48 section "CLEAN"

49 rm -rf "$DIST_DIR"

50 print "remove" "$DIST_DIR/"

51fi

52

53if [[ "$MODE" == "dev" ]]; then

54 section "LINK"

55 print "create" "$DIST_DIR/"

56 mkdir -p "$DIST_DIR"

57 print "link" "$DIST_DIR/app/"

58 ln -sf "../app" "$DIST_DIR/app"

59 print "link" "$DIST_DIR/www/"

60 ln -sf "../www" "$DIST_DIR/www"

61fi

62if [[ "$MODE" == "prod" ]]; then

63 section "COPY"

64 print "create" "$DIST_DIR/"

65 mkdir -p "$DIST_DIR"

66 print "copy" "$DIST_DIR/app/"

67 cp -rf app "$DIST_DIR/app"

68 print "copy" "$DIST_DIR/www/"

69 cp -rf www "$DIST_DIR/www"

70fi

71

72if [[ "$MODE" == "prod" ]]; then

73 section "INJECT"

74

75 sed -i -e "s/{{version}}/$VERSION/g" "$DIST_DIR/www/worker.js"

76 print "inject" "$DIST_DIR/www/worker.js"

77 sed -i -e "s/{{version}}/$VERSION/g" "$DIST_DIR/app/main.js"

78 print "inject" "$DIST_DIR/app/main.js"

79fi

80

81LIB_DIR="$DIST_DIR/www/asset/lib"

82FONT_DIR="$DIST_DIR/www/asset/font"

83

84section "DEPS"

85

86print "create" "$LIB_DIR/"

87mkdir -p "$LIB_DIR"

88print "create" "$FONT_DIR/"

89mkdir -p "$FONT_DIR"

90

91TWC_LOCAL="${config["twc-local"]}"

92

93# tailwindcss

94if [[ "$TWC_LOCAL" == "false" ]]; then

95 print "download" "tailwindcss"

96 curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -o "$DIST_DIR/tailwindcss"

97 chmod +x "$DIST_DIR/tailwindcss"

98fi

99

100# vue

101print "download" "vue"

102curl -sL https://cdn.jsdelivr.net/npm/vue@2/dist/vue.esm.browser.min.js -o "$LIB_DIR/vue.min.js"

103# curl -L https://unpkg.com/vue@latest/dist/vue.esm-browser.prod.js -o ./www/asset/lib/vue.min.js -s

104

105# tabler-icons

106print "download" "tabler-icons"

107curl -sL https://cdn.jsdelivr.net/npm/@tabler/icons@latest/iconfont/tabler-icons.min.css -o "$LIB_DIR/tabler-icons.min.css"

108sed -i -e "s/fonts\/tabler-icons/..\/font\/tabler-icons/g" "$LIB_DIR/tabler-icons.min.css"

109print "download" "tabler-icons-font"

110curl -sL https://cdn.jsdelivr.net/npm/@tabler/icons@latest/iconfont/fonts/tabler-icons.eot -o "$FONT_DIR/tabler-icons.eot"

111curl -sL https://cdn.jsdelivr.net/npm/@tabler/icons@latest/iconfont/fonts/tabler-icons.ttf -o "$FONT_DIR/tabler-icons.ttf"

112curl -sL https://cdn.jsdelivr.net/npm/@tabler/icons@latest/iconfont/fonts/tabler-icons.woff -o "$FONT_DIR/tabler-icons.woff"

113curl -sL https://cdn.jsdelivr.net/npm/@tabler/icons@latest/iconfont/fonts/tabler-icons.woff2 -o "$FONT_DIR/tabler-icons.woff2"

114

115# inter

116print "download" "inter-font"

117curl -sL https://fonts.google.com/download?family=Inter -o "$FONT_DIR/inter.zip"

118unzip -qq "$FONT_DIR/inter.zip" -d "$FONT_DIR/inter"

119mv "$FONT_DIR/inter/static/Inter-Regular.ttf" "$FONT_DIR/"

120mv "$FONT_DIR/inter/static/Inter-Medium.ttf" "$FONT_DIR/"

121mv "$FONT_DIR/inter/static/Inter-SemiBold.ttf" "$FONT_DIR/"

122rm -rf "$FONT_DIR/inter"

123rm -rf "$FONT_DIR/inter.zip"

124

125section "BUILD"

126

127TWC_BIN="$DIST_DIR/tailwindcss"

128TWC_WATCH="${config["twc-watch"]}"

129

130if [[ "$TWC_LOCAL" == "true" ]] || [[ "$TWC_LOCAL" == "twc-local" ]]; then

131 TWC_BIN="tailwindcss"

132fi

133

134if [[ "$TWC_WATCH" == "true" ]] || [[ "$TWC_WATCH" == "twc-watch" ]]; then

135 print "watch" "tailwindcss"

136 WATCH_FLAG="--watch"

137else

138 print "build" "tailwindcss"

139fi

140

141"$TWC_BIN" -c tailwind.config.js -i "$DIST_DIR/www/asset/css/input.css" -o "$DIST_DIR/www/asset/css/output.css" --minify "$WATCH_FLAG"

142

143STATUS="$?"

144

145section

146

147if [[ "$STATUS" != "0" ]]; then

148 print "status" "failed"

149 echo ""

150 exit 1

151fi

152

153print "status" "success"

154echo ""