maxkomarychev / react-native-ultimate-config

Config that works
MIT License
262 stars 31 forks source link

Ability for xcode to run an rnuc command #7

Closed ahartzog closed 4 years ago

ahartzog commented 4 years ago

Hey Max,

This is more of a feature request than an issue report. Also, please tell me if I'm getting annoying :-P.

During my every day dev, the rnuc scripts inside my npm scripts work perfectly well for dev/staging environments.

However, manually setting the environment via npm for xcode leaves plenty of room for error (and wouldn't work if you're doing it in some sort of pipeline)

So the question is, inside a specific schema (or for archive), how can I have it run an rnuc command from inside the build pre-actions?

Something like... image

I barely know what I'm doing with bash/xcode so I'm quite unfamiliar with how these work. I figure you'll get other people asking the same thing, so if this is the right approach to have it set up a particular set of environment variables on build then you could update the documentation to explain this.

ahartzog commented 4 years ago

I set up a build pre-action to accomplish this:

image

Could do the same for archive ofc.

ahartzog commented 4 years ago

I'd probably recommend adding a "how to" on this, or you're going to get this question again. Explain that it has nothing to do with the library really, it's just something people will probably want to do to associate schemes with different environments.

ahartzog commented 4 years ago

image

Using srcroot correctly so it'll work anywhere (obviously the .deploy/.stage.env would need to be adjusted to wherever the user's env files are placed)


#goes to the workspace root

cd "$SRCROOT" 

#up one level

cd ..

#run the actual NPM script to set the environment variables

npm run rnuc '.deploy/.stage.env'

echo "build pre action script finished" >> /tmp/whatever
maxkomarychev commented 4 years ago

@ahartzog wow thanks for sharing this!

I've got few questions:

However, manually setting the environment via npm for xcode leaves plenty of room for error (and wouldn't work if you're doing it in some sort of pipeline)

I am curious what kind of errors do you have in mind here and would you mind sharing specific details of a pipeline you are referring to?

I'd probably recommend adding a "how to" on this, or you're going to get this question again. Explain that it has nothing to do with the library really, it's just something people will probably want to do to associate schemes with different environments.

I tried something similar yesterday when saw your issue and it didn't work on my environment neither with yarn not with npm out of the box. I assume this is because my node.js stack is installed via nvm and it can't find node in default PATH. Not that this issue is not solvable but it opens a space for wide range of issues which depend on specific environment of a specific developer and/or CI.

Would you mind sharing your environment details? how do you have your node installed? brew? nvm? pkg installer?

That said I am slightly hesitant declaring support on this as a way to consume library but if that's the demand I might consider maintaining some sort of cookbook for such things. It's important to understand why one wants/needs to use schemes since by using this library you don't even need to worry about such nuances.

Thanks for a great feedback, this is important!

ahartzog commented 4 years ago

Hey @maxkomarychev - again I am no expert by any means, but from my understanding of the general workflows it's fairly common for people to have schemas set up like Dev, Staging, and Prod.

In order for their schema to use the correct respective .env files, they'd need this step.

As far as a pipeline - I think you're right that the scripts will work fine. You just built the rnuc command into whatever environment you're building for.

I have everything installed via homebrew. I totally get your hesitation about the environment issues - that damn xcode run scripts tool is a black box, it's so hard to test/debug what's going on.

maxkomarychev commented 4 years ago

I added a cookbook section with few common recipes of how this lib can be used. I am still struggling to figure out how to support multiple flavors in android in a similar manner how schemes work in xcode though

maxkomarychev commented 4 years ago

relevant section for android: https://github.com/maxkomarychev/react-native-ultimate-config/blob/master/docs/cookbook.md#using-multiple-flavors-android to keep parity between platforms. closing for now, thanks a lot for this feedback!