UNPKG

4.39 kBapplication/x-shView Raw
1#!/bin/sh
2
3TEMP_DIR_PATH=""
4FONTAWESOME_PRO_DIR_NAME=""
5VERSION=${1:-"5"}
6DEST_DIR_PATH=${2:-"assets/fonts"}
7PROJECT_NAME="react-native-vector-icons"
8FONT_NAME="Font Awesome Pro"
9
10setup_npm_config()
11{
12 # always returns successfull zero code
13 if [ "$(npm config get @fortawesome:registry)" = "undefined" ]; then
14 npm config set "@fortawesome:registry" https://npm.fontawesome.com/
15 fi
16
17 local npm_token=""
18 echo "Please enter your $FONT_NAME npm token:";
19 read npm_token
20 npm config set "//npm.fontawesome.com/:_authToken" "${npm_token}"
21}
22
23create_tmp_directory()
24{
25 local tmp_dir="$(mktemp -d -t 'rnvi.XXXXXX')"
26 retval=$?
27 if [ "$retval" != 0 ]; then
28 echo "[FAIL] Can't create temporary directory";
29 return 1;
30 fi
31
32 if [ -z "$tmp_dir" ]; then
33 echo "[FAIL] Generated temporary directory name is empty";
34 return 1;
35 fi
36
37 TEMP_DIR_PATH="$tmp_dir"
38}
39
40download_and_unpack_fontawesome_pro()
41{
42 local archive_file_name="$(npm pack @fortawesome/fontawesome-pro --silent)"
43 retval=$?
44 if [ "$retval" != 0 ]; then
45 echo "[FAIL] Can't download [$archive_file_name] archive";
46 return 1;
47 fi
48
49 tar -xzf "$archive_file_name"
50 retval=$?
51 if [ "$retval" != 0 ]; then
52 echo "[FAIL] Can't unpack [$archive_file_name] archive";
53 return 1;
54 fi
55
56 local font_dir_name="package"
57 if [ ! -d "$font_dir_name" ]; then
58 echo "[FAIL] Archive doesn't contain [$font_dir_name] required directory";
59 return 1;
60 fi
61
62 FONTAWESOME_PRO_DIR_NAME="$font_dir_name"
63}
64
65copy_ttf_fonts_to_dest_dir()
66{
67 mkdir -p "$DEST_DIR_PATH"
68 retval=$?
69 if [ "$retval" != 0 ]; then
70 echo "[FAIL] Can't create [$DEST_DIR_PATH] directory";
71 return 1;
72 fi
73
74 local font_dir_path="$TEMP_DIR_PATH/$FONTAWESOME_PRO_DIR_NAME/webfonts"
75
76 if [ "$VERSION" = "5" ]; then
77 cp "$font_dir_path/fa-light-300.ttf" "$DEST_DIR_PATH/FontAwesome5_Pro_Light.ttf" &&
78 cp "$font_dir_path/fa-brands-400.ttf" "$DEST_DIR_PATH/FontAwesome5_Pro_Brands.ttf" &&
79 cp "$font_dir_path/fa-regular-400.ttf" "$DEST_DIR_PATH/FontAwesome5_Pro_Regular.ttf" &&
80 cp "$font_dir_path/fa-solid-900.ttf" "$DEST_DIR_PATH/FontAwesome5_Pro_Solid.ttf"
81 elif [ "$VERSION" = "6" ]; then
82 cp "$font_dir_path/fa-light-300.ttf" "$DEST_DIR_PATH/FontAwesome6_Pro_Light.ttf" &&
83 cp "$font_dir_path/fa-brands-400.ttf" "$DEST_DIR_PATH/FontAwesome6_Pro_Brands.ttf" &&
84 cp "$font_dir_path/fa-regular-400.ttf" "$DEST_DIR_PATH/FontAwesome6_Pro_Regular.ttf" &&
85 cp "$font_dir_path/fa-solid-900.ttf" "$DEST_DIR_PATH/FontAwesome6_Pro_Solid.ttf"
86 cp "$font_dir_path/fa-duotone-900.ttf" "$DEST_DIR_PATH/FontAwesome6_Pro_Duotone.ttf"
87 cp "$font_dir_path/fa-thin-100.ttf" "$DEST_DIR_PATH/FontAwesome6_Pro_Thin.ttf"
88 cp "$font_dir_path/fa-sharp-solid-900.ttf" "$DEST_DIR_PATH/FontAwesome6_Pro_Sharp_Solid.ttf"
89 else
90 echo "[FAIL] Unsupported version [$VERSION]";
91 exit 1
92 fi
93
94 retval=$?
95 if [ "$retval" != 0 ]; then
96 echo "[FAIL] Can't copy ttf fonts to [$DEST_DIR_PATH] directory";
97 return 1;
98 fi
99}
100
101create_rn_config()
102{
103 if [ -f "./react-native.config.js" ]; then
104 echo "You already have a react-native-config.js file, make sure you have the new fonts added to the dependencies!";
105 return 1;
106 else
107 echo "module.exports = { assets: [ '${DEST_DIR_PATH}' ] };" > react-native.config.js;
108 fi
109}
110
111react_native_link_project()
112{
113 react-native link
114}
115
116if setup_npm_config; then
117 echo "[SUCCESS] Set up npm config";
118else
119 exit 1;
120fi
121
122if create_tmp_directory; then
123 echo "[SUCCESS] Temporary directory [$TEMP_DIR_PATH] was created";
124else
125 exit 1;
126fi
127
128cd "$TEMP_DIR_PATH"
129if download_and_unpack_fontawesome_pro; then
130 echo "[SUCCESS] $FONT_NAME was unpacked to [$TEMP_DIR_PATH/$FONTAWESOME_PRO_DIR_NAME] directory";
131else
132 exit 1;
133fi
134cd - > /dev/null
135
136if copy_ttf_fonts_to_dest_dir; then
137 echo "[SUCCESS] Copied $FONT_NAME to [$DEST_DIR_PATH] directory";
138else
139 exit 1;
140fi
141
142if create_rn_config; then
143 echo "[SUCCESS] Created react-native.config.js";
144else
145 echo "[INFO] Didn't create react-native.config.js, it already exists. Make sure '${DEST_DIR_PATH}' is part of the 'assets' array!";
146fi
147
148if react_native_link_project; then
149 echo "[SUCCESS] Linked $PROJECT_NAME to React Native";
150else
151 exit 1;
152fi
153
154echo "[SUCCESS] $FONT_NAME was successfully upgraded"
155echo "Note: [$TEMP_DIR_PATH] was created. Delete it manually or it will be deleted automatically on next reboot"