Skip to content

Commit 51f3589

Browse files
authored
Auto upload source map (#44)
1) Adds Auto Upload Source maps bash files 2) Adds Build Phase to Ruby Script 3) Adds Pre Build execution in android gradle
1 parent d0a37c6 commit 51f3589

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

android/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,13 @@ dependencies {
2929
exclude group: 'com.android.support:appcompat-v7'
3030
}
3131
}
32+
33+
task upload_sourcemap(type: Exec) {
34+
commandLine 'sh', './upload_sourcemap.sh'
35+
}
36+
37+
tasks.whenTaskAdded { task ->
38+
if (task.name == 'preReleaseBuild') {
39+
task.dependsOn upload_sourcemap
40+
}
41+
}

android/upload_sourcemap.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
cd ..
3+
cd ..
4+
cd ..
5+
#Generate android sourcemap
6+
react-native bundle --platform android \
7+
--entry-file index.js \
8+
--dev false \
9+
--bundle-output ./android/main.jsbundle \
10+
--sourcemap-output ./android-sourcemap.json &&
11+
zip ./android-sourcemap.zip ./android-sourcemap.json
12+
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
17+
18+
if [ ! "${APP_TOKEN}" ] || [ -z "${APP_TOKEN}" ];then
19+
echo "Instabug: err: APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.startWithToken"
20+
exit 1
21+
else
22+
echo "Instabug: Uploading files..."
23+
#Upload android sourcemap
24+
curl --data "file=android-sourcemap.json&platform=react_native&os=android&application_token=${APP_TOKEN}" https://api.instabug.com/api/sdk/v3/symbols_files
25+
echo
26+
fi

ios/upload_sourcemap.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cd "${SRCROOT}"
2+
cd ..
3+
#Generate ios sourcemap
4+
react-native bundle --platform ios \
5+
--entry-file index.js \
6+
--dev false \
7+
--bundle-output ./ios/main.jsbundle \
8+
--sourcemap-output ./ios-sourcemap.json &&
9+
zip ./ios-sourcemap.zip ./ios-sourcemap.json
10+
echo "Instabug: Looking for Token..."
11+
if [ ! "${APP_TOKEN}" ]; then
12+
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)
13+
fi
14+
15+
if [ ! "${APP_TOKEN}" ] || [ -z "${APP_TOKEN}" ];then
16+
echo "Instabug: err: APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.startWithToken"
17+
exit 1
18+
else
19+
echo "Instabug: Uploading files..."
20+
#Upload ios sourcemap
21+
curl --data "file=ios-sourcemap.json&platform=react_native&os=ios&application_token=${APP_TOKEN}" https://api.instabug.com/api/sdk/v3/symbols_files
22+
echo
23+
fi
24+

link.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Instabug.framework/strip-frameworks.sh"
2222
SCRIPTEND
2323

24+
INSTABUG_UPLOAD_NAME = "Upload Sourcemap"
25+
26+
INSTABUG_UPLOAD_SCRIPT = <<-SCRIPTEND
27+
bash "../node_modules/instabug-reactnative/ios/upload_sourcemap.sh"
28+
SCRIPTEND
29+
2430
# Get useful variables
2531
project = Xcodeproj::Project.open(project_location)
2632
frameworks_group = project.groups.find { |group| group.display_name == 'Frameworks' }
@@ -68,6 +74,11 @@
6874
#Add New Run Script Phase to Build Phases
6975
phase = target.new_shell_script_build_phase(INSTABUG_PHASE_NAME)
7076
phase.shell_script = INSTABUG_PHASE_SCRIPT
77+
78+
#Add New Run Script Phase to Build Phases
79+
upload_build_phase = target.new_shell_script_build_phase(INSTABUG_UPLOAD_NAME)
80+
upload_build_phase.shell_script = INSTABUG_UPLOAD_SCRIPT
81+
upload_build_phase.run_only_for_deployment_postprocessing = '1'
7182
end
7283

7384
# Save Xcode project

unlink.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
INSTABUG_PHASE_NAME = "Strip Frameworks"
1818

19+
INSTABUG_UPLOAD_NAME = "Upload Sourcemap"
20+
1921
# Get useful variables
2022
project = Xcodeproj::Project.open(project_location)
2123
frameworks_group = project.groups.find { |group| group.display_name == 'Frameworks' }
@@ -45,6 +47,10 @@
4547
#Delete New Run Script Phase from Build Phases
4648
shell_script_build_phase = target.shell_script_build_phases.find { |build_phase| build_phase.to_s == INSTABUG_PHASE_NAME }
4749
target.build_phases.delete(shell_script_build_phase)
50+
51+
#Delete New Run Script Phase from Build Phases
52+
shell_script_build_phase = target.shell_script_build_phases.find { |build_phase| build_phase.to_s == INSTABUG_UPLOAD_NAME }
53+
target.build_phases.delete(shell_script_build_phase)
4854
end
4955

5056
# Save Xcode project

0 commit comments

Comments
 (0)