Skip to content

Commit 5386c80

Browse files
authored
✨Exposes environment variable for APP TOKEN (#54)
Exposes environment variable to be set in android and ios for the APP TOKEN Renames the token inside the script to INSTABUG_APP_TOKEN
1 parent 2d45af4 commit 5386c80

File tree

5 files changed

+64
-27
lines changed

5 files changed

+64
-27
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,30 @@ If your app doesn’t already access the microphone or photo library, we recomme
174174
175175
**The permission alert for accessing the microphone/photo library will NOT appear unless users attempt to attach a voice note/photo while using Instabug.**
176176
177+
178+
## Auto Uploading Source Map Files
179+
180+
We will automatically generate the source map files and upload them to your dashboard on release build. You just have to add
181+
`Instabug.startWithToken('YOUR_APP_TOKEN'` in your .js file.
182+
183+
Alternatively, you can set the app token manually as shown below:
184+
185+
1. In Android, go to the `build.gradle` file of the library and you will find below code, replace `YOUR_APP_TOKEN` with your token from the dashboard.
186+
187+
```java
188+
task upload_sourcemap(type: Exec) {
189+
environment "INSTABUG_APP_TOKEN", "YOUR_APP_TOKEN"
190+
commandLine 'sh', './upload_sourcemap.sh'
191+
}
192+
```
193+
194+
2. In iOS, go to the build phases of the project, you will find a build phase called `Upload Sourcemap`. Expand it you will find below lines of code, replace `YOUR_APP_TOKEN` with your token from the dashboard.
195+
196+
```bash
197+
export INSTABUG_APP_TOKEN="YOUR_APP_TOKEN"
198+
bash "../node_modules/instabug-reactnative/ios/upload_sourcemap.sh"
199+
```
200+
177201
## Documentation
178202
179203
For more details about the supported APIs and how to use them, check our [**Documentation**](https://docs.instabug.com/docs/react-native-overview).

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies {
3131
}
3232

3333
task upload_sourcemap(type: Exec) {
34+
environment "INSTABUG_APP_TOKEN", "YOUR_APP_TOKEN"
3435
commandLine 'sh', './upload_sourcemap.sh'
3536
}
3637

android/upload_sourcemap.sh

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
cd ..
33
cd ..
44
cd ..
5+
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
6+
. "$HOME/.nvm/nvm.sh"
7+
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
8+
. "$(brew --prefix nvm)/nvm.sh"
9+
fi
10+
export NODE_BINARY=node
511
#Generate android sourcemap
612
react-native bundle --platform android \
713
--entry-file index.js \
@@ -10,22 +16,24 @@ react-native bundle --platform android \
1016
--sourcemap-output ./android-sourcemap.json &&
1117
zip ./android-sourcemap.zip ./android-sourcemap.json
1218

13-
echo "Instabug: Looking for Token..."
14-
if [ ! "${APP_TOKEN}" ]; then
15-
APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} 'Instabug.startWithToken(\"[0-9a-zA-Z]*\"' ./ -m 1 | grep -o '\"[0-9a-zA-Z]*\"' | cut -d "\"" -f 2)
16-
fi
19+
if [ ${INSTABUG_APP_TOKEN} == "YOUR_APP_TOKEN" ]; then
20+
echo "Instabug: Looking for Token..."
21+
if [ ! "${INSTABUG_APP_TOKEN}" ]; then
22+
INSTABUG_APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} 'Instabug.startWithToken(\"[0-9a-zA-Z]*\"' ./ -m 1 | grep -o '\"[0-9a-zA-Z]*\"' | cut -d "\"" -f 2)
23+
fi
1724

18-
if [ ! "${APP_TOKEN}" ]; then
19-
APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} "Instabug.startWithToken(\'[0-9a-zA-Z]*\'" ./ -m 1 | grep -o "\'[0-9a-zA-Z]*\'" | cut -d "\"" -f 2)
25+
if [ ! "${INSTABUG_APP_TOKEN}" ]; then
26+
INSTABUG_APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} "Instabug.startWithToken(\'[0-9a-zA-Z]*\'" ./ -m 1 | grep -o "\'[0-9a-zA-Z]*\'" | cut -d "\"" -f 2)
27+
fi
2028
fi
2129

