From e88760a9ba97bc49682f8b15359cb378908cba95 Mon Sep 17 00:00:00 2001 From: Muhammad Numan Date: Wed, 26 Jul 2023 00:24:49 +0500 Subject: [PATCH] docs: add migration guide for react-native-config --- README.md | 5 +++-- docs/react-native-config-migration-guide.md | 12 ++++++++++++ example/keys.development.json | 2 +- example/keys.production.json | 2 +- example/keys.staging.json | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 docs/react-native-config-migration-guide.md diff --git a/README.md b/README.md index ba60d36..79ff32d 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ ### Why should we use react-native-keys over react-native-config? 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 +#### See the [ Migration from react-native-config](docs/react-native-config-migration-guide.md)
@@ -36,7 +37,7 @@ We can Manage **secure**(undecryptable) and **public** enviroment through **reac Buy Me A Coffee
-## See the [How we are protecting ENVs on the app side?](docs/workflow.md) +#### See the [How we are protecting ENVs on the app side?](docs/workflow.md) ## Installation @@ -58,7 +59,7 @@ Create a new file `keys.development.json` in the root of your React Native app a "APP_NAME": "Keys Example", "BUNDLE_ID": "com.example.rnkeys.dev", "ANDROID_CODE": "50", - "PACKGE_ID": "com.example.rnkeys.dev" + "PACKAGE_ID": "com.example.rnkeys.dev" } } ``` diff --git a/docs/react-native-config-migration-guide.md b/docs/react-native-config-migration-guide.md new file mode 100644 index 0000000..5e3ea95 --- /dev/null +++ b/docs/react-native-config-migration-guide.md @@ -0,0 +1,12 @@ +# Migration from react-native-config + +| react-native-config | react-native-keys | +| ---- | ----- | +| .env.development

BASE_URL=https://www.example.com
APP_NAME=Example
GOOGLE_API=ABCDEF
BRANCH_API=ABCDEF
PACKAGE_ID=com.example.rnkeys.dev
| keys.development.json

{
  "secure": {
    "GOOGLE_API": "ABCD",
    "BRANCH_API": "ABCDEF"
  },
  "public": {
   "APP_NAME": "dev RNKEYS",
    "PACKAGE_ID": "com.example.rnkeys.dev"
  }
}
| +| Android: apply a plugin to your app, from android/app/build.gradle:

apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" | Android: apply a plugin to your app, from android/app/build.gradle:

apply from: project(':react-native-keys').projectDir.getPath() + "/RNKeys.gradle" | +|Android (build.gradle):
project.ext.envConfigFiles = [
debug: ".env.development",
release: ".env.production",
anothercustombuild: ".env",
]
|Android (build.gradle):
project.ext.keyFiles = [
debug: "keys.development.json",
release: "keys.staging.json",
release: "keys.json",
]
| +|Android (.Java File):
BuildConfig.GOOGLE_MAPS_API_KEY
BuildConfig.PACKAGE_ID
|Android (.Java File):
import static com.reactnativekeysjsi.KeysModule.getSecureFor;

getSecureFor("GOOGLE_MAPS_API_KEY")

BuildConfig.PACKAGE_ID
| +| Android: You can also read them from your Gradle configuration:
defaultConfig {
applicationId project.env.get("APP_ID")
}
| Android: You can also read them from your Gradle configuration:
defaultConfig {
applicationId project.keys.get("APP_ID")
}
| +|
import Config from "react-native-config";

Config.GOOGLE_MAPS_API_KEY;
Config.PACKAGE_ID;
|
import Keys from 'react-native-keys';

Keys.secureFor('GOOGLE_MAPS_API_KEY');
Keys.PACKAGE_ID;
| +| IOS
#import "RNCConfig.h"

NSString *googleMapApiKey = [RNCConfig envFor:@"GOOGLE_MAPS_API_KEY"];
NSString *appName = [RNCConfig envFor:@"APP_NAME"];
| IOS
#import "Keys.h"

NSString *googleMapApiKey = [Keys secureFor:@"GOOGLE_MAPS_API_KEY"];
NSString *appName = [Keys publicFor:@"APP_NAME"];
| +|IOS

Go to Edit scheme... -> Build -> Pre-actions,
click + and select New Run Script Action

"`$`{SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb"
"`$`{SRCROOT}/.." "`$`{SRCROOT}/tmp.xcconfig"
|IOS

Go to Edit scheme... -> Build -> Pre-actions,
click + and select New Run Script Action

export KEYSFILE=keys.development.json
"`$`{SRCROOT}/../node_modules/react-native-keys/keysIOS.js"
| diff --git a/example/keys.development.json b/example/keys.development.json index 00a9a0c..259d5e1 100644 --- a/example/keys.development.json +++ b/example/keys.development.json @@ -10,7 +10,7 @@ "APP_NAME": "dev RNKEYS", "BUNDLE_ID": "com.example.rnkeys.dev", "ANDROID_CODE": "50", - "PACKGE_ID": "com.example.rnkeys.dev", + "PACKAGE_ID": "com.example.rnkeys.dev", "public1": "dev numan", "public2": "dev usman" } diff --git a/example/keys.production.json b/example/keys.production.json index b5968fd..27a7108 100644 --- a/example/keys.production.json +++ b/example/keys.production.json @@ -10,7 +10,7 @@ "APP_NAME": "prod RNKEYS", "BUNDLE_ID": "com.example.rnkeys.prod", "ANDROID_CODE": "50", - "PACKGE_ID": "com.example.rnkeys.prod", + "PACKAGE_ID": "com.example.rnkeys.prod", "public1": "prod numan", "public2": "prod usman" } diff --git a/example/keys.staging.json b/example/keys.staging.json index 6d00781..2d34232 100644 --- a/example/keys.staging.json +++ b/example/keys.staging.json @@ -10,7 +10,7 @@ "APP_NAME": "staging RNKEYS", "BUNDLE_ID": "com.example.rnkeys.staging", "ANDROID_CODE": "50", - "PACKGE_ID": "com.example.rnkeys.staging", + "PACKAGE_ID": "com.example.rnkeys.staging", "public1": "staging numan", "public2": "staging usman" }