|
8 | 8 | */ |
9 | 9 | import launchChrome from '../launchChrome'; |
10 | 10 | import logger from '../../../tools/logger'; |
| 11 | +import {exec} from 'child_process'; |
11 | 12 |
|
12 | 13 | function launchChromeDevTools(port, args = '') { |
13 | 14 | const debuggerURL = `http://localhost:${port}/debugger-ui${args}`; |
14 | 15 | logger.info('Launching Dev Tools...'); |
15 | 16 | launchChrome(debuggerURL); |
16 | 17 | } |
17 | 18 |
|
| 19 | +function escapePath(pathname) { |
| 20 | + // " Can escape paths with spaces in OS X, Windows, and *nix |
| 21 | + return `"${pathname}"`; |
| 22 | +} |
| 23 | + |
18 | 24 | function launchDevTools({port, watchFolders}, isChromeConnected) { |
19 | 25 | // Explicit config always wins |
20 | 26 | const customDebugger = process.env.REACT_DEBUGGER; |
21 | 27 | if (customDebugger) { |
22 | | - customDebugger({watchFolders, customDebugger}); |
| 28 | + startCustomDebugger({watchFolders, customDebugger}); |
23 | 29 | } else if (!isChromeConnected()) { |
24 | 30 | // Dev tools are not yet open; we need to open a session |
25 | 31 | launchChromeDevTools(port); |
26 | 32 | } |
27 | 33 | } |
28 | 34 |
|
| 35 | +function startCustomDebugger({watchFolders, customDebugger}) { |
| 36 | + const folders = watchFolders.map(escapePath).join(' '); |
| 37 | + const command = `${customDebugger} ${folders}`; |
| 38 | + console.log('Starting custom debugger by executing:', command); |
| 39 | + exec(command, function(error, stdout, stderr) { |
| 40 | + if (error !== null) { |
| 41 | + console.log('Error while starting custom debugger:', error); |
| 42 | + } |
| 43 | + }); |
| 44 | +} |
| 45 | + |
29 | 46 | export default function getDevToolsMiddleware(options, isChromeConnected) { |
30 | 47 | return function devToolsMiddleware(req, res, next) { |
31 | 48 | if (req.url === '/launch-safari-devtools') { |
|
0 commit comments