-
Notifications
You must be signed in to change notification settings - Fork 932
docs: initial documentation of the basic features #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
18f3069
fix: typos in Autolinking & use same repo for both examples
grabbou 307d7b7
structure new files
grabbou 9158f6f
Add documentation for plugins and update naming in one place
grabbou fcf09e5
Update index.js
grabbou ece2601
Fix flow and update docs
grabbou 7f82a86
Update
grabbou f096fea
Prefix
grabbou 595bb1a
Updates
grabbou 7d20fc5
Take advantage of Joi
grabbou 815032f
Update docs/plugins.md
thymikee 29708d5
Update docs/plugins.md
thymikee 1023933
Some other tweaks
grabbou f6fe3a4
Merge branch 'feat/docs' of github.com:react-native-community/react-n…
grabbou 4e3677d
Placeholder for dependency
grabbou c1cfa7f
Updates
grabbou 6e37fca
Delete linking.md
grabbou 9b55f15
fix tests
grabbou 5dd6366
Merge branch 'feat/docs' of github.com:react-native-community/react-n…
grabbou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Configuration | ||
|
|
||
| TBD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Dependency | ||
|
|
||
| TBD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Platforms | ||
|
|
||
| TBD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,151 @@ | ||
| # Plugins | ||
|
|
||
| TBD | ||
| Plugin is a JavaScript package that extends built-in React Native CLI features. It can provide an array of additional commands to run or platforms to target. | ||
|
|
||
| For example, `react-native-windows` package is a plugin that provides `react-native run-windows` command and `windows` platform. | ||
|
|
||
| Details of this particular integration as well as how to provide an additional platform for React Native were described in a [`dedicated section`](./platforms.md) about platforms. | ||
|
|
||
| ## How does it work? | ||
|
|
||
| Except for React Native dependencies, where configuration is implicit, each package needs to have a `react-native.config.js` at the root folder in order to be discovered by the CLI as a plugin. | ||
|
|
||
| ```js | ||
| module.exports = { | ||
| commands: [ | ||
| { | ||
| name: 'foo-command', | ||
| func: () => console.log('It worked') | ||
thymikee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| ] | ||
| }; | ||
| ``` | ||
|
|
||
| > Above is an example of a plugin that exports a command named `foo-command` that can be executed with `react-native foo-command` and logs "It worked" and exits. | ||
|
|
||
|
|
||
| At the startup, React Native CLI reads configuration from all dependencies listed in `package.json` and reduces them into a single configuration. | ||
|
|
||
| At the end, an array of commands concatenated from all plugins is passed on to the CLI to be loaded after built-in commands. | ||
|
|
||
| ## Command interface | ||
|
|
||
| ```ts | ||
| type Command = { | ||
| name: string, | ||
| description?: string, | ||
| func: (argv: Array<string>, config: ConfigT, args: Object) => ?Promise<void>, | ||
| options?: Array<{ | ||
| name: string, | ||
| description?: string, | ||
| parse?: (val: string) => any, | ||
| default?: | ||
| | string | ||
| | boolean | ||
| | number | ||
| | ((config: ConfigT) => string | boolean | number), | ||
| }>, | ||
| examples?: Array<{ | ||
| desc: string, | ||
| cmd: string, | ||
| }>, | ||
| }; | ||
| ``` | ||
|
|
||
| > Note: `ConfigT` is described in [`configuration`](./configuration.md) section | ||
|
|
||
| #### `name` | ||
|
|
||
| A name that will be used in order to run the command. | ||
|
|
||
| Note: If you want your command to accept additional arguments, make sure to include them in the name. | ||
|
|
||
| For example, `my-command <argument>` will require an argument to be provided and will throw a validation error otherwise. Alternatively, `my-command [argument]` will accept an argument, but will not throw when run without it. In that case, make sure to check for its presence. | ||
|
|
||
| #### `func` | ||
|
|
||
| Function that will be run when this command is executed. Receives an array of arguments, in order they were provided, a config object (see [`configuration` section](./configuration.md)) and options, that were passed to your command. | ||
|
|
||
| You can return a Promise if your command is async. | ||
|
|
||
| All errors are handled by the built-in logger. Prefer throwing instead of implementing your own logging mechanism. | ||
|
|
||
| #### `options` | ||
|
|
||
| An array of options that your command accepts. | ||
|
|
||
| ##### `options.name` | ||
|
|
||
| Name of the option. | ||
|
|
||
| For example, a `--reset-cache` option will result in a `resetCache: true` or `resetCache: false` present in the `options` object - passed to a command function as a last argument. | ||
|
|
||
| Just like with a [command name](#name), your option can require a value (e.g. `--port <port>`) or accept an optional one (e.g. `--host [host]`). In this case, you may find [`default`](#optionsdefault) value useful. | ||
|
|
||
| ##### `options.description` | ||
|
|
||
| Optional description of your option. When provided, will be used to output a better help information. | ||
|
|
||
| ##### `options.parse` | ||
|
|
||
| Parsing function that can be used to transform a raw (string) option as passed by the user into a format expected by your function. | ||
|
|
||
| ##### `options.default` | ||
|
|
||
| Default value for the option when not provided. Can be either a primitive value or a function, that receives a configuration and returns a primitive. | ||
|
|
||
| Useful when you want to use project settings as default value for your option. | ||
|
|
||
| #### `examples` | ||
|
|
||
| An array of example usage of the command to be printed to the user. | ||
|
|
||
| ##### `examples.desc` | ||
|
|
||
| String that describes this particular usage. | ||
|
|
||
| ##### `examples.cmd` | ||
|
|
||
| A command with arguments and options (if applicable) that can be run in order to achieve the desired goal. | ||
|
|
||
| ## Migrating from `rnpm` configuration | ||
|
|
||
| The changes are mostly cosmetic so the migration should be pretty straight-forward. | ||
|
|
||
| ### Changing the configuration | ||
|
|
||
| A `plugin` property should be renamed to `commands`. | ||
|
|
||
| For example, the following `rnpm` configuration inside `package.json`: | ||
| ```json | ||
| { | ||
| "rnpm": { | ||
| "plugin": "./path-to-commands.js", | ||
| } | ||
| } | ||
| ``` | ||
| should be moved to a `react-native.config.js`: | ||
| ```js | ||
| module.exports = { | ||
| commands: require('./path-to-commands.js') | ||
| }; | ||
| ``` | ||
| provided that `./path-to-commands.js` returns an array of commands. | ||
|
|
||
| ### Renaming command options | ||
|
|
||
| If your command accepts options, rename `command` property of each of them to `name`. | ||
|
|
||
| ```diff | ||
| module.exports = { | ||
| name: 'foo', | ||
| func: () => console.log('My work'), | ||
| options: [ | ||
| { | ||
| - command: '--reset-cache, --resetCache', | ||
| + name: '--reset-cache, --resetCache', | ||
| description: 'Removes cached files', | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.