Provides the Android/Gradle functionality to go with https://github.com/react-native-community/react-native-cli/pull/256 & https://github.com/react-native-community/react-native-cli/pull/254
## CLI Changes
- Updated `react-native config` to include the android `sourceDir` for react native module packages
----
## Usage
These are the one-off changes required to enable this in the React Native init template (or for existing user projects).
### Modify `android/settings.gradle`
Include the following line in your Android projects `settings.gradle` file:
```groovy
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
```
### Modify `android/app/build.gradle`
Add the following line at the bottom of your Android projects `android/app/build.gradle` file:
```groovy
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
```
### Modify `MainApplication.java`
Import the PackageList class;
```java
import com.facebook.react.PackageList;
```
Replace the `protected List<ReactPackage> getPackages()` method with the following:
```java
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// additional non auto detected packages can still be added here:
// packages.add(new SomeReactNativePackage());
return packages;
}
```
### Testing
I've tested the following scenarios locally:
- User has no React Native global CLI installed
- Will warn but continue without issue
- User has no React Native packages installed yet
- Continues as normal with no warning
- User has more than one React Native package installed
- Correctly adds multiple packages without issue
- User has a package installed that does not support autodetection (config == null)
- Prints a warning but continues gracefully
- User has custom/non-linked React Native packages
- Can be sucessfully manually added via `packages.add(new SomeReactNativePackage());` as documented above in `MainApplication.java`
To test this in a new `react-native init` project locally:
- Clone the CLI project
- Run `yarn` in the CLI project
- Run `cd packages/cli && yarn && yarn link` in the CLI project
- (a little hacky as it's a mono-repo)
- Run `yarn link "@react-native-community/cli"` on your React Native project
- Make the required changes as above to your React Native project
----
### Codegen Output Example
An example of the generated `PackageList.java` class:
```java
package com.facebook.react;
import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import java.util.Arrays;
import java.util.List;
import com.test.BuildConfig;
// react-native-webview
import com.reactnativecommunity.webview.RNCWebViewPackage;
public class PackageList {
private ReactNativeHost reactNativeHost;
public PackageList(ReactNativeHost reactNativeHost) {
this.reactNativeHost = reactNativeHost;
}
private ReactNativeHost getReactNativeHost() {
return this.reactNativeHost;
}
private Resources getResources() {
return this.getApplication().getResources();
}
private Application getApplication() {
return this.reactNativeHost.getApplication();
}
private Context getApplicationContext() {
return this.getApplication().getApplicationContext();
}
public List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNCWebViewPackage()
);
}
}
```
* chore: move shared types to root; moar link styles; bye promiseWaterfall
* fix test
* add alias for global types
* bump Flow to 0.97
* add lint annotation to bin
* enable babel module resolver plugin
* import inquirer prompt type
Summary:
---------
Metro server can become too verbose if there are a lot of assets due to morgan verbosely logging every request. Trying to make use of `verbose` flag to allow users skipping successful requests if 'verbose' is set to false (default)
<!-- Thank you for sending the PR! We appreciate you spending the time to work on these changes.
Help us understand your motivation by explaining why you decided to make this change: -->
Test Plan:
----------
1. run `react-native start`
Expected Result: no console output on a successful request
2. run `react-native start --verbose`
Expected Result: console output for every request
<!-- Write your test plan here (**REQUIRED**). If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos! Increase test coverage whenever possible. -->
Summary:
---------
Thanks to this change, CLI will not add default React Native configuration when one is present. I can now go to React Native, add the configuration and release it and CLI will pick that one.
The below temporary workaround allows us to run on 0.59, where config is not yet present.
Summary:
---------
I've noticed that the `max-workers` CLI flag is not behaving as expected for the bundle command.
We need it in one of our CI builds where the container is a bit memory-starved and the default of `numberOfWorkers = numberOfCores` isn't always accurate in a virtualized environment.
This fix ensures the flag makes it to the server config and that the number of node processes reflect the number provided + 1.
Test Plan:
----------
I made a reproduction repo: https://github.com/sterlingwes/rn-cli-repro
The values in the "expected output" reflect the fact:
* i already have a node process running for an unrelated task
* the number of node processes should be `maxWorkersValue + 1`, since there's a parent node process that spawns the child workers
So in the success case, `maxWorkers: 2` would lead to 3 node processes for the RN cli
* wip
* Finish it up
* Clean up packages
* Move files around
* Simplify regex
* Remove unused type
* Move packages around
* Fix type
* Update snapshot
* Make snapshot even smaller
* Throw unlink error
* feat: infer packageName and projectName for upgrade from config
* extract merge to tools and use it in tests
* warn if unsupported platform is being upgraded
Summary:
---------
This PR moves the logic for loading commands from CLI to the dependency authors. They should define a JavaScript configuration and return an array of commands (an object with required properties) they want to load.
Previously, we would require them to define paths (relative to root) to a JavaScript file to require.
This is necessary to send a follow-up PR, which removes built-in platform commands to be bundled with React Native.
WIP: Need to check tests and update one or two snapshots to make sure we output Objects, instead of strings in a configuration.
Summary:
---------
Historically, Android and iOS platform were hardcoded inside CLI and provided by default. Then, other packages could export additional platforms on top of it.
React Native as a platform was hardcoded in Metro configuration (default platforms, default extensions) and inside link. That means all new features were always developed with these platforms in mind, leaving others behind. We often used private APIs, which made things more complicated for 3rd party platform developers.
From this PR on, there's no longer concept of an out-of-tree platform inside of the CLI. In a follow up PR to React Native, I am going to configure iOS and Android platforms inside React Native, just like React Native Windows exposes Windows platform.
This will open room for improvements and should make it even easier for the CLI to welcome other platforms.
* Implement spinners for initializing flow
* Use execa module
* Change banner
* Ignore silent flag when in verbose mode
* Refactor packageManager test
* Change loader exports
* Fix e2e test
* Rename packageManager
* Add e2e test
* smaller paddings for React logo
* Cleanup tests
* fix flowfixme
* add space for post install script
* rename packageManager.test as well
Summary:
---------
This PR switches `link` to rely on the new configuration (from "ctx") that is also used by "react-native config" and soon, "auto linking".
Test Plan:
----------
You should be able to run link w/o any issues
Summary:
---------
`fs.copySync` does not properly copy binary files. I am using the copy method that we already have in the repo.
Test Plan:
----------
Without this change `react-native run-android` breaks with the following error:
<img width="962" alt="Screen Shot 2019-04-02 at 16 58 14" src="https://user-images.githubusercontent.com/13352/55443764-b8638380-5568-11e9-94ba-0d33322d24da.png">