/**
 * React Starter Kit (http://www.reactstarterkit.com/)
 *
 * Copyright © 2014-2015 Kriasoft, LLC. All rights reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.txt file in the root directory of this source tree.
 */

import path from 'path';
import cp from 'child_process';
import watch from './lib/watch';

/**
 * Launches Node.js/Express web server in a separate (forked) process.
 */
function serve() {
  return new Promise((resolve, reject) => {
    function start() {
      const server = cp.spawn('node', [path.join(__dirname, '../build/server.js')], {
        env: Object.assign({ NODE_ENV: 'development' }, process.env),
        silent: false,
      });

      server.stdout.on('data', data => {
        const message = data.toString();
        if (message.match(' running ')) {
          console.log(message.trim());
          resolve();
        } else {
          console.log(message);
        }
      });

      server.stderr.once('data', data => {
        reject(data.toString());
      });

      server.on('error', err => reject(err));
      process.on('exit', () => server.kill('SIGTERM'));
      return server;
    }

    let server = start();

    if (global.WATCH) {
      watch('build/server.js').then(watcher => {
        watcher.on('changed', () => {
          server.kill('SIGTERM');
          server = start();
        });
      });
    }
  });
}

export default serve;

@@ -544,15 +544,32 @@
 awn(
-'node',
+%0A        'node',%0A       
  %5Bpa
@@ -610,19 +610,29 @@
 r.js')%5D,
+%0A       
  %7B%0A
+  
         
@@ -701,16 +701,18 @@
         
+  
 silent: 
@@ -718,27 +718,35 @@
  false,%0A
+  
       %7D
+%0A      
 );%0A
-%0A
       se
@@ -790,189 +790,280 @@
     
-const message = data.toString();%0A        if (message.match(' running ')) %7B%0A          console.log(message.trim());%0A          resolve();%0A        %7D else %7B%0A          console.log(message
+let time = new Date().toTimeString();%0A        time = time.replace(/.*(%5Cd%7B2%7D:%5Cd%7B2%7D:%5Cd%7B2%7D).*/, '$1');%0A        process.stdout.write(%60%5B$%7Btime%7D%5D %60);%0A        process.stdout.write(data);%0A        if (data.toString('utf8').includes('The server is running at')) %7B%0A          resolve(
 );%0A 
@@ -1073,33 +1073,32 @@
     %7D%0A      %7D);%0A
-%0A
       server.std
@@ -1103,18 +1103,16 @@
 tderr.on
-ce
 ('data',
@@ -1124,53 +1124,36 @@
  =%3E 
-%7B%0A        reject(data.toString());%0A      %7D);%0A
+process.stderr.write(data));
 %0A   

Update tools/serve.js script