diff --git a/config/paths.js b/config/paths.js index bb1ba761258..c3594e14519 100644 --- a/config/paths.js +++ b/config/paths.js @@ -39,6 +39,7 @@ var nodePaths = (process.env.NODE_PATH || '') module.exports = { appBuild: resolveApp('build'), appHtml: resolveApp('index.html'), + appIndexJs: resolveApp('src/index.js'), appPackageJson: resolveApp('package.json'), appSrc: resolveApp('src'), testsSetup: resolveApp('src/setupTests.js'), @@ -56,6 +57,7 @@ function resolveOwn(relativePath) { module.exports = { appBuild: resolveApp('build'), appHtml: resolveApp('index.html'), + appIndexJs: resolveApp('src/index.js'), appPackageJson: resolveApp('package.json'), appSrc: resolveApp('src'), testsSetup: resolveApp('src/setupTests.js'), @@ -70,6 +72,7 @@ module.exports = { module.exports = { appBuild: resolveOwn('../build'), 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/config/webpack.config.dev.js b/config/webpack.config.dev.js index 86f592ba5b8..a88409f2d05 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 2a482f9547e..552ded48551 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/build.js b/scripts/build.js index e60b554466f..71dcc798bba 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -21,9 +21,12 @@ var rimrafSync = require('rimraf').sync; var webpack = require('webpack'); var config = require('../config/webpack.config.prod'); var paths = require('../config/paths'); +var checkRequiredFiles = require('./utils/checkRequiredFiles'); var recursive = require('recursive-readdir'); var stripAnsi = require('strip-ansi'); +checkRequiredFiles(); + // Input: /User/dan/app/build/static/js/main.82be8.js // Output: /static/js/main.js function removeFileNameHash(fileName) { diff --git a/scripts/eject.js b/scripts/eject.js index 3e5e18af387..74c5c9ef99b 100644 --- a/scripts/eject.js +++ b/scripts/eject.js @@ -44,6 +44,7 @@ prompt( path.join('config', 'jest', 'transform.js'), path.join('scripts', 'build.js'), path.join('scripts', 'start.js'), + path.join('scripts', 'utils', 'checkRequiredFiles.js'), path.join('scripts', 'utils', 'chrome.applescript'), path.join('scripts', 'utils', 'prompt.js'), path.join('scripts', 'utils', 'WatchMissingNodeModulesPlugin.js') diff --git a/scripts/start.js b/scripts/start.js index be1d6f80e0d..84d1e7c4b48 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -20,6 +20,7 @@ var httpProxyMiddleware = require('http-proxy-middleware'); var execSync = require('child_process').execSync; var opn = require('opn'); var detect = require('detect-port'); +var checkRequiredFiles = require('./utils/checkRequiredFiles'); var prompt = require('./utils/prompt'); var config = require('../config/webpack.config.dev'); var paths = require('../config/paths'); @@ -180,7 +181,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 +191,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 +305,7 @@ function runDevServer(port, protocol) { function run(port) { var protocol = process.env.HTTPS === 'true' ? "https" : "http"; + checkRequiredFiles(); setupCompiler(port, protocol); runDevServer(port, protocol); } diff --git a/scripts/utils/checkRequiredFiles.js b/scripts/utils/checkRequiredFiles.js new file mode 100644 index 00000000000..8110eb01cdb --- /dev/null +++ b/scripts/utils/checkRequiredFiles.js @@ -0,0 +1,33 @@ +// @remove-on-eject-begin +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +// @remove-on-eject-end + +const fs = require('fs'); +const path = require('path'); +const chalk = require('chalk'); +const paths = require('../../config/paths'); + +function checkRequiredFiles() { + const filesPathToCheck = [paths.appHtml, paths.appIndexJs]; + filesPathToCheck.forEach(filePath => { + try { + fs.accessSync(filePath, fs.F_OK); + } catch (err) { + const dirName = path.dirname(filePath); + const fileName = path.basename(filePath); + console.log(chalk.red('Could not find a required file.')); + console.log(chalk.red(' Name: ') + chalk.cyan(fileName)); + console.log(chalk.red(' Searched in: ') + chalk.cyan(dirName)); + process.exit(1); + } + }); +} + +module.exports = checkRequiredFiles;