From eb6cbb9d9de334fd36c2264cdfd2eeb33efdb74b Mon Sep 17 00:00:00 2001 From: Harjot Singh Date: Tue, 11 Jan 2022 18:43:03 +0000 Subject: [PATCH] build: use react-native-config over original dotenv approach --- .github/workflows/release-next.yml | 1 + Gemfile | 1 - Gemfile.lock | 1 - android/app/build.gradle | 1 + babel.config.js | 2 +- config/README.md | 2 +- fastlane/Fastfile | 1 - fastlane/load_env.rb | 11 -- ios/Podfile.lock | 8 ++ package-lock.json | 181 +++++++---------------------- package.json | 9 +- 11 files changed, 56 insertions(+), 162 deletions(-) delete mode 100644 fastlane/load_env.rb diff --git a/.github/workflows/release-next.yml b/.github/workflows/release-next.yml index 1aa6277e..25d76f9d 100644 --- a/.github/workflows/release-next.yml +++ b/.github/workflows/release-next.yml @@ -19,6 +19,7 @@ env: UPLOAD_KEYSTORE_PASSWORD: ${{ secrets.UPLOAD_KEYSTORE_PASSWORD }} UPLOAD_KEYSTORE_KEY_ALIAS: ${{ secrets.UPLOAD_KEYSTORE_KEY_ALIAS }} UPLOAD_KEYSTORE_KEY_PASSWORD: ${{ secrets.UPLOAD_KEYSTORE_KEY_PASSWORD }} + ENVFILE: config/.env.next jobs: prepare: diff --git a/Gemfile b/Gemfile index a4f95c66..2ca40b2e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,6 @@ source 'https://rubygems.org' gem 'fastlane', '~> 2.199.0' -gem 'dotenv', '~> 2.1', '>= 2.1.1' plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') eval_gemfile(plugins_path) if File.exist?(plugins_path) diff --git a/Gemfile.lock b/Gemfile.lock index de7aa980..966d3b5d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -221,7 +221,6 @@ PLATFORMS x86_64-linux DEPENDENCIES - dotenv (~> 2.1, >= 2.1.1) fastlane (~> 2.199.0) fastlane-plugin-appicon fastlane-plugin-badge diff --git a/android/app/build.gradle b/android/app/build.gradle index 058985af..48806d8c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,4 +1,5 @@ apply plugin: "com.android.application" +apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" import com.android.build.OutputFile diff --git a/babel.config.js b/babel.config.js index 4f9edce8..fb7e9206 100644 --- a/babel.config.js +++ b/babel.config.js @@ -12,7 +12,7 @@ module.exports = { plugins: [ 'transform-remove-console' ], }, test: { - plugins: [ 'transform-remove-console' ], + plugins: [ 'react-native-config-node/transform', 'transform-remove-console' ], }, }, } diff --git a/config/README.md b/config/README.md index 5e875230..1bd40d9c 100644 --- a/config/README.md +++ b/config/README.md @@ -4,7 +4,7 @@ This app follows the [12 factor app](https://12factor.net/config) approach to co _Currently, build configuration in [`fastlane/`](../fastlane) is not configurable through these files._ -Specific dotenv files can be loaded by Fastlane by supplying `app_env:name` as an option to any commands. For example, `fastlane ios build app_env:next` would load the variables from `config/.env.next` and make these available to the app. +Specific dotenv files can be loaded by supplying an `ENVFILE` environment variable to any command. For example, `ENVFILE=config/.env.next fastlane ios build` would load the variables from `config/.env.next` and make these available to the app. ## Environments diff --git a/fastlane/Fastfile b/fastlane/Fastfile index b85b6d92..c8e91afb 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -1,4 +1,3 @@ import './utils.rb' -import './load_env.rb' import './Fastfile.ios' import './Fastfile.android' diff --git a/fastlane/load_env.rb b/fastlane/load_env.rb deleted file mode 100644 index bf5d351f..00000000 --- a/fastlane/load_env.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'dotenv' - -before_all do |lane, options| - puts options - environment = options[:app_env] || 'local' - - env_file = ".env.#{environment}" - - puts "Loading #{env_file}" - Dotenv.overload("../config/#{env_file}") -end diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 4ed2d31e..20f15489 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -290,6 +290,10 @@ PODS: - React-jsinspector (0.66.3) - React-logger (0.66.3): - glog + - react-native-config (1.4.5): + - react-native-config/App (= 1.4.5) + - react-native-config/App (1.4.5): + - React-Core - react-native-safe-area-context (3.3.2): - React-Core - React-perflogger (0.66.3) @@ -447,6 +451,7 @@ DEPENDENCIES: - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) - React-logger (from `../node_modules/react-native/ReactCommon/logger`) + - react-native-config (from `../node_modules/react-native-config`) - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) - React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`) @@ -524,6 +529,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/jsinspector" React-logger: :path: "../node_modules/react-native/ReactCommon/logger" + react-native-config: + :path: "../node_modules/react-native-config" react-native-safe-area-context: :path: "../node_modules/react-native-safe-area-context" React-perflogger: @@ -600,6 +607,7 @@ SPEC CHECKSUMS: React-jsiexecutor: 433a691aee158533a6a6ee9c86cb4a1684fa2853 React-jsinspector: d9c8eb0b53f0da206fed56612b289fec84991157 React-logger: e522e76fa3e9ec3e7d7115b49485cc065cf4ae06 + react-native-config: 6502b1879f97ed5ac570a029961fc35ea606cd14 react-native-safe-area-context: 584dc04881deb49474363f3be89e4ca0e854c057 React-perflogger: 73732888d37d4f5065198727b167846743232882 React-RCTActionSheet: 96c6d774fa89b1f7c59fc460adc3245ba2d7fd79 diff --git a/package-lock.json b/package-lock.json index 9b9586b0..453b8e50 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "react": "^17.0.2", "react-i18next": "^11.14.3", "react-native": "^0.66.3", + "react-native-config": "^1.4.5", "react-native-gesture-handler": "^1.10.3", "react-native-reanimated": "^2.2.4", "react-native-safe-area-context": "^3.3.2", @@ -46,7 +47,6 @@ "@typescript-eslint/parser": "^5.4.0", "babel-jest": "^27.4.2", "babel-plugin-transform-remove-console": "^6.9.4", - "dotenv-cli": "^4.1.1", "eslint": "^8.3.0", "eslint-config-airbnb": "^19.0.1", "eslint-config-airbnb-typescript": "^16.0.0", @@ -68,6 +68,7 @@ "npm-run-all": "^4.1.5", "pod-install": "^0.1.29", "prettier": "2.5.0", + "react-native-config-node": "^0.0.3", "react-test-renderer": "^17.0.2", "typescript": "^4.5.2" }, @@ -6873,86 +6874,6 @@ "node": ">=10" } }, - "node_modules/dotenv-cli": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-4.1.1.tgz", - "integrity": "sha512-XvKv1pa+UBrsr3CtLGBsR6NdsoS7znqaHUf4Knj0eZO+gOI/hjj9KgWDP+KjpfEbj6wAba1UpbhaP9VezNkWhg==", - "dev": true, - "dependencies": { - "cross-spawn": "^7.0.1", - "dotenv": "^8.1.0", - "dotenv-expand": "^5.1.0", - "minimist": "^1.1.3" - }, - "bin": { - "dotenv": "cli.js" - } - }, - "node_modules/dotenv-cli/node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", - "dev": true, - "dependencies": { - "path-key": "^3.1.0", - "shebang-command": "^2.0.0", - "which": "^2.0.1" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/dotenv-cli/node_modules/path-key": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", - "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/dotenv-cli/node_modules/shebang-command": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", - "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, - "dependencies": { - "shebang-regex": "^3.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/dotenv-cli/node_modules/shebang-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", - "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/dotenv-cli/node_modules/which": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/dotenv-expand": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-5.1.0.tgz", - "integrity": "sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==", - "dev": true - }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -14972,6 +14893,28 @@ "nullthrows": "^1.1.1" } }, + "node_modules/react-native-config": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/react-native-config/-/react-native-config-1.4.5.tgz", + "integrity": "sha512-5oiAsoW88SOYDg/0cleJ2vJDqv98FJUbFQYEnH4sdMtEn3AAT3lb7BkTGW8HO/t3Vk9VOruwxUUnO4tzuxzCsw==", + "peerDependencies": { + "react-native-windows": ">=0.61" + }, + "peerDependenciesMeta": { + "react-native-windows": { + "optional": true + } + } + }, + "node_modules/react-native-config-node": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/react-native-config-node/-/react-native-config-node-0.0.3.tgz", + "integrity": "sha512-AZgVrUxJtEvQqSN2W5zlVdZDbxTn9YNohUfQ51SCPASlYSU0Nx3G8m8+9XSWUv0iN66rwPNoywPrhxwr/V9OVg==", + "dev": true, + "dependencies": { + "dotenv": "^8.2.0" + } + }, "node_modules/react-native-gesture-handler": { "version": "1.10.3", "resolved": "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-1.10.3.tgz", @@ -22622,67 +22565,6 @@ "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==", "dev": true }, - "dotenv-cli": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-4.1.1.tgz", - "integrity": "sha512-XvKv1pa+UBrsr3CtLGBsR6NdsoS7znqaHUf4Knj0eZO+gOI/hjj9KgWDP+KjpfEbj6wAba1UpbhaP9VezNkWhg==", - "dev": true, - "requires": { - "cross-spawn": "^7.0.1", - "dotenv": "^8.1.0", - "dotenv-expand": "^5.1.0", - "minimist": "^1.1.3" - }, - "dependencies": { - "cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", - "dev": true, - "requires": { - "path-key": "^3.1.0", - "shebang-command": "^2.0.0", - "which": "^2.0.1" - } - }, - "path-key": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", - "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true - }, - "shebang-command": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", - "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, - "requires": { - "shebang-regex": "^3.0.0" - } - }, - "shebang-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", - "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true - }, - "which": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, - "requires": { - "isexe": "^2.0.0" - } - } - } - }, - "dotenv-expand": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-5.1.0.tgz", - "integrity": "sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==", - "dev": true - }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -28952,6 +28834,21 @@ "nullthrows": "^1.1.1" } }, + "react-native-config": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/react-native-config/-/react-native-config-1.4.5.tgz", + "integrity": "sha512-5oiAsoW88SOYDg/0cleJ2vJDqv98FJUbFQYEnH4sdMtEn3AAT3lb7BkTGW8HO/t3Vk9VOruwxUUnO4tzuxzCsw==", + "requires": {} + }, + "react-native-config-node": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/react-native-config-node/-/react-native-config-node-0.0.3.tgz", + "integrity": "sha512-AZgVrUxJtEvQqSN2W5zlVdZDbxTn9YNohUfQ51SCPASlYSU0Nx3G8m8+9XSWUv0iN66rwPNoywPrhxwr/V9OVg==", + "dev": true, + "requires": { + "dotenv": "^8.2.0" + } + }, "react-native-gesture-handler": { "version": "1.10.3", "resolved": "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-1.10.3.tgz", diff --git a/package.json b/package.json index bad110e7..7f657eee 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,10 @@ "scripts": { "lint": "eslint . --ext .js,.jsx,.ts,.tsx --color", "test:types": "tsc --pretty", - "test:unit": "dotenv -e ./config/.env.local jest --color", + "test:unit": "ENVFILE=config/.env.local jest --color", "test": "run-p -l test:*", - "emulator:android": "dotenv -e ./config/.env.local react-native run-android", - "emulator:ios": "dotenv -e ./config/.env.local react-native run-ios --simulator='iPhone 8'", + "emulator:android": "ENVFILE=config/.env.local react-native run-android", + "emulator:ios": "ENVFILE=config/.env.local react-native run-ios --simulator='iPhone 8'", "start:android": "run-p -l emulator:android \"test:* -- --watch\"", "start:ios": "run-p -l emulator:ios \"test:* -- --watch\"", "build:android": "bundle exec fastlane android build", @@ -40,6 +40,7 @@ "react": "^17.0.2", "react-i18next": "^11.14.3", "react-native": "^0.66.3", + "react-native-config": "^1.4.5", "react-native-gesture-handler": "^1.10.3", "react-native-reanimated": "^2.2.4", "react-native-safe-area-context": "^3.3.2", @@ -64,7 +65,6 @@ "@typescript-eslint/parser": "^5.4.0", "babel-jest": "^27.4.2", "babel-plugin-transform-remove-console": "^6.9.4", - "dotenv-cli": "^4.1.1", "eslint": "^8.3.0", "eslint-config-airbnb": "^19.0.1", "eslint-config-airbnb-typescript": "^16.0.0", @@ -86,6 +86,7 @@ "npm-run-all": "^4.1.5", "pod-install": "^0.1.29", "prettier": "2.5.0", + "react-native-config-node": "^0.0.3", "react-test-renderer": "^17.0.2", "typescript": "^4.5.2" }