react-native-ultimate-config icon indicating copy to clipboard operation
react-native-ultimate-config copied to clipboard

How to access from shell scripts

Open JeremyBradshaw7 opened this issue 2 years ago • 5 comments

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.

JeremyBradshaw7 avatar Apr 26 '22 08:04 JeremyBradshaw7

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

maxkomarychev avatar May 24 '22 07:05 maxkomarychev

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 =)

maxkomarychev avatar May 24 '22 07:05 maxkomarychev

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.

JeremyBradshaw7 avatar May 25 '22 08:05 JeremyBradshaw7

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.

maxkomarychev avatar May 31 '22 20:05 maxkomarychev

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
    }
  }
};

ghost avatar May 11 '23 13:05 ghost