From 3dffbc4e178b1c6d2e7866e0d414e97b49e647b8 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Tue, 16 Mar 2021 01:28:22 -0700 Subject: [PATCH] chore: Add config for exposing environment variables (#318) * add react-native config package * update pods * update sentry config * update docs --- .env.example | 1 + CONTRIBUTING.md | 7 +------ android/app/build.gradle | 1 + index.js | 7 ++----- ios/Podfile.lock | 10 +++++++++- package.json | 4 +++- yarn.lock | 10 ++++++++++ 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index e69de29bb..ab7a23c8a 100644 --- a/.env.example +++ b/.env.example @@ -0,0 +1 @@ +SENTRY_DSN= \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e91257bb5..447b71ee2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,13 +42,8 @@ And install dependencies Create a new project in [Sentry](https://sentry.io/for/react-native/) -Create file sentry under `sentry.js` in root of the project. -Add the following contents. - -``` -export const SENTRY_TOKEN_URL =; -``` +Add `SENTRY_DSN` value in `.env` file. If you want to supports native crashes, link the sentry SDK to your native projects. Run the command diff --git a/android/app/build.gradle b/android/app/build.gradle index c07b1a0bb..32a344b57 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -235,3 +235,4 @@ task copyDownloadableDepsToLibs(type: Copy) { } apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) +apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" diff --git a/index.js b/index.js index 752d24b0f..cbbf8159d 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,11 @@ import { AppRegistry } from 'react-native'; import * as Sentry from '@sentry/react-native'; - +import Config from 'react-native-config'; import { name as appName } from './app.json'; -import { SENTRY_TOKEN_URL } from './sentry'; - import App from './src/app'; AppRegistry.registerComponent(appName, () => App); - Sentry.init({ - dsn: SENTRY_TOKEN_URL, + dsn: Config.SENTRY_DSN, }); diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 868e470de..83fe66223 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -296,6 +296,10 @@ PODS: - React-cxxreact (= 0.63.3) - React-jsi (= 0.63.3) - React-jsinspector (0.63.3) + - react-native-config (1.4.2): + - react-native-config/App (= 1.4.2) + - react-native-config/App (1.4.2): + - React-Core - react-native-document-picker (5.0.0): - React-Core - react-native-image-picker (3.1.4): @@ -445,6 +449,7 @@ DEPENDENCIES: - React-jsi (from `../node_modules/react-native/ReactCommon/jsi`) - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) + - react-native-config (from `../node_modules/react-native-config`) - react-native-document-picker (from `../node_modules/react-native-document-picker`) - react-native-image-picker (from `../node_modules/react-native-image-picker`) - "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)" @@ -537,6 +542,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/jsiexecutor" React-jsinspector: :path: "../node_modules/react-native/ReactCommon/jsinspector" + react-native-config: + :path: "../node_modules/react-native-config" react-native-document-picker: :path: "../node_modules/react-native-document-picker" react-native-image-picker: @@ -639,6 +646,7 @@ SPEC CHECKSUMS: React-jsi: df07aa95b39c5be3e41199921509bfa929ed2b9d React-jsiexecutor: b56c03e61c0dd5f5801255f2160a815f4a53d451 React-jsinspector: 8e68ffbfe23880d3ee9bafa8be2777f60b25cbe2 + react-native-config: c98128a72bc2c3a1ca72caec0b021f0fa944aa29 react-native-document-picker: ca0c8769c3848866970dc9164e809c6ea45cb5d6 react-native-image-picker: 28d8d1f5a643119876b8b2c7d4d1dcfb2b232dd4 react-native-netinfo: 30fb89fa913c342be82a887b56e96be6d71201dd @@ -675,4 +683,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 359eeed31941826235cdc4a3c6b998cb2e176764 -COCOAPODS: 1.10.0 +COCOAPODS: 1.10.1 diff --git a/package.json b/package.json index 44e3bb718..6373f54c7 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "react-native-actions-sheet": "^0.4.2", "react-native-animatable": "^1.3.3", "react-native-background-color": "^0.0.8", + "react-native-config": "^1.4.2", "react-native-device-info": "^5.6.5", "react-native-document-picker": "^5.0.0", "react-native-exception-handler": "^2.10.9", @@ -64,7 +65,8 @@ "redux-persist": "^6.0.0", "redux-thunk": "^2.3.0", "tcomb-form-native": "^0.6.20", - "validator": "^13.5.2" + "validator": "^13.5.2", + "yarn": "^1.22.10" }, "devDependencies": { "@babel/core": "^7.8.4", diff --git a/yarn.lock b/yarn.lock index 12e787ea6..c52d7a3b5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7374,6 +7374,11 @@ react-native-background-color@^0.0.8: resolved "https://registry.yarnpkg.com/react-native-background-color/-/react-native-background-color-0.0.8.tgz#661f737156a18a86ece362126e9c97e33fa42ed2" integrity sha512-Or89KCBNyFsD0234g/MgWyRrhwtd5egHXdqUwal1e5FKpum8d/x1y5PQqF3OUFR0W/ztp5Vt3FaLc/LEY0Fy+Q== +react-native-config@^1.4.2: + version "1.4.2" + resolved "https://registry.yarnpkg.com/react-native-config/-/react-native-config-1.4.2.tgz#cc39f22ed72c5cb06af1adf0ba70ef01593900b4" + integrity sha512-iTvCvThvFTH7SdiBcsxYtpLy86zglsh51ZBqFPPZ75tdrQMdlRnDNnb86kNjQf03KT0qs1nCMLRejfPMIim8iA== + react-native-device-info@^5.6.5: version "5.6.5" resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-5.6.5.tgz#3f18d7c38b21cfc475163351a9aae6e9037a43a0" @@ -9490,3 +9495,8 @@ yargs@^15.1.0, yargs@^15.3.1: which-module "^2.0.0" y18n "^4.0.0" yargs-parser "^18.1.2" + +yarn@^1.22.10: + version "1.22.10" + resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.10.tgz#c99daa06257c80f8fa2c3f1490724e394c26b18c" + integrity sha512-IanQGI9RRPAN87VGTF7zs2uxkSyQSrSPsju0COgbsKQOOXr5LtcVPeyXWgwVa0ywG3d8dg6kSYKGBuYK021qeA==