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

Add more details on how to configure step to generate tmp.xcconfig #503

Merged
merged 1 commit into from
Nov 6, 2020

Conversation

devoto13
Copy link
Contributor

@devoto13 devoto13 commented Oct 5, 2020

Disclaimer: I'm not an iOS developer and I'm barely familiar with how things work here. My team has been hit by this issue and I hope it may help future users of react-native-config.

Can somebody, who actually understands iOS development check if this makes sense before merging? Maybe @maxkomarychev who initially introduced this approach?

@height
Copy link

height bot commented Oct 5, 2020

Link Height tasks by mentioning a task ID in the pull request title or description, commit messages, or comments.

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

@devoto13
Copy link
Contributor Author

devoto13 commented Oct 6, 2020

Apparently one needs to copy-paste same pre-action to every schema they use... Which is not very nice.


7. **Accessing your variable in info.plist**: You can now access your env variable using the prefix `RNC_`, for example `$(RNC_MY_ENV_VARIABLE)`. If you face issues accessing variables, please refer to [this issue](https://github.com/luggit/react-native-config/issues/391#issuecomment-632331803).
7. You can now access your env variables in the Info.plist, for example `$(MY_ENV_VARIABLE)`. If you face issues accessing variables, please open a new issue and provide as much details as possible so above steps can be improved.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems accurate to me. I was wondering why the variables are always empty when using $(RNC_MY_ENV_VARIABLE). It looks like we don't need the RNC_ prefix, it should just be $(MY_ENV_VARIABLE).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure though if this was intended. I feel like having the prefix would be a good idea to avoid accidentally overwriting other existing variables like $(PRODUCT_NAME), $(PRODUCT_BUNDLE_IDENTIFIER), ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that RNC_ prefix is useful, but that would be a breaking change.
Maybe someone can make a separate PR to generate both styles of variables and document using RNC_-prefixed ones, so it is easier to remove unprefixed variables in the next major.

In any case it is more helpful to describe actual behavior (even undesired) than mislead people :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on that. I was just wondering if the variables had the prefix before, or it was just an incorrect statement in README. I updated recently this library in a project from an older version (0.11.7) where the variables were being accesed in Info.plist with __RN_CONFIG_MY_ENV_VARIABLE to the latest version (1.3.3), so I'm not sure if there was some versions in between that were using the RNC_ prefix.

Copy link
Contributor Author

@devoto13 devoto13 Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT 1eb6ac0 removed __RN_CONFIG_ prefix and introduced new approach with .xcconfig file (no prefix) and then bc3ca9d introduced RNC_ prefix if you use previous approach with Info.plist postprocessing, which is no longer documented.

It's messy 🤷

Copy link
Contributor Author

@devoto13 devoto13 Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I guess the reason why older approach was restored at the first place is because .xccconfig was misunderstood/not working properly: #391 (comment).

@@ -217,13 +217,15 @@ ios/tmp.xcconfig
4. go to project settings
5. apply config to your configurations
![img](./readme-pics/3.ios_apply_config.png)
6. create new build phase for the scheme which will generate "tmp.xcconfig" before each build exposing values to Build Settings and Info.plist (this snippet has to be placed after "cp ... ${PROJECT_DIR}/../.env" if [approach explained below](#ios-multi-scheme) is used)
6. Go to _Edit scheme..._ -> _Build_ -> _Pre-actions_, click _+_ and select _New Run Script Action_. Paste below code which will generate "tmp.xcconfig" before each build exposing values to Build Settings and Info.plist. Make sure to select your target under _Provide build settings from_, so `$SRCROOT` environment variables is available to the script. (Note that this snippet has to be placed after "cp ... \${PROJECT_DIR}/../.env" if [approach explained below](#ios-multi-scheme) is used).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me.

README.md Outdated Show resolved Hide resolved
@danielfx90
Copy link

It might be nice to add a post-action script to the readme where the .env file gets removed IF using multi-environment configuration.

With my team we have .env.development, .env.staging and .env.production files. Having a .env file created when building but then keeping it adds noise to the working environment.

The post-action script could be as simple as:
rm "${PROJECT_DIR}/../.env"

@devoto13
Copy link
Contributor Author

devoto13 commented Oct 21, 2020

@danielfx90 I think the easier and cleaner solution to deal with environments is to add .env to .gitignore if that’s what you mean by noise.

@danielfx90
Copy link

No, I meant for any dev not to mix configs when debuging. It sounds that one might edit .env instead of the proper file, lose changes and maybe understand what's happening after a while.

@devoto13
Copy link
Contributor Author

Sounds like a good idea then! IMO it would be better if you submit it as a separate PR though.

@danielfx90
Copy link

I'm not a maintainer here, but IMO this PR looks good to be merged!

@luancurti
Copy link
Collaborator

luancurti commented Nov 6, 2020

I don't have time to review carefully but looks good to me too. Thanks for review @danielfx90 @mlazari

Great job @devoto13 🎉

@luancurti luancurti merged commit f2cea0c into lugg:master Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants