so://phie

verbal

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

blob: 18bc0b0c27e393fdc04b3a3d129d5ac0d837aa04 (4141 bytes)[doc][blame][raw]

1#!/bin/bash

2

3declare -A config

4config=(

5 ["--mode"]="dev"

6 ["--tw-local"]=false

7 ["--tw-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 if [[ "$value" == "$key" ]]; then

17 value="true"

18 fi

19 config["$key"]=$value

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

21

22print() {

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

24}

25

26section() {

27 echo ""

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

29 printf "\n"

30}

31

32MODE="${config["--mode"]}"

33

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

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

36 exit 1

37fi

38

39section "INFO"

40print "mode" $MODE

41

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

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

44fi

45

46print "version" $VERSION

47

48DIST_DIR="dist"

49

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

51 section "CLEAN"

52 rm -rf "$DIST_DIR"

53 print "remove" "$DIST_DIR/"

54fi

55

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

57 section "LINK"

58 print "create" "$DIST_DIR/"

59 mkdir -p "$DIST_DIR"

60 print "link" "$DIST_DIR/app/"

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

62 print "link" "$DIST_DIR/www/"

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

64fi

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

66 section "COPY"

67 print "create" "$DIST_DIR/"

68 mkdir -p "$DIST_DIR"

69 print "copy" "$DIST_DIR/app/"

70 cp -rf app "$DIST_DIR/app"

71 print "copy" "$DIST_DIR/www/"

72 cp -rf www "$DIST_DIR/www"

73fi

74

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

76 section "INJECT"

77

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

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

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

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

82fi

83

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

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

86

87section "DEPS"

88

89print "create" "$LIB_DIR/"

90mkdir -p "$LIB_DIR"

91print "create" "$FONT_DIR/"

92mkdir -p "$FONT_DIR"

93

94TW_LOCAL="${config["--tw-local"]}"

95

96# tailwindcss

97if [[ "$TW_LOCAL" == "false" ]]; then

98 print "download" "tailwindcss"

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

100 chmod +x "$DIST_DIR/tailwindcss"

101fi

102

103# vue

104print "download" "vue"

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

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

107

108# tabler-icons

109print "download" "tabler-icons"

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

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

112print "download" "tabler-icons-font"

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

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

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

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

117

118# inter

119print "download" "inter-font"

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

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

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

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

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

125rm -rf "$FONT_DIR/inter"

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

127

128section "BUILD"

129

130TW_BIN="$DIST_DIR/tailwindcss"

131TW_WATCH="${config["--tw-watch"]}"

132

133if [[ "$TW_LOCAL" == "true" ]]; then

134 TW_BIN="tailwindcss"

135fi

136

137if [[ "$TW_WATCH" == "true" ]]; then

138 print "watch" "tailwindcss"

139 WATCH_FLAG="--watch"

140else

141 print "build" "tailwindcss"

142fi

143

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

145

146STATUS="$?"

147

148section

149

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

151 print "status" "failed"

152 echo ""

153 exit 1

154fi

155

156print "status" "success"

157echo ""