22-
if [ ! "${APP_TOKEN}" ] || [ -z "${APP_TOKEN}" ];then
23-
echo "Instabug: err: APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.startWithToken"
24-
exit 0
25-
else
26-
echo "Instabug: Uploading files..."
27-
#Upload android sourcemap
28-
curl -X POST 'https://api.instabug.com/api/sdk/v3/symbols_files' -F "symbols_file=@./android-sourcemap.json" -F "application_token=${APP_TOKEN}" -F "platform=react_native" -F "os=android"
2930

30-
echo
31+
if [ ! "${INSTABUG_APP_TOKEN}" ] || [ -z "${INSTABUG_APP_TOKEN}" ] || [ "${INSTABUG_APP_TOKEN}" == "YOUR_APP_TOKEN" ];then
32+
echo "Instabug: err: INSTABUG_APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.startWithToken Or added it to the environment variable in the gradle"
33+
exit 0
34+
else
35+
echo "Instabug: Uploading files..."
36+
#Upload ios sourcemap
37+
curl -X POST 'https://api.instabug.com/api/sdk/v3/symbols_files' -F "symbols_file=@./ios-sourcemap.json" -F "application_token=${INSTABUG_APP_TOKEN}" -F "platform=react_native" -F "os=ios"
38+
echo
3139
fi

ios/upload_sourcemap.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@ react-native bundle --platform ios \
1515
--sourcemap-output ./ios-sourcemap.json &&
1616
zip ./ios-sourcemap.zip ./ios-sourcemap.json
1717

18-
echo "Instabug: Looking for Token..."
19-
if [ ! "${APP_TOKEN}" ]; then
20-
APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} 'Instabug.startWithToken(\"[0-9a-zA-Z]*\"' ./ -m 1 | grep -o '\"[0-9a-zA-Z]*\"' | cut -d "\"" -f 2)
21-
fi
18+
if [ ${INSTABUG_APP_TOKEN} == "YOUR_APP_TOKEN" ]; then
19+
echo "Instabug: Looking for Token..."
20+
if [ ! "${INSTABUG_APP_TOKEN}" ]; then
21+
INSTABUG_APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} 'Instabug.startWithToken(\"[0-9a-zA-Z]*\"' ./ -m 1 | grep -o '\"[0-9a-zA-Z]*\"' | cut -d "\"" -f 2)
22+
fi
2223

23-
if [ ! "${APP_TOKEN}" ]; then
24-
APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} "Instabug.startWithToken(\'[0-9a-zA-Z]*\'" ./ -m 1 | grep -o "\'[0-9a-zA-Z]*\'" | cut -d "\"" -f 2)
24+
if [ ! "${INSTABUG_APP_TOKEN}" ]; then
25+
INSTABUG_APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} "Instabug.startWithToken(\'[0-9a-zA-Z]*\'" ./ -m 1 | grep -o "\'[0-9a-zA-Z]*\'" | cut -d "\"" -f 2)
26+
fi
2527
fi
2628

27-
if [ ! "${APP_TOKEN}" ] || [ -z "${APP_TOKEN}" ];then
28-
echo "Instabug: err: APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.startWithToken"
29-
exit 0
29+
30+
if [ ! "${INSTABUG_APP_TOKEN}" ] || [ -z "${INSTABUG_APP_TOKEN}" ] || [ "${INSTABUG_APP_TOKEN}" == "YOUR_APP_TOKEN" ];then
31+
echo "Instabug: err: INSTABUG_APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.startWithToken Or added it to the environment variable in the gradle"
32+
exit 0
3033
else
31-
echo "Instabug: Uploading files..."
32-
#Upload ios sourcemap
33-
curl -X POST 'https://api.instabug.com/api/sdk/v3/symbols_files' -F "symbols_file=@./ios-sourcemap.json" -F "application_token=${APP_TOKEN}" -F "platform=react_native" -F "os=ios"
34-
echo
34+
echo "Instabug: Uploading files..."
35+
#Upload ios sourcemap
36+
curl -X POST 'https://api.instabug.com/api/sdk/v3/symbols_files' -F "symbols_file=@./ios-sourcemap.json" -F "application_token=${INSTABUG_APP_TOKEN}" -F "platform=react_native" -F "os=ios"
37+
echo
3538
fi

link.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
INSTABUG_UPLOAD_NAME = "Upload Sourcemap"
2525

2626
INSTABUG_UPLOAD_SCRIPT = <<-SCRIPTEND
27+
export INSTABUG_APP_TOKEN="YOUR_APP_TOKEN"
2728
bash "../node_modules/instabug-reactnative/ios/upload_sourcemap.sh"
2829
SCRIPTEND
2930

0 commit comments

Comments
 (0)