Skip to content

Commit ff1951b

Browse files
committed
Pulled out app paths to seperate config and added a check for required files in start script
1 parent e395498 commit ff1951b

File tree

5 files changed

+63
-15
lines changed

5 files changed

+63
-15
lines changed

config/appPaths.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
var path = require('path');
11+
12+
module.exports = function(relativePath) {
13+
14+
// TODO: hide this behind a flag and eliminate dead code on eject.
15+
// This shouldn't be exposed to the user.
16+
var isInNodeModules = 'node_modules' ===
17+
path.basename(path.resolve(path.join(__dirname, '..', '..')));
18+
19+
var srcPath = path.resolve(__dirname, relativePath, 'src');
20+
var nodeModulesPath = path.join(__dirname, '..', 'node_modules');
21+
var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html');
22+
var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico');
23+
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
24+
25+
return {
26+
srcPath: srcPath,
27+
nodeModulesPath: nodeModulesPath,
28+
indexHtmlPath: indexHtmlPath,
29+
faviconPath: faviconPath,
30+
buildPath: buildPath
31+
};
32+
};

config/webpack.config.dev.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ var autoprefixer = require('autoprefixer');
1212
var webpack = require('webpack');
1313
var HtmlWebpackPlugin = require('html-webpack-plugin');
1414

15-
// TODO: hide this behind a flag and eliminate dead code on eject.
16-
// This shouldn't be exposed to the user.
1715
var isInNodeModules = 'node_modules' ===
1816
path.basename(path.resolve(path.join(__dirname, '..', '..')));
1917
var relativePath = isInNodeModules ? '../../..' : '..';
@@ -23,11 +21,13 @@ var isInDebugMode = process.argv.some(arg =>
2321
if (isInDebugMode) {
2422
relativePath = '../template';
2523
}
26-
var srcPath = path.resolve(__dirname, relativePath, 'src');
27-
var nodeModulesPath = path.join(__dirname, '..', 'node_modules');
28-
var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html');
29-
var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico');
30-
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
24+
25+
var appPaths = require(path.join(__dirname, 'appPaths.js'))(relativePath);
26+
var srcPath = appPaths.srcPath;
27+
var nodeModulesPath = appPaths.nodeModulesPath;
28+
var indexHtmlPath = appPaths.indexHtmlPath;
29+
var faviconPath = appPaths.faviconPath;
30+
var buildPath = appPaths.buildPath;
3131

3232
module.exports = {
3333
devtool: 'eval',

config/webpack.config.prod.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ var webpack = require('webpack');
1313
var HtmlWebpackPlugin = require('html-webpack-plugin');
1414
var ExtractTextPlugin = require('extract-text-webpack-plugin');
1515

16-
// TODO: hide this behind a flag and eliminate dead code on eject.
17-
// This shouldn't be exposed to the user.
1816
var isInNodeModules = 'node_modules' ===
19-
path.basename(path.resolve(path.join(__dirname, '..', '..')));
17+
path.basename(path.resolve(path.join(__dirname, '..', '..')));
2018
var relativePath = isInNodeModules ? '../../..' : '..';
2119
if (process.argv[2] === '--debug-template') {
2220
relativePath = '../template';
2321
}
24-
var srcPath = path.resolve(__dirname, relativePath, 'src');
25-
var nodeModulesPath = path.join(__dirname, '..', 'node_modules');
26-
var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html');
27-
var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico');
28-
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
22+
23+
var appPaths = require(path.join(__dirname, 'appPaths.js'))(relativePath);
24+
var srcPath = appPaths.srcPath;
25+
var nodeModulesPath = appPaths.nodeModulesPath;
26+
var indexHtmlPath = appPaths.indexHtmlPath;
27+
var faviconPath = appPaths.faviconPath;
28+
var buildPath = appPaths.buildPath;
2929

3030
module.exports = {
3131
bail: true,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"eslint-plugin-import": "1.10.3",
4444
"eslint-plugin-react": "5.2.2",
4545
"extract-text-webpack-plugin": "1.0.1",
46+
"file-exists": "^1.0.0",
4647
"file-loader": "0.9.0",
4748
"fs-extra": "^0.30.0",
4849
"html-webpack-plugin": "2.22.0",

scripts/start.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var WebpackDevServer = require('webpack-dev-server');
1616
var config = require('../config/webpack.config.dev');
1717
var execSync = require('child_process').execSync;
1818
var opn = require('opn');
19+
var fileExists = require('file-exists');
1920

2021
// TODO: hide this behind a flag and eliminate dead code on eject.
2122
// This shouldn't be exposed to the user.
@@ -121,6 +122,19 @@ compiler.plugin('done', function (stats) {
121122
}
122123
});
123124

125+
function checkRequiredFiles() {
126+
var indexHtmlPath = path.join(__dirname, '../index.html');
127+
var faviconPath = path.join(__dirname, '../favicon.ico');
128+
var indexJsPath = path.join(__dirname, '../src/index.js');
129+
130+
[indexHtmlPath, faviconPath, indexJsPath]
131+
.forEach(function(requiredFile) {
132+
if (!fileExists(requiredFile)) {
133+
console.log(chalk.red('ERROR: ', requiredFile, ' is missing!'));
134+
}
135+
});
136+
}
137+
124138
function openBrowser() {
125139
if (process.platform === 'darwin') {
126140
try {
@@ -154,6 +168,7 @@ new WebpackDevServer(compiler, {
154168

155169
clearConsole();
156170
console.log(chalk.cyan('Starting the development server...'));
171+
checkRequiredFiles();
157172
console.log();
158173
openBrowser();
159174
});

0 commit comments

Comments
 (0)