maxkomarychev / react-native-ultimate-config

Config that works
MIT License
261 stars 31 forks source link

How to access from shell scripts #93

Open JeremyBradshaw7 opened 2 years ago

JeremyBradshaw7 commented 2 years ago

I'm migrating from react-native-config and trying to access some of the environment variables from a shell script after initiating the rnuc utility. I have this working like this which is an adjustment from how I had it working from react-native-config:

# Get current version from production env file
yarn rnuc .env.prod
set -o allexport; source ios/rnuc.xcconfig; set +o allexport
echo "Current version: ${APP_VERSION}"

But is there a better/simpler recommended way? I cant see it in the docs.

What does the rnuc utility write to the android project by the way? Whatever it is seems to disappear after running yarn so I've put a postinstall script in my package.json to run yarn rnuc .env - again if that's the best way perhaps it could be added to the readme.

maxkomarychev commented 2 years ago

Can you give an example of how it used to work with react-native-config?

maxkomarychev commented 2 years ago

What does the rnuc utility write to the android project by the way? Whatever it is seems to disappear after running yarn so I've put a postinstall script in my package.json to run yarn rnuc .env - again if that's the best way perhaps it could be added to the readme.

can you please elaborate on this a bit? can you suggest exact copy which could help to avoid this confusion? Feel free to submit pr too =)

JeremyBradshaw7 commented 2 years ago

Can you give an example of how it used to work with react-native-config?

react-native-config relied in setting an ENVFILE environment variable to point to whatever .env file should be the source of all config variables, so to expose the variables from that file in a script what I had was:

set -o allexport; source $ENVFILE; set +o allexport

I don't recall where I got this from however, it's not in their README - I think maybe I plucked it from this thread. I just need to know the recommended way to access the settings from this package's "current" config in a shell script.

maxkomarychev commented 2 years ago

Ok. While I do not natively support this it is still possible to simply source your env file as long as this file is a dotenv one.

If you're using YAML then it's going to be tricky but using xcconfig maybe an acceptable workaround.

ghost commented 1 year ago

If your just trying to add secrets from yoour bash profile you could try this:

module.exports = {
  js_override: true,
  on_env: async function (env) {
    // append process.env 
    return {
      ...env,
      API_KEY: process.env._API_KEY
    }
  }
};