@@ -35,6 +35,7 @@ var paths = require('../config/paths');
35
35
36
36
var useYarn = pathExists . sync ( paths . yarnLockFile ) ;
37
37
var cli = useYarn ? 'yarn' : 'npm' ;
38
+ var isInteractive = process . stdout . isTTY ;
38
39
39
40
// Warn and crash if required files are missing
40
41
if ( ! checkRequiredFiles ( [ paths . appHtml , paths . appIndexJs ] ) ) {
@@ -69,21 +70,33 @@ function setupCompiler(host, port, protocol) {
69
70
// bundle, so if you refresh, it'll wait instead of serving the old one.
70
71
// "invalid" is short for "bundle invalidated", it doesn't imply any errors.
71
72
compiler . plugin ( 'invalid' , function ( ) {
72
- clearConsole ( ) ;
73
+ if ( isInteractive ) {
74
+ clearConsole ( ) ;
75
+ }
73
76
console . log ( 'Compiling...' ) ;
74
77
} ) ;
75
78
79
+ var isFirstCompile = true ;
80
+
76
81
// "done" event fires when Webpack has finished recompiling the bundle.
77
82
// Whether or not you have warnings or errors, you will get this event.
78
83
compiler . plugin ( 'done' , function ( stats ) {
79
- clearConsole ( ) ;
84
+ if ( isInteractive ) {
85
+ clearConsole ( ) ;
86
+ }
80
87
81
88
// We have switched off the default Webpack output in WebpackDevServer
82
89
// options so we are going to "massage" the warnings and errors and present
83
90
// them in a readable focused way.
84
91
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 ) {
86
96
console . log ( chalk . green ( 'Compiled successfully!' ) ) ;
97
+ }
98
+
99
+ if ( showInstructions ) {
87
100
console . log ( ) ;
88
101
console . log ( 'The app is running at:' ) ;
89
102
console . log ( ) ;
@@ -92,6 +105,7 @@ function setupCompiler(host, port, protocol) {
92
105
console . log ( 'Note that the development build is not optimized.' ) ;
93
106
console . log ( 'To create a production build, use ' + chalk . cyan ( cli + ' run build' ) + '.' ) ;
94
107
console . log ( ) ;
108
+ isFirstCompile = false ;
95
109
}
96
110
97
111
// If errors exist, only show errors.
@@ -258,10 +272,15 @@ function runDevServer(host, port, protocol) {
258
272
return console . log ( err ) ;
259
273
}
260
274
261
- clearConsole ( ) ;
275
+ if ( isInteractive ) {
276
+ clearConsole ( ) ;
277
+ }
262
278
console . log ( chalk . cyan ( 'Starting the development server...' ) ) ;
263
279
console . log ( ) ;
264
- openBrowser ( protocol + '://' + host + ':' + port + '/' ) ;
280
+
281
+ if ( isInteractive ) {
282
+ openBrowser ( protocol + '://' + host + ':' + port + '/' ) ;
283
+ }
265
284
} ) ;
266
285
}
267
286
@@ -280,16 +299,20 @@ detect(DEFAULT_PORT).then(port => {
280
299
return ;
281
300
}
282
301
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?' ;
289
309
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
+ }
295
318
} ) ;
0 commit comments