Skip to content

Commit

Permalink
Move debug option to env variable
Browse files Browse the repository at this point in the history
The debug module does not work well with dynamic configurations. So we need to use the environment variable to set up the debug logs.
  • Loading branch information
maxcnunes committed Oct 26, 2015
1 parent a9ea6d1 commit e8d85d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ require('spawn-auto-restart')({
});
```

To enable logs set an environment variable like this:

```shell
DEBUG=spawn-auto-restart
```

**advanced args options**

* [spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)
* [chokidar](https://github.com/paulmillr/chokidar)

```js
require('spawn-auto-restart')({
debug: true,
proc: {
command: 'executable path',
// ... any spawn argument
Expand All @@ -50,7 +55,7 @@ Auto restarting an [electron](https://github.com/atom/electron) app in developme

![](https://www.dropbox.com/s/gxird1lr72tq56s/spawn-auto-restart.gif?raw=1)

**restart.js**
**node DEBUG=spawn-auto-restart restart.js**
```js
#!/usr/bin/env node

Expand All @@ -63,7 +68,6 @@ var watch = join(__dirname, '../src/browser');


require('spawn-auto-restart')({
debug: true,
proc: {
command: electron,
args: main
Expand Down
9 changes: 3 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var spawn = require('child_process').spawn;
var chokidar = require('chokidar');
var debug = require('debug');
var debug = require('debug')('spawn-auto-restart');


module.exports = function (options) {
Expand All @@ -11,9 +11,6 @@ module.exports = function (options) {
var proc;
var restarting = false;

if (options.debug) { debug.enable('spawn-auto-restart'); }
var log = debug('spawn-auto-restart');

// allows use all options available for spawn
var procCommand = options.proc;
var procArgs;
Expand Down Expand Up @@ -53,7 +50,7 @@ module.exports = function (options) {
};

proc.on('error', function () {
log('restarting due error');
debug('restarting due error');
restarting = true;
proc.kill('SIGINT');
});
Expand All @@ -66,7 +63,7 @@ module.exports = function (options) {

// starts watching
chokidar.watch(watchPath, watchOptions).on('change', function() {
log('restarting due changes');
debug('restarting due changes');
restarting = true;
proc.kill('SIGINT');
});
Expand Down

0 comments on commit e8d85d7

Please sign in to comment.