Commit Graph
159 Commits
Author SHA1 Message Date
Mike Grabowski 9b55f15907 fix tests 2019-04-23 18:17:13 +02:00
Mike Grabowski 7d20fc5d02 Take advantage of Joi 2019-04-23 17:44:47 +02:00
Mike Grabowski 7f82a866fd Update 2019-04-23 17:35:07 +02:00
Mike Grabowski ece2601210 Fix flow and update docs 2019-04-23 17:26:43 +02:00
Mike Grabowski 9158f6f613 Add documentation for plugins and update naming in one place 2019-04-23 17:20:29 +02:00
Michał Pierzchała b306c99fda docs: update and rearrange documentation (#338)
* docs: update and rearrange documentation

* add autolinking base docs

* add init docs
2019-04-23 12:26:19 +02:00
Michał Pierzchała 1040959a30 fix: stop resolving "react-native" from package.json as a config (#341)
* fix: stop resolving "react-native" as a valid package.json config property

* add missing editTemplate file
2019-04-22 21:37:54 +02:00
Michał Pierzchała 513d27bd4c v2.0.0-alpha.14 2019-04-20 11:50:31 +02:00
Michał Pierzchała 827daa4c16 v2.0.0-alpha.13 2019-04-19 19:51:30 +02:00
Mike Diarmid f1105bcf9a feat: autolinking for Android with Gradle (#258)
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()
    );
  }
}
```
2019-04-19 19:48:16 +02:00
Michał Pierzchała 6c575fdb29 feat: support init inside monorepos (#320) 2019-04-19 19:47:52 +02:00
Mike Grabowski 83d58a63ac chore: top-level unknown keys are now allowed, update test case 2019-04-18 23:19:17 +02:00
Mike Grabowski 15cea82c3e v2.0.0-alpha.12 2019-04-18 23:05:23 +02:00
Mike Grabowski 9440b15c2d handle haste (#336) 2019-04-18 23:03:57 +02:00
Mike Grabowski a0b9e31542 v2.0.0-alpha.11 2019-04-18 22:12:34 +02:00
Mike Grabowski f7a7d4ca16 fix: update haste config with platforms too 2019-04-18 22:11:52 +02:00
Mike Grabowski ac9a85e0dd feat: support platforms that ship with project (#335)
* Project can also have platforms

* strip unknown

* Remove stripUnknown and prefer allowUnknown on one level only
2019-04-18 22:06:50 +02:00
Mike Grabowski cacaa075ba v2.0.0-alpha.10 2019-04-18 18:03:21 +02:00
Mike Grabowski 365be100e7 fix: allow empty strings to be used as defaults 2019-04-18 18:03:02 +02:00
Mike Grabowski e7eeea4a80 v2.0.0-alpha.9 2019-04-18 17:48:52 +02:00
Mike Grabowski c28fb93696 Support functions in default (#333) 2019-04-18 17:48:07 +02:00
Michał Pierzchała 98d88d5f43 v2.0.0-alpha.8 2019-04-18 16:32:28 +02:00
Michał Pierzchała 60606efd56 v2.0.0-alpha.7 2019-04-17 22:20:33 +02:00
Eloy Durán 76f079ee8a feat: autolink on iOS 2019-04-16 22:54:46 +02:00
Brent Vatne fb94fef712 Add support for assetPlugins argument to start command (#318)
* Add support for assetPlugins argument to start command

* Add assetPlugins arg type
2019-04-16 22:31:44 +02:00
Michał Pierzchała 708211a645 chore: move shared types to root; moar link styles; bye promiseWaterfall (#312)
* 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
2019-04-16 14:53:50 +02:00
Michał Pierzchała 4036fc5eb2 chore: add documentation on link, unlink, start, upgrade (#316) 2019-04-16 14:51:35 +02:00
ifsnow 7ac73fa563 fix: add new line to the help message (#319)
Summary:
---------
There is a problem with the line break of command help as below.

<img width="561" src="https://user-images.githubusercontent.com/3139234/56199103-3484bd80-6077-11e9-9c00-9aa4f45bc185.png">

Test Plan:
----------

Not required.
2019-04-16 12:47:51 +02:00
Michał Pierzchała 964c45296d chore: use files instead of npmignore for publishing (#314) 2019-04-13 11:02:02 +02:00
Shaun Donnelly fc21e30f88 chore: fix typo in link debug message (#311)
Typo
2019-04-11 16:28:00 +02:00
Vance Hu c608a8827f feat: skip successful Metro server requests if --verbose not set (#291)
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. -->
2019-04-11 10:00:33 +02:00
Mike Grabowski 5881ed5606 feat: skip packages that have invalid config instead of throwing an error (#309)
* Do not throw on invalid packages

* Fix type error

* Update test

* add dot

* Update snapshots
2019-04-10 20:41:41 +02:00
Michał Pierzchała 0a049714b0 v2.0.0-alpha.6 2019-04-10 17:21:42 +02:00
Mike Grabowski 51f4dcab34 chore: don't apply RN config automatically (#306)
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.
2019-04-10 17:20:28 +02:00
Wes Johnson f3e7717f43 fix: pass maxWorkers arg to server (#305)
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
2019-04-10 16:16:06 +02:00
Mike Grabowski 6343e2a892 feat: extract commands out to platform packages (#302)
* 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
2019-04-10 14:24:20 +02:00
Michał Pierzchała 1440eb4163 feat: infer package and project name for upgrade from config (#299)
* 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
2019-04-10 14:22:40 +02:00
Mike Grabowski ad702edc6c fix: resolve relative paths for reactNativePath (#297)
* Fix for relative paths

* Update snapshots
2019-04-09 15:10:29 +02:00
Mike Grabowski 38129ea728 feat: commands should be defined as object, unless defined via legacy config (#295)
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.
2019-04-09 15:03:38 +02:00
Kacper Wiszczuk 978935ff26 feat: use logkitty to format android logs (#294)
feat: use `logkitty` to format android logs
2019-04-09 12:45:14 +02:00
Michał Pierzchała f1c72e9256 v2.0.0-alpha.5 2019-04-09 08:56:14 +02:00
Christoph Nakazawa 586f79b4b7 fix: copy .keystore files as binary extensions. (#300) 2019-04-09 07:57:50 +02:00
maxaggedon 4d8cfe46d3 feat: apply upgrade patch in subdirectory if necessary (#272)
* bug: apply update patch in subdirectory if necessary

* add tests instead of changing existing ones
2019-04-06 20:40:57 +02:00
Michał Pierzchała 49352be129 v2.0.0-alpha.4 2019-04-06 18:40:21 +02:00
Mike Grabowski 5f7dba3d6e feat: extract iOS and Android specific linking files out of the core (#290)
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.
2019-04-05 22:02:26 +02:00
Kacper Wiszczuk 0d8f2e4182 feat: add React logo and spinners to make init UI nicer (#292)
* 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
2019-04-05 20:37:23 +02:00
Mike Grabowski 4320d3e447 feat: make legacy link use new configuration (#281)
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
2019-04-04 17:47:13 +02:00
Michał Pierzchała 90c0f49249 chore: make legacyInit test less flaky (#286)
Summary:
---------

Get rid of moving parts in legacy init test


Test Plan:
----------

Test runs fine
2019-04-03 10:43:15 +02:00
Christoph Nakazawa 4bf4028639 fix: properly copy template binary files (#285)
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">
2019-04-03 10:22:45 +02:00
Michał Pierzchała 65f5f9cdd7 v2.0.0-alpha.1 2019-04-03 09:12:22 +02:00