redux-devtools/packages/redux-devtools-cli/README.md

163 lines
8.0 KiB
Markdown
Raw Permalink Normal View History

2019-01-10 21:51:14 +03:00
# Redux DevTools Command Line Interface
2019-01-04 01:30:48 +03:00
2019-01-04 22:44:48 +03:00
Bridge for remote debugging via [Redux DevTools extension](https://github.com/zalmoxisus/redux-devtools-extension), [Remote Redux DevTools](https://github.com/zalmoxisus/remote-redux-devtools) or [RemoteDev](https://github.com/zalmoxisus/remotedev).
2019-01-04 01:30:48 +03:00
### Usage
#### Install the package globally
with npm:
2019-01-04 01:30:48 +03:00
```
npm install -g @redux-devtools/cli
2019-01-04 01:30:48 +03:00
```
or with yarn:
2019-01-04 01:30:48 +03:00
```
yarn global add @redux-devtools/cli
```
2019-01-04 01:30:48 +03:00
and start as:
2019-01-04 01:30:48 +03:00
```
redux-devtools --hostname=localhost --port=8000
2019-01-04 01:30:48 +03:00
```
> Note the package is called `@redux-devtools/cli` not `redux-devtools` (the latter is a React component).
2019-01-04 01:30:48 +03:00
#### Or add in your project
2019-01-04 01:30:48 +03:00
with npm:
```
npm install --save-dev @redux-devtools/cli
2019-01-04 01:30:48 +03:00
```
or with yarn:
2019-01-04 01:30:48 +03:00
```
yarn add --dev @redux-devtools/cli
```
and add to `package.json`:
2019-01-04 01:30:48 +03:00
```
"scripts": {
"redux-devtools": "redux-devtools --hostname=localhost --port=8000"
}
```
So, you can start redux-devtools server by running `npm run redux-devtools`.
##### Import in your `server.js` script you use for starting a development server:
```js
var reduxDevTools = require('@redux-devtools/cli');
reduxDevTools({ hostname: 'localhost', port: 8000 });
2019-01-04 01:30:48 +03:00
```
So, you can start redux-devtools server together with your dev server.
### Open Redux DevTools
2019-01-05 18:49:52 +03:00
You can add `--open` argument (or set it as `electron`) to open Redux DevTools as a standalone application:
```
redux-devtools --open
```
2019-01-05 18:49:52 +03:00
Set it as `browser` to open as a web app in the default browser instead:
```
redux-devtools --open=browser
```
To specify the browser:
```
redux-devtools --open=firefox
```
2019-01-04 01:30:48 +03:00
### Connection settings
Set `hostname` and `port` to the values you want. `hostname` by default is `localhost` and `port` is `8000`.
To use WSS, set `protocol` argument to `https` and provide `key`, `cert` and `passphrase` arguments.
#### Available options
2019-01-10 21:51:14 +03:00
| Console argument | description | default value |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| `--hostname` | hostname | localhost |
| `--port` | port | 8000 |
| `--protocol` | protocol | http |
| `--key` | the key file for [running an https server](https://github.com/SocketCluster/socketcluster#using-over-https) (`--protocol` must be set to 'https') | - |
| `--cert` | the cert file for [running an https server](https://github.com/SocketCluster/socketcluster#using-over-https) (`--protocol` must be set to 'https') | - |
| `--passphrase` | the key passphrase for [running an https server](https://github.com/SocketCluster/socketcluster#using-over-https) (`--protocol` must be set to 'https') | - |
| `--dbOptions` | database configuration, can be whether an object or a path (string) to json configuration file (by default it uses our `./defaultDbOptions.json` file. Set `migrate` key to `true` to use our migrations file. [More details bellow](#save-reports-and-logs). | - |
| `--logLevel` | the socket server log level - 0=none, 1=error, 2=warn, 3=info | 3 |
| `--wsEngine` | the socket server web socket engine - ws or uws (sc-uws) | ws |
| `--open` | open Redux DevTools as a standalone application or as web app. See [Open Redux DevTools](#open-redux-devtools) for details. | false |
2019-01-04 01:30:48 +03:00
### Inject to React Native local server
##### Add in your React Native app's `package.json`:
```
"scripts": {
"redux-devtools": "redux-devtools --hostname=localhost --port=8000 --injectserver=reactnative"
2019-01-04 01:30:48 +03:00
}
```
The `injectserver` value can be `reactnative` or `macos` ([react-native-macos](https://github.com/ptmt/react-native-macos)), it used `reactnative` by default.
Then, we can start React Native server and Redux DevTools server with one command (`npm start`).
2019-01-04 01:30:48 +03:00
##### Revert the injection
Add in your React Native app's `package.json`:
```
"scripts": {
"redux-devtools-revert": "redux-devtools --revert=reactnative"
2019-01-04 01:30:48 +03:00
}
```
Or just run `$(npm bin)/redux-devtools --revert`.
2019-01-04 01:30:48 +03:00
### Connect from Android device or emulator
2019-01-10 21:51:14 +03:00
> Note that if you're using `injectserver` argument explained above, this step is not necessary.
2019-01-04 01:30:48 +03:00
If you're running an Android 5.0+ device connected via USB or an Android emulator, use [adb command line tool](http://developer.android.com/tools/help/adb.html) to setup port forwarding from the device to your computer:
```
adb reverse tcp:8000 tcp:8000
```
If you're still use Android 4.0, you should use `10.0.2.2` (Genymotion: `10.0.3.2`) instead of `localhost` in [remote-redux-devtools](https://github.com/zalmoxisus/remote-redux-devtools#storeconfigurestorejs) or [remotedev](https://github.com/zalmoxisus/remotedev#usage).
### Save reports and logs
You can store reports via [`redux-remotedev`](https://github.com/zalmoxisus/redux-remotedev) and get them replicated with [Redux DevTools extension](https://github.com/zalmoxisus/redux-devtools-extension) or [Remote Redux DevTools](https://github.com/zalmoxisus/remote-redux-devtools). You can get action history right in the extension just by clicking the link from a report. Open `http://localhost:8000/graphql` (assuming you're using `localhost` as host and `8000`) to explore in GraphQL. Reports are posted to `http://localhost:8000/`. See examples in [tests](https://github.com/zalmoxisus/remotedev-server/blob/937cfa1f0ac9dc12ebf7068eeaa8b03022ec33bc/test/integration.spec.js#L110-L165).
2019-01-04 01:30:48 +03:00
Redux DevTools server is database agnostic using `knex` schema. By default everything is stored in the memory using sqlite database. See [`defaultDbOptions.json`](https://github.com/reduxjs/redux-devtools/tree/master/packages/redux-devtools-cli/defaultDbOptions.json) for example of sqlite. You can replace `"connection": { "filename": ":memory:" },` with your file name (instead of `:memory:`) to persist teh database. Here's an example for PostgreSQL:
2019-01-10 21:51:14 +03:00
2019-01-04 01:30:48 +03:00
```
{
"client": "pg",
"connection": { "user": "myuser", "password": "mypassword", "database": "mydb" },
"debug": false,
"migrate": true
}
```
### Advanced
2019-01-10 21:51:14 +03:00
2019-01-05 19:25:16 +03:00
- [Writing your integration for a native application](https://github.com/reduxjs/redux-devtools/blob/master/docs/Integrations/Remote.md)
2019-01-04 01:30:48 +03:00
2019-01-10 21:51:14 +03:00
### License
2019-01-04 01:30:48 +03:00
MIT