From f4341bb5f573ba9dfd437cf76bed094b5c62379c Mon Sep 17 00:00:00 2001 From: Vincent TAING Date: Thu, 15 Sep 2016 17:40:44 +0200 Subject: [PATCH 1/5] adds file paths to config/paths.js, try to retrieve required files when starting --- config/paths.js | 6 ++++++ scripts/start.js | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/config/paths.js b/config/paths.js index 9fbb4ecbc56..8227a239b16 100644 --- a/config/paths.js +++ b/config/paths.js @@ -34,7 +34,9 @@ function resolveApp(relativePath) { // config after eject: we're in ./config/ module.exports = { appBuild: resolveApp('build'), + appFavico: resolveOwn('src/favicon.ico'), appHtml: resolveApp('index.html'), + appIndexJs: resolveApp('src/index.js'), appPackageJson: resolveApp('package.json'), appSrc: resolveApp('src'), testsSetup: resolveApp('src/setupTests.js'), @@ -51,7 +53,9 @@ function resolveOwn(relativePath) { // config before eject: we're in ./node_modules/react-scripts/config/ module.exports = { appBuild: resolveApp('build'), + appFavico: resolveApp('src/favicon.ico'), appHtml: resolveApp('index.html'), + appIndexJs: resolveApp('src/index.js'), appPackageJson: resolveApp('package.json'), appSrc: resolveApp('src'), testsSetup: resolveApp('src/setupTests.js'), @@ -65,7 +69,9 @@ module.exports = { // @remove-on-publish-begin module.exports = { appBuild: resolveOwn('../build'), + appFavico: resolveOwn('../template/src/favicon.ico'), appHtml: resolveOwn('../template/index.html'), + appIndexJs: resolveOwn('../template/src/index.js'), appPackageJson: resolveOwn('../package.json'), appSrc: resolveOwn('../template/src'), testsSetup: resolveOwn('../template/src/setupTests.js'), diff --git a/scripts/start.js b/scripts/start.js index 32f20c25fcf..4d62ea1e534 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -11,6 +11,7 @@ process.env.NODE_ENV = 'development'; +var fs = require('fs'); var path = require('path'); var chalk = require('chalk'); var webpack = require('webpack'); @@ -170,6 +171,20 @@ function openBrowser(port, protocol) { opn(protocol + '://localhost:' + port + '/'); } +function checkRequiredFiles() { + var filesPathToCheck = [paths.appHtml, paths.appIndexJs, paths.appFavico]; + filesPathToCheck.forEach(function(filePath) { + fs.access(filePath, fs.constants.F_OK, function(err) { + if(err) { + var fileName = path.basename(filePath); + console.log( + chalk.red(`Cannot find ${fileName} in ${filePath} directory`) + ); + process.exit(1); + } + }); + }); +} // We need to provide a custom onError function for httpProxyMiddleware. // It allows us to log custom error messages on the console. function onProxyError(proxy) { @@ -180,7 +195,7 @@ function onProxyError(proxy) { ' from ' + chalk.cyan(host) + ' to ' + chalk.cyan(proxy) + '.' ); console.log( - 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' + + 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' + chalk.cyan(err.code) + ').' ); console.log(); @@ -190,7 +205,7 @@ function onProxyError(proxy) { if (res.writeHead && !res.headersSent) { res.writeHead(500); } - res.end('Proxy error: Could not proxy request ' + req.url + ' from ' + + res.end('Proxy error: Could not proxy request ' + req.url + ' from ' + host + ' to ' + proxy + ' (' + err.code + ').' ); } @@ -304,6 +319,7 @@ function runDevServer(port, protocol) { function run(port) { var protocol = process.env.HTTPS === 'true' ? "https" : "http"; + checkRequiredFiles(); setupCompiler(port, protocol); runDevServer(port, protocol); } From 6da870a8a9e84d8c146118def02a449eb3d9ff72 Mon Sep 17 00:00:00 2001 From: Vincent TAING Date: Thu, 15 Sep 2016 18:33:00 +0200 Subject: [PATCH 2/5] change resolveOwn > resolveApp --- config/paths.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/paths.js b/config/paths.js index 8227a239b16..3767646ac3b 100644 --- a/config/paths.js +++ b/config/paths.js @@ -34,7 +34,7 @@ function resolveApp(relativePath) { // config after eject: we're in ./config/ module.exports = { appBuild: resolveApp('build'), - appFavico: resolveOwn('src/favicon.ico'), + appFavico: resolveApp('src/favicon.ico'), appHtml: resolveApp('index.html'), appIndexJs: resolveApp('src/index.js'), appPackageJson: resolveApp('package.json'), From aa9f5c8ecce16b72672039304785c61c0ccf532d Mon Sep 17 00:00:00 2001 From: Vincent TAING Date: Sat, 17 Sep 2016 23:24:31 +0200 Subject: [PATCH 3/5] tries to access synchronously the required files --- scripts/start.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/start.js b/scripts/start.js index 4d62ea1e534..291dac47a3d 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -174,15 +174,15 @@ function openBrowser(port, protocol) { function checkRequiredFiles() { var filesPathToCheck = [paths.appHtml, paths.appIndexJs, paths.appFavico]; filesPathToCheck.forEach(function(filePath) { - fs.access(filePath, fs.constants.F_OK, function(err) { - if(err) { - var fileName = path.basename(filePath); - console.log( - chalk.red(`Cannot find ${fileName} in ${filePath} directory`) - ); - process.exit(1); - } - }); + try { + fs.accessSync(filePath, fs.F_OK); + } catch (err) { + var fileName = path.basename(filePath); + console.log( + chalk.red(`Cannot find ${fileName} in ${filePath} directory`) + ); + process.exit(1); + } }); } // We need to provide a custom onError function for httpProxyMiddleware. From cb3f4a68f3770bd68da04d6ca286db0cb90471bb Mon Sep 17 00:00:00 2001 From: Vincent TAING Date: Sat, 17 Sep 2016 23:30:23 +0200 Subject: [PATCH 4/5] uses appIndexJs variable for specifying entry path in webpack configs --- config/webpack.config.dev.js | 2 +- config/webpack.config.prod.js | 2 +- scripts/start.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js index 34bda5590a3..d45e0a9e0e6 100644 --- a/config/webpack.config.dev.js +++ b/config/webpack.config.dev.js @@ -49,7 +49,7 @@ module.exports = { // We ship a few polyfills by default. require.resolve('./polyfills'), // Finally, this is your app's code: - path.join(paths.appSrc, 'index') + paths.appIndexJs // We include the app code last so that if there is a runtime error during // initialization, it doesn't blow up the WebpackDevServer client, and // changing JS code would still trigger a refresh. diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js index c03b6ef272f..50c38923990 100644 --- a/config/webpack.config.prod.js +++ b/config/webpack.config.prod.js @@ -48,7 +48,7 @@ module.exports = { // In production, we only want to load the polyfills and the app code. entry: [ require.resolve('./polyfills'), - path.join(paths.appSrc, 'index') + paths.appIndexJs ], output: { // The build folder. diff --git a/scripts/start.js b/scripts/start.js index 291dac47a3d..d3e1f88343a 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -172,7 +172,7 @@ function openBrowser(port, protocol) { } function checkRequiredFiles() { - var filesPathToCheck = [paths.appHtml, paths.appIndexJs, paths.appFavico]; + var filesPathToCheck = [paths.appHtml, paths.appIndexJs]; filesPathToCheck.forEach(function(filePath) { try { fs.accessSync(filePath, fs.F_OK); From dfb3c4ea7eade1b2b99bbe873978b3fa46dcd068 Mon Sep 17 00:00:00 2001 From: Vincent TAING Date: Sat, 17 Sep 2016 23:36:15 +0200 Subject: [PATCH 5/5] removes favico from the paths --- config/paths.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/config/paths.js b/config/paths.js index 3767646ac3b..0041e66330d 100644 --- a/config/paths.js +++ b/config/paths.js @@ -34,7 +34,6 @@ function resolveApp(relativePath) { // config after eject: we're in ./config/ module.exports = { appBuild: resolveApp('build'), - appFavico: resolveApp('src/favicon.ico'), appHtml: resolveApp('index.html'), appIndexJs: resolveApp('src/index.js'), appPackageJson: resolveApp('package.json'), @@ -53,7 +52,6 @@ function resolveOwn(relativePath) { // config before eject: we're in ./node_modules/react-scripts/config/ module.exports = { appBuild: resolveApp('build'), - appFavico: resolveApp('src/favicon.ico'), appHtml: resolveApp('index.html'), appIndexJs: resolveApp('src/index.js'), appPackageJson: resolveApp('package.json'), @@ -69,7 +67,6 @@ module.exports = { // @remove-on-publish-begin module.exports = { appBuild: resolveOwn('../build'), - appFavico: resolveOwn('../template/src/favicon.ico'), appHtml: resolveOwn('../template/index.html'), appIndexJs: resolveOwn('../template/src/index.js'), appPackageJson: resolveOwn('../package.json'),