()
| 346 | } |
| 347 | |
| 348 | function restart() { |
| 349 | |
| 350 | if (watchercallback) { |
| 351 | if (first) |
| 352 | first = false; |
| 353 | else |
| 354 | watchercallback(changes); |
| 355 | return; |
| 356 | } |
| 357 | |
| 358 | if (app !== null) { |
| 359 | try |
| 360 | { |
| 361 | isSkip = true; |
| 362 | process.kill(app.pid); |
| 363 | if (options.inspector) { |
| 364 | setTimeout(restart, 1000); |
| 365 | return; |
| 366 | } |
| 367 | } catch (err) {} |
| 368 | app = null; |
| 369 | } |
| 370 | |
| 371 | var arr = ARGV.slice(2); |
| 372 | |
| 373 | var port = arr.pop(); |
| 374 | |
| 375 | if (process.execArgv.indexOf('--debug') !== -1 || options.debugger) { |
| 376 | var key = '--debug=' + (options.debugger || 40894); |
| 377 | process.execArgv.indexOf(key) === -1 && process.execArgv.push(key); |
| 378 | } |
| 379 | |
| 380 | if (process.execArgv.indexOf('--inspect') !== -1 || options.inspector) { |
| 381 | var key = '--inspect=' + (options.inspector || 9229); |
| 382 | process.execArgv.indexOf(key) === -1 && process.execArgv.push(key); |
| 383 | } |
| 384 | |
| 385 | if (first) |
| 386 | first = false; |
| 387 | else |
| 388 | arr.push('restart'); |
| 389 | |
| 390 | arr.push('debugging'); |
| 391 | port && arr.push(port); |
| 392 | |
| 393 | app = fork(Path.join(directory, FILENAME), arr); |
| 394 | |
| 395 | app.on('message', function(msg) { |
| 396 | switch (msg) { |
| 397 | case 'total:eaddrinuse': |
| 398 | process.exit(1); |
| 399 | break; |
| 400 | case 'total:restart': |
| 401 | console.log(makestamp().replace('#', 'RES')); |
| 402 | restart(); |
| 403 | break; |
| 404 | case 'total:ready': |
| 405 | if (status === 0) { |
no test coverage detected