Skip to content

Commit 38c5f60

Browse files
committed
🐛 (ios) fix env retreiving on runtime
1 parent f71bf9d commit 38c5f60

File tree

6 files changed

+11
-12
lines changed

6 files changed

+11
-12
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<h1 align="center">React Native Config</h1>
22

33
<p align="center">Module to expose config variables to your javascript code in React Native, supporting both iOS and Android.</p>
4-
<p align="center">Bring some [12 factor](http://12factor.net/config) love to your mobile apps!</p>
5-
<p align="center">Forked from [luggit's repo](https://github.com/luggit/react-native-config)</p>
4+
<p align="center">Bring some <a href="http://12factor.net/config">12 factor</a> love to your mobile apps!</p>
5+
<p align="center">Forked from <a href="https://github.com/luggit/react-native-config">luggit's repo</a></p>
66

77
<p align="center">
88

@@ -86,14 +86,15 @@ pod install
8686

8787
# react-native-config codegen
8888
ios/react-native-config.xcconfig
89+
ios/envfile
8990
```
9091

9192
- In the Xcode menu, go to Product > Scheme > Edit Scheme
9293
- Expand the "Build" settings on left
9394
- Click "Pre-actions", and under the plus sign select "New Run Script Action"
9495
- Where it says "Type a script or drag a script file", type:
9596
```
96-
ENVFILE=.env ${SRCROOT}/../node_modules/@bam.tech/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb ${SRCROOT}/.. ${SRCROOT}/react-native-config.xcconfig
97+
echo ".env.development" > "${SRCROOT}/envfile"
9798
```
9899

99100
### Optional : Multi-environment support
@@ -114,7 +115,7 @@ For each environment, use the following step (and change `ANOTHER_ENV` by your e
114115
## Javascript
115116

116117
```js
117-
import Config from '@bam.tech/react-native-config';
118+
import Config from "@bam.tech/react-native-config";
118119

119120
Config.API_URL; // 'https://myapi.com'
120121
Config.GOOGLE_MAPS_API_KEY; // 'abcdefgh'
@@ -195,12 +196,12 @@ export default {
195196
```js
196197
// __mocks__/@bam.tech/react-native-config.js
197198

198-
import fs from 'fs';
199-
import path from 'path';
199+
import fs from "fs";
200+
import path from "path";
200201

201-
import dotenv from 'dotenv';
202+
import dotenv from "dotenv";
202203

203-
const buf = fs.readFileSync(path.resolve(__dirname, '..', '..', '.env'));
204+
const buf = fs.readFileSync(path.resolve(__dirname, "..", "..", ".env"));
204205
const config = dotenv.parse(buf);
205206

206207
export default config;

ios/ReactNativeConfig/BuildDotenvConfig.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@
2525
path = File.join(m_output_path, 'GeneratedDotEnv.m')
2626
File.open(path, 'w') { |f| f.puts template }
2727

28-
File.delete('/tmp/envfile') if custom_env
29-
3028
puts "Wrote to #{path}"

ios/ReactNativeConfig/ReadDotEnv.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def read_dot_env(envs_root)
1212
puts "going to read env file from root folder #{envs_root}"
1313

1414
# pick a custom env file if set
15-
if File.exist?('/tmp/envfile')
15+
if File.exist?("#{envs_root}/ios/envfile")
1616
custom_env = true
17-
file = File.read('/tmp/envfile').strip
17+
file = File.read("#{envs_root}/ios/envfile").strip
1818
else
1919
custom_env = false
2020
file = ENV['ENVFILE'] || defaultEnvFile

readme-pics/1.ios_new_file.png

-599 KB
Binary file not shown.

readme-pics/2.ios_file_type.png

-269 KB
Binary file not shown.

readme-pics/3.ios_apply_config.png

-437 KB
Binary file not shown.

0 commit comments

Comments
 (0)