|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +main() { |
| 4 | + if [[ "$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE" = true ]]; then |
| 5 | + echo "[Info] \`INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\` was set to true, skipping sourcemaps upload..." |
| 6 | + exit 0 |
| 7 | + fi |
| 8 | + |
| 9 | + if [[ -z "$INFOPLIST_FILE" ]] || [[ -z "$PROJECT_DIR" ]]; then |
| 10 | + echo "[Error] Instabug sourcemaps script must be invoked by Xcode" |
| 11 | + exit 1 |
| 12 | + fi |
| 13 | + |
| 14 | + local source_map_file=$(generate_sourcemaps | tail -n 1) |
| 15 | + |
| 16 | + local js_project_dir="$PROJECT_DIR/.." |
| 17 | + local instabug_dir=$(dirname $(node -p "require.resolve('instabug-reactnative/package.json')")) |
| 18 | + local inferred_token=$(cd $js_project_dir && source $instabug_dir/scripts/find-token.sh) |
| 19 | + local app_token=$(resolve_var "App Token" "INSTABUG_APP_TOKEN" "$inferred_token" | tail -n 1) |
| 20 | + |
| 21 | + local inferred_name=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' "$PROJECT_DIR/$INFOPLIST_FILE") |
| 22 | + local version_name=$(resolve_var "Version Name" "INSTABUG_APP_VERSION_NAME" "$inferred_name" | tail -n 1) |
| 23 | + |
| 24 | + local inferred_code=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' "$PROJECT_DIR/$INFOPLIST_FILE") |
| 25 | + local version_code=$(resolve_var "Version Code" "INSTABUG_APP_VERSION_CODE" "$inferred_code" | tail -n 1) |
| 26 | + |
| 27 | + npx instabug upload-sourcemaps \ |
| 28 | + --platform ios \ |
| 29 | + --file $source_map_file \ |
| 30 | + --token $app_token \ |
| 31 | + --name $version_name \ |
| 32 | + --code $version_code |
| 33 | +} |
| 34 | + |
| 35 | +generate_sourcemaps() { |
| 36 | + local react_native_dir=$(dirname $(node -p "require.resolve('react-native/package.json')")) |
| 37 | + |
| 38 | + # Fixes an issue with react-native prior to v0.67.0 |
| 39 | + # For more info: https://github.com/facebook/react-native/issues/32168 |
| 40 | + export RN_DIR=$react_native_dir |
| 41 | + |
| 42 | + # Used withing `react-native-xcode.sh` to generate sourcemap file |
| 43 | + export SOURCEMAP_FILE="$(pwd)/main.jsbundle.map"; |
| 44 | + |
| 45 | + source "$react_native_dir/scripts/react-native-xcode.sh" |
| 46 | + |
| 47 | + if [[ ! -f "$SOURCEMAP_FILE" ]]; then |
| 48 | + echo "[Error] Unable to find source map file at: $SOURCEMAP_FILE" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + |
| 52 | + echo $SOURCEMAP_FILE |
| 53 | +} |
| 54 | + |
| 55 | +resolve_var() { |
| 56 | + local name=$1 |
| 57 | + local env_key=$2 |
| 58 | + local default_value=$3 |
| 59 | + |
| 60 | + local env_value="${!env_key}" |
| 61 | + |
| 62 | + if [[ -n "$env_value" ]] && [[ "$env_value" != default_value ]]; then |
| 63 | + echo "[Warning] Environment variable \`$env_key\` might have incorrect value, make sure this was intentional:" |
| 64 | + echo " Environment Value: $env_value" |
| 65 | + echo " Default Value: $default_value" |
| 66 | + fi |
| 67 | + |
| 68 | + local value="${env_value:-$default_value}" |
| 69 | + |
| 70 | + if [[ -z "$value" ]]; then |
| 71 | + echo "[Error] Unable to find $name! Set the environment variable \`$env_key\` and try again." |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | + |
| 75 | + echo $value |
| 76 | +} |
| 77 | + |
| 78 | +main "$@"; exit |
0 commit comments