Skip to content

Commit

Permalink
Open Redux DevTools in browser from cli
Browse files Browse the repository at this point in the history
  • Loading branch information
zalmoxisus committed Jan 5, 2019
1 parent 2d69d52 commit b002903
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/redux-devtools-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ reduxDevTools({ hostname: 'localhost', port: 8000 });

So, you can start redux-devtools server together with your dev server.

### Open Redux DevTools

You can add `--open` argument to open Redux DevTools app. If nothing specified or set as `browser` will use default browser:

```
redux-devtools --open
```

To specify the browser:

```
redux-devtools --open=firefox
```

### Connection settings

Set `hostname` and `port` to the values you want. `hostname` by default is `localhost` and `port` is `8000`.
Expand All @@ -80,6 +94,7 @@ To use WSS, set `protocol` argument to `https` and provide `key`, `cert` and `pa
| `--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 DevTools app in browser. If nothing specified or set as `browser` will use default browser. | false |

### Inject to React Native local server

Expand Down
8 changes: 8 additions & 0 deletions packages/redux-devtools-cli/bin/open.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var opn = require('opn');

function open(app, options) {
console.log('app', app)
opn('http://localhost:' + options.port + '/', app !== 'browser' && app !== true ? { app: app } : undefined);
}

module.exports = open;
13 changes: 11 additions & 2 deletions packages/redux-devtools-cli/bin/redux-devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ var argv = require('minimist')(process.argv.slice(2));
var chalk = require('chalk');
var injectServer = require('./injectServer');
var getOptions = require('./../src/options');
var server = require('../index');
var open = require('./open');

var options = getOptions(argv);

function readFile(filePath) {
return fs.readFileSync(path.resolve(process.cwd(), filePath), 'utf-8');
Expand Down Expand Up @@ -61,7 +65,6 @@ if (argv.revert) {
}

if (argv.injectserver) {
var options = getOptions(argv);
var module = getModule(argv.injectserver);
var pass = injectServer.inject(module.path, options, module.name);
var msg = 'Inject ReduxDevTools server into React Native local server';
Expand All @@ -70,4 +73,10 @@ if (argv.injectserver) {
process.exit(pass ? 0 : 1);
}

require('../index')(argv);
server(argv).then(function (r) {
if (argv.open && argv.open !== 'false') {
r.on('ready', function () {
open(argv.open, options);
});
}
});
1 change: 1 addition & 0 deletions packages/redux-devtools-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"lodash": "^4.15.0",
"minimist": "^1.2.0",
"morgan": "^1.7.0",
"opn": "^5.4.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"redux-devtools-core": "^1.0.0-1",
Expand Down

0 comments on commit b002903

Please sign in to comment.