@@ -35,6 +35,7 @@ var paths = require('../config/paths');
3535
3636var useYarn = pathExists . sync ( paths . yarnLockFile ) ;
3737var cli = useYarn ? 'yarn' : 'npm' ;
38+ var isInteractive = process . stdout . isTTY ;
3839
3940// Warn and crash if required files are missing
4041if ( ! checkRequiredFiles ( [ paths . appHtml , paths . appIndexJs ] ) ) {
@@ -69,21 +70,33 @@ function setupCompiler(host, port, protocol) {
6970 // bundle, so if you refresh, it'll wait instead of serving the old one.
7071 // "invalid" is short for "bundle invalidated", it doesn't imply any errors.
7172 compiler . plugin ( 'invalid' , function ( ) {
72- clearConsole ( ) ;
73+ if ( isInteractive ) {
74+ clearConsole ( ) ;
75+ }
7376 console . log ( 'Compiling...' ) ;
7477 } ) ;
7578
79+ var isFirstCompile = true ;
80+
7681 // "done" event fires when Webpack has finished recompiling the bundle.
7782 // Whether or not you have warnings or errors, you will get this event.
7883 compiler . plugin ( 'done' , function ( stats ) {
79- clearConsole ( ) ;
84+ if ( isInteractive ) {
85+ clearConsole ( ) ;
86+ }
8087
8188 // We have switched off the default Webpack output in WebpackDevServer
8289 // options so we are going to "massage" the warnings and errors and present
8390 // them in a readable focused way.
8491 var messages = formatWebpackMessages ( stats . toJson ( { } , true ) ) ;
85- if ( ! messages . errors . length && ! messages . warnings . length ) {
92+ var isSuccessful = ! messages . errors . length && ! messages . warnings . length ;
93+ var showInstructions = isSuccessful && ( isInteractive || isFirstCompile ) ;
94+
95+ if ( isSuccessful ) {
8696 console . log ( chalk . green ( 'Compiled successfully!' ) ) ;
97+ }
98+
99+ if ( showInstructions ) {
87100 console . log ( ) ;
88101 console . log ( 'The app is running at:' ) ;
89102 console . log ( ) ;
@@ -92,6 +105,7 @@ function setupCompiler(host, port, protocol) {
92105 console . log ( 'Note that the development build is not optimized.' ) ;
93106 console . log ( 'To create a production build, use ' + chalk . cyan ( cli + ' run build' ) + '.' ) ;
94107 console . log ( ) ;
108+ isFirstCompile = false ;
95109 }
96110
97111 // If errors exist, only show errors.
@@ -258,10 +272,15 @@ function runDevServer(host, port, protocol) {
258272 return console . log ( err ) ;
259273 }
260274
261- clearConsole ( ) ;
275+ if ( isInteractive ) {
276+ clearConsole ( ) ;
277+ }
262278 console . log ( chalk . cyan ( 'Starting the development server...' ) ) ;
263279 console . log ( ) ;
264- openBrowser ( protocol + '://' + host + ':' + port + '/' ) ;
280+
281+ if ( isInteractive ) {
282+ openBrowser ( protocol + '://' + host + ':' + port + '/' ) ;
283+ }
265284 } ) ;
266285}
267286
@@ -280,16 +299,20 @@ detect(DEFAULT_PORT).then(port => {
280299 return ;
281300 }
282301
283- clearConsole ( ) ;
284- var existingProcess = getProcessForPort ( DEFAULT_PORT ) ;
285- var question =
286- chalk . yellow ( 'Something is already running on port ' + DEFAULT_PORT + '.' +
287- ( ( existingProcess ) ? ' Probably:\n ' + existingProcess : '' ) ) +
288- '\n\nWould you like to run the app on another port instead?' ;
302+ if ( isInteractive ) {
303+ clearConsole ( ) ;
304+ var existingProcess = getProcessForPort ( DEFAULT_PORT ) ;
305+ var question =
306+ chalk . yellow ( 'Something is already running on port ' + DEFAULT_PORT + '.' +
307+ ( ( existingProcess ) ? ' Probably:\n ' + existingProcess : '' ) ) +
308+ '\n\nWould you like to run the app on another port instead?' ;
289309
290- prompt ( question , true ) . then ( shouldChangePort => {
291- if ( shouldChangePort ) {
292- run ( port ) ;
293- }
294- } ) ;
310+ prompt ( question , true ) . then ( shouldChangePort => {
311+ if ( shouldChangePort ) {
312+ run ( port ) ;
313+ }
314+ } ) ;
315+ } else {
316+ console . log ( chalk . red ( 'Something is already running on port ' + DEFAULT_PORT + '.' ) ) ;
317+ }
295318} ) ;
0 commit comments