@@ -7,6 +7,7 @@ var fs = require('fs')
7
7
var tsNodeVersion = require ( 'ts-node' ) . VERSION
8
8
var tsVersion = require ( 'typescript' ) . version
9
9
var kill = require ( 'tree-kill' )
10
+ var readline = require ( 'readline' )
10
11
11
12
module . exports = function ( script , scriptArgs , nodeArgs , opts ) {
12
13
if ( typeof script !== 'string' || script . length === 0 ) {
@@ -44,34 +45,7 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) {
44
45
recursive : true
45
46
} )
46
47
var starting = false
47
- watcher . on ( 'change' , function ( file ) {
48
- if ( file === compiler . tsConfigPath ) {
49
- notify ( 'Reinitializing TS compilation' )
50
- compiler . init ( opts )
51
- }
52
- /* eslint-disable no-octal-escape */
53
-
54
- if ( cfg . clear || cfg . cls ) {
55
- process . stdout . write ( '\033[2J\033[H' )
56
- }
57
- notify ( 'Restarting' , file + ' has been modified' )
58
- compiler . compileChanged ( file )
59
- if ( starting ) {
60
- log . debug ( 'Already starting' )
61
- return
62
- }
63
- log . debug ( 'Removing all watchers from files' )
64
- watcher . removeAll ( )
65
- starting = true
66
- if ( child ) {
67
- log . debug ( 'Child is still running, restart upon exit' )
68
- child . on ( 'exit' , start )
69
- stop ( )
70
- } else {
71
- log . debug ( 'Child is already stopped, probably due to a previous error' )
72
- start ( )
73
- }
74
- } )
48
+ watcher . on ( 'change' , restart )
75
49
76
50
watcher . on ( 'fallback' , function ( limit ) {
77
51
log . warn ( 'node-dev ran out of file handles after watching %s files.' , limit )
@@ -80,6 +54,19 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) {
80
54
if ( cfg . deps ) log . info ( '... or add `--no-deps` to use less file handles.' )
81
55
} )
82
56
57
+ // Read for "rs" from command line
58
+ const rl = readline . createInterface ( {
59
+ input : process . stdin ,
60
+ output : process . stdout ,
61
+ terminal : false
62
+ } )
63
+ rl . on ( 'line' , function ( line ) {
64
+ if ( line . trim ( ) === 'rs' ) {
65
+ log . debug ( 'User entered `rs`' )
66
+ restart ( '' , true )
67
+ }
68
+ } )
69
+
83
70
/**
84
71
* Run the wrapped script.
85
72
*/
@@ -192,6 +179,36 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) {
192
179
}
193
180
}
194
181
182
+ function restart ( file , isManualRestart ) {
183
+ if ( file === compiler . tsConfigPath ) {
184
+ notify ( 'Reinitializing TS compilation' )
185
+ compiler . init ( opts )
186
+ }
187
+ /* eslint-disable no-octal-escape */
188
+ if ( cfg . clear ) process . stdout . write ( '\033[2J\033[H' )
189
+ if ( isManualRestart ) {
190
+ notify ( 'Restarting' , 'manual restart from user' )
191
+ } else {
192
+ notify ( 'Restarting' , file + ' has been modified' )
193
+ }
194
+ compiler . compileChanged ( file )
195
+ if ( starting ) {
196
+ log . debug ( 'Already starting' )
197
+ return
198
+ }
199
+ log . debug ( 'Removing all watchers from files' )
200
+ watcher . removeAll ( )
201
+ starting = true
202
+ if ( child ) {
203
+ log . debug ( 'Child is still running, restart upon exit' )
204
+ child . on ( 'exit' , start )
205
+ stop ( )
206
+ } else {
207
+ log . debug ( 'Child is already stopped, probably due to a previous error' )
208
+ start ( )
209
+ }
210
+ }
211
+
195
212
// Relay SIGTERM
196
213
process . on ( 'SIGTERM' , function ( ) {
197
214
log . debug ( 'Process got SIGTERM' )
0 commit comments