11
11
12
12
process . env . NODE_ENV = 'development' ;
13
13
14
+ var fs = require ( 'fs' ) ;
14
15
var path = require ( 'path' ) ;
15
16
var chalk = require ( 'chalk' ) ;
16
17
var webpack = require ( 'webpack' ) ;
@@ -170,6 +171,20 @@ function openBrowser(port, protocol) {
170
171
opn ( protocol + '://localhost:' + port + '/' ) ;
171
172
}
172
173
174
+ function checkRequiredFiles ( ) {
175
+ var filesPathToCheck = [ paths . appHtml , paths . appIndexJs ] ;
176
+ filesPathToCheck . forEach ( function ( filePath ) {
177
+ try {
178
+ fs . accessSync ( filePath , fs . F_OK ) ;
179
+ } catch ( err ) {
180
+ var fileName = path . basename ( filePath ) ;
181
+ console . log (
182
+ chalk . red ( `Cannot find ${ fileName } in ${ filePath } directory` )
183
+ ) ;
184
+ process . exit ( 1 ) ;
185
+ }
186
+ } ) ;
187
+ }
173
188
// We need to provide a custom onError function for httpProxyMiddleware.
174
189
// It allows us to log custom error messages on the console.
175
190
function onProxyError ( proxy ) {
@@ -180,7 +195,7 @@ function onProxyError(proxy) {
180
195
' from ' + chalk . cyan ( host ) + ' to ' + chalk . cyan ( proxy ) + '.'
181
196
) ;
182
197
console . log (
183
- 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
198
+ 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
184
199
chalk . cyan ( err . code ) + ').'
185
200
) ;
186
201
console . log ( ) ;
@@ -190,7 +205,7 @@ function onProxyError(proxy) {
190
205
if ( res . writeHead && ! res . headersSent ) {
191
206
res . writeHead ( 500 ) ;
192
207
}
193
- res . end ( 'Proxy error: Could not proxy request ' + req . url + ' from ' +
208
+ res . end ( 'Proxy error: Could not proxy request ' + req . url + ' from ' +
194
209
host + ' to ' + proxy + ' (' + err . code + ').'
195
210
) ;
196
211
}
@@ -304,6 +319,7 @@ function runDevServer(port, protocol) {
304
319
305
320
function run ( port ) {
306
321
var protocol = process . env . HTTPS === 'true' ? "https" : "http" ;
322
+ checkRequiredFiles ( ) ;
307
323
setupCompiler ( port , protocol ) ;
308
324
runDevServer ( port , protocol ) ;
309
325
}
0 commit comments