so://phie

verbal

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

blob: d98c82ed1bcaf19183257694ad8683d9f672e86f (4227 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"

49MEDIA_DIR="media"

50

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

52 section "CLEAN"

53 rm -rf "$DIST_DIR"

54 print "remove" "$DIST_DIR/"

55fi

56

57section "MEDIA"

58mkdir -p "$MEDIA_DIR"

59print "create" "$MEDIA_DIR/"

60

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

62 section "LINK"

63 print "create" "$DIST_DIR/"

64 mkdir -p "$DIST_DIR"

65 print "link" "$DIST_DIR/app/"

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

67 print "link" "$DIST_DIR/www/"

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

69fi

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

71 section "COPY"

72 print "create" "$DIST_DIR/"

73 mkdir -p "$DIST_DIR"

74 print "copy" "$DIST_DIR/app/"

75 cp -rf app "$DIST_DIR/app"

76 print "copy" "$DIST_DIR/www/"

77 cp -rf www "$DIST_DIR/www"

78fi

79

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

81 section "INJECT"

82

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

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

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

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

87fi

88

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

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

91

92section "DEPS"

93

94print "create" "$LIB_DIR/"

95mkdir -p "$LIB_DIR"

96print "create" "$FONT_DIR/"

97mkdir -p "$FONT_DIR"

98

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

100

101# tailwindcss

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

103 print "download" "tailwindcss"

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

105 chmod +x "$DIST_DIR/tailwindcss"

106fi

107

108# vue

109print "download" "vue"

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

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

112

113# tabler-icons

114print "download" "tabler-icons"

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

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

117print "download" "tabler-icons-font"

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

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

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

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

122

123# inter

124print "download" "inter-font"

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

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

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

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

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

130rm -rf "$FONT_DIR/inter"

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

132

133section "BUILD"

134

135TW_BIN="$DIST_DIR/tailwindcss"

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

137

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

139 TW_BIN="tailwindcss"

140fi

141

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

143 print "watch" "tailwindcss"

144 WATCH_FLAG="--watch"

145else

146 print "build" "tailwindcss"

147fi

148

149"$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"

150

151STATUS="$?"

152

153section

154

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

156 print "status" "failed"

157 echo ""

158 exit 1

159fi

160

161print "status" "success"

162echo ""