Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access from shell scripts #93

Open
JeremyBradshaw7 opened this issue Apr 26, 2022 · 5 comments
Open

How to access from shell scripts #93

JeremyBradshaw7 opened this issue Apr 26, 2022 · 5 comments
Labels
question Further information is requested

Comments

@JeremyBradshaw7
Copy link

JeremyBradshaw7 commented Apr 26, 2022

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
Copy link
Owner

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

@maxkomarychev
Copy link
Owner

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
Copy link
Author

JeremyBradshaw7 commented May 25, 2022

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
Copy link
Owner

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
Copy link

ghost commented May 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants