* Change `packageName` to `projectName` & add `projectPath` argument
* Add a way to specify a custom project path to init the app on
* Force the `init` command to create the project path recursively
* Add test for providing the project path on init
* Throw error if custom project path doesn’t exist and can’t be created
* Fix type error on `customProjectPath`
* Create directory before running the test with custom project path
* Use `mkdirp` to create project folder & Use `inquirer` to prompt for a directory replace
* Specify `directory` as an option
* Handle custom directory path after react logo
* Check if `ios` folder exists before trying to open it
* Update `init` tests
* Add `directory` type
* Remove unused `inquirer` from `init` test
* Only remove the project folder if it didn’t exist before running `init`
* Remove correct directory if it didn’t exist before `init`
* simplify
* make directory an argument instead of a flag
* update descriptions
* fix test
* use --directory after all
* address feedback; remove version handling from createFromTemplate
* flip the default
* fix: run "config" from react-native binary
* use yarn run when necessary and fallback to accessing binary with Node
* filter out non-json stuff in gradle implementation
* use yarn --silent
* Specify `.xcworkspace` on run instructions instead of `.xcodeproj`
* Add `command-exists` package
* Remove unneeded space after log message
* Run `pod install` and check for cocoa pods when running `init` command
* Put pods installation directly on `init` file and verify if `Podfile` exists before running
* Revert change to space
* Remove unneeded `console.log`
* `cd` back to the directory after pod installation
* Throw with `CLIError` instead of `Error`
* Remove unneeded `try…catch`
* Fix wrong uppercased word
* Try to install `cocoapods` without sudo before trying with it
* Run pods installation only on macOS
* Check which extension for the project to print out on the run instructions for iOS
* Use `fs` instead of `fs-extra`
* Move `installPods` to separate file
* Add missing `logger` import
* Fix warnings on duplicated variable declaration
* fixups
* chore: cleanup run-android implementation
* feat: overhaul gradle install errors
* fix copying executables by bringing back chmod
* rename 'installDebug' -> 'task'
* cleanup unused args from refactor
* use inherit and don't show null error
* simplify creating gradle args
* adjust descriptions
* use logger
* Add support for multiple tasks
* Change function name to match current functionality
* Change task to tasks
The `loadConfig` function in `metro-config` reads the `reporter` option
from the second argument (`defaultConfigOverrides`) instead of the
first argument (`argv`), so we need to pass it in that object to
make the `customLogReporterPath` CLI option work.
* [ios] Ensure that the right cwd is set up for auto-linking dependencies
* [autolink] Switch to DIing in the root path as a param in to use_native_modules
* [autolink] Docs for autolink root changes
* fix: typos in Autolinking & use same repo for both examples
* structure new files
* Add documentation for plugins and update naming in one place
* Update index.js
* Fix flow and update docs
* Update
* Prefix
* Updates
* Take advantage of Joi
* Update docs/plugins.md
Co-Authored-By: grabbou <[email protected]>
* Update docs/plugins.md
Co-Authored-By: grabbou <[email protected]>
* Some other tweaks
* Placeholder for dependency
* Updates
* Delete linking.md
* fix tests
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()
);
}
}
```