Skip to content

Navigation Menu

Sign in
Sign up

Allowing users to hook into native build steps #2410

atlj started this conversation in Ideas
Discussion options

It would be handy to have a way in the Community CLI to run arbitrary commands in native build steps. The build steps here can be pre-build and post-build for starters.

Ideally, the commands should be called regardless of the build method being used i.g. using the XCode App or the Android Studio App, running yarn android, or yarn ios, using xcodebuild or gradlew via the terminal.

A good example here would be with React Native libraries. When a library author opts in to ship the codegen-generated code with their library (more details in this document), codegen doesn't run for their libraries during the build process anymore. This is the desired behavior when the author ships their library however this can cause issues in the development process. If the author updates their codegen specs without calling codegen, their native app would build just fine on their end. However, when they ship their code, consumers would have trouble building the library on their end. With a way to hook into the native build process, the library author can call the codegen whenever they build their app, verifying their codegen-generated code is up-to-date.

How can React Native apps specify their build hooks?

One way of doing this would be adding a new property to the project section of the React Native configuration.

project.ios.preBuild, project.ios.postBuild, project.android.preBuild, and project.android.postBuild with string values can be added and their values would be called during appropriate build stages.

Possible Issues

  1. If anyone relies on the pre-build step to generate some library code (like invoking codegen), the build will fail since pod installs would be called before having the generated files, therefore those files wouldn't be captured by CocoaPods. It's possible to add a pre_install step to CocoaPods but this is not a part of the native build.
You must be logged in to vote

Replies: 3 comments

Comment options

Note: You can also take a look at this file from react-native-builder-bob that patches the example React Native application to invoke codegen before native builds.

You must be logged in to vote
0 replies
Comment options

The pre-/postBuild names sound quite generic and, as you mentioned with Cocoapods case, will result in issues as to when they're called, possibly indicating we'd need more places to hook into. I'd appreciate a different design that would allow us to achieve similar results, or a more specific name of the hook

You must be logged in to vote
0 replies
Comment options

It would be handy to have a way in the Community CLI to run arbitrary commands in native build steps. The build steps here can be pre-build and post-build for starters.

My 2c here: Gradle/CocoaPods already offer this level of configurability. I don't think this should be exposed via the CLI as it's too broad and generic and potentially hard to maintain for CLI developers in the long run

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /