Skip to content

Commit ecca0a4

Browse files
authored
Merge pull request #33 from numandev1/docs/migration-config
docs: add migration guide for react-native-config
2 parents c537538 + e88760a commit ecca0a4

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Why should we use react-native-keys over react-native-config?
66

77
We should use **react-native-keys** instead of **react-native-config** because **react-native-keys** gives guarantee of undecryptable **envs** whereas **react-native-config** **envs** can be decompile and hack
8+
#### See the [ Migration from react-native-config](docs/react-native-config-migration-guide.md)
89

910
<div align="center">
1011
<img align="right" width="250" style="margin-right: 55px;" src="./media/key.png">
@@ -36,7 +37,7 @@ We can Manage **secure**(undecryptable) and **public** enviroment through **reac
3637
<a href="https://www.buymeacoffee.com/numan.dev" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
3738
</div>
3839

39-
## See the [How we are protecting ENVs on the app side?](docs/workflow.md)
40+
#### See the [How we are protecting ENVs on the app side?](docs/workflow.md)
4041

4142
## Installation
4243

@@ -58,7 +59,7 @@ Create a new file `keys.development.json` in the root of your React Native app a
5859
"APP_NAME": "Keys Example",
5960
"BUNDLE_ID": "com.example.rnkeys.dev",
6061
"ANDROID_CODE": "50",
61-
"PACKGE_ID": "com.example.rnkeys.dev"
62+
"PACKAGE_ID": "com.example.rnkeys.dev"
6263
}
6364
}
6465
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Migration from react-native-config
2+
3+
| react-native-config | react-native-keys |
4+
| ---- | ----- |
5+
| <code>.env.development</code><br/><br/> <pre>BASE_URL=https://www.example.com<br/>APP_NAME=Example<br/>GOOGLE_API=ABCDEF<br/>BRANCH_API=ABCDEF<br/>PACKAGE_ID=com.example.rnkeys.dev</pre> | <code>keys.development.json</code><br/><br/> <pre>{<br/>&nbsp;&nbsp;"secure": { <br/>&nbsp;&nbsp;&nbsp;&nbsp;"GOOGLE_API": "ABCD", <br/>&nbsp;&nbsp;&nbsp;&nbsp;"BRANCH_API": "ABCDEF" <br/>&nbsp;&nbsp;},<br/>&nbsp;&nbsp;"public": {<br/> &nbsp;&nbsp;&nbsp;"APP_NAME": "dev RNKEYS",<br/>&nbsp;&nbsp;&nbsp;&nbsp;"PACKAGE_ID": "com.example.rnkeys.dev"<br/>&nbsp;&nbsp;} <br/>}</pre>|
6+
| <b>Android:</b> apply a plugin to your app, from <code>android/app/build.gradle</code>:<br/><br/><code>apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"</code> | <b>Android:</b> apply a plugin to your app, from <code>android/app/build.gradle</code>:<br/></br><code>apply from: project(':react-native-keys').projectDir.getPath() + "/RNKeys.gradle"</code> |
7+
|<b>Android (build.gradle):</b></br><pre>project.ext.envConfigFiles = [</br> debug: ".env.development",</br> release: ".env.production",</br> anothercustombuild: ".env",</br>]</pre>|<b>Android (build.gradle):</b></br><pre>project.ext.keyFiles = [</br> debug: "keys.development.json",</br> release: "keys.staging.json", </br> release: "keys.json",</br>]</pre>|
8+
|<b>Android (.Java File):</b></br><pre>BuildConfig.GOOGLE_MAPS_API_KEY</br>BuildConfig.PACKAGE_ID</pre>|<b><b>Android (.Java File):</b></br><pre>import static com.reactnativekeysjsi.KeysModule.getSecureFor;</br></br>getSecureFor("GOOGLE_MAPS_API_KEY")</br></br>BuildConfig.PACKAGE_ID</pre>|
9+
| <b>Android:</b> You can also read them from your Gradle configuration:<br/><pre>defaultConfig {<br/>applicationId project.env.get("APP_ID")<br/>}</pre> | <b>Android:</b> You can also read them from your Gradle configuration:<br/><pre>defaultConfig {<br/>applicationId project.keys.get("APP_ID")<br/>}</pre> |
10+
| <pre>import Config from "react-native-config";</br></br>Config.GOOGLE_MAPS_API_KEY;</br>Config.PACKAGE_ID;</pre> | <pre>import Keys from 'react-native-keys';</br></br>Keys.secureFor('GOOGLE_MAPS_API_KEY');</br>Keys.PACKAGE_ID;</pre> |
11+
| <b>IOS</b></br><pre>#import "RNCConfig.h"</br></br>NSString *googleMapApiKey = [RNCConfig envFor:@"GOOGLE_MAPS_API_KEY"];</br>NSString *appName = [RNCConfig envFor:@"APP_NAME"];</pre> | <b>IOS</b></br><pre>#import "Keys.h"</br></br>NSString *googleMapApiKey = [Keys secureFor:@"GOOGLE_MAPS_API_KEY"];</br>NSString *appName = [Keys publicFor:@"APP_NAME"];</pre> |
12+
|<b>IOS</br></br><code>Go to Edit scheme... -> Build -> Pre-actions,</br> click + and select New Run Script Action</code></br><pre>"`$`{SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb"</br>"`$`{SRCROOT}/.." "`$`{SRCROOT}/tmp.xcconfig"</pre>|<b>IOS</br></br><code>Go to Edit scheme... -> Build -> Pre-actions,</br> click + and select New Run Script Action</code></br><pre>export KEYSFILE=keys.development.json</br>"`$`{SRCROOT}/../node_modules/react-native-keys/keysIOS.js"</pre>|

example/keys.development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"APP_NAME": "dev RNKEYS",
1111
"BUNDLE_ID": "com.example.rnkeys.dev",
1212
"ANDROID_CODE": "50",
13-
"PACKGE_ID": "com.example.rnkeys.dev",
13+
"PACKAGE_ID": "com.example.rnkeys.dev",
1414
"public1": "dev numan",
1515
"public2": "dev usman"
1616
}

example/keys.production.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"APP_NAME": "prod RNKEYS",
1111
"BUNDLE_ID": "com.example.rnkeys.prod",
1212
"ANDROID_CODE": "50",
13-
"PACKGE_ID": "com.example.rnkeys.prod",
13+
"PACKAGE_ID": "com.example.rnkeys.prod",
1414
"public1": "prod numan",
1515
"public2": "prod usman"
1616
}

example/keys.staging.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"APP_NAME": "staging RNKEYS",
1111
"BUNDLE_ID": "com.example.rnkeys.staging",
1212
"ANDROID_CODE": "50",
13-
"PACKGE_ID": "com.example.rnkeys.staging",
13+
"PACKAGE_ID": "com.example.rnkeys.staging",
1414
"public1": "staging numan",
1515
"public2": "staging usman"
1616
}

0 commit comments

Comments
 (0)