Skip to content

Commit f8b4726

Browse files
committed
Add missing file check to npm run build too
1 parent 4a0f39a commit f8b4726

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

scripts/build.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ var rimrafSync = require('rimraf').sync;
2121
var webpack = require('webpack');
2222
var config = require('../config/webpack.config.prod');
2323
var paths = require('../config/paths');
24+
var checkRequiredFiles = require('./utils/checkRequiredFiles');
2425
var recursive = require('recursive-readdir');
2526
var stripAnsi = require('strip-ansi');
2627

28+
checkRequiredFiles();
29+
2730
// Input: /User/dan/app/build/static/js/main.82be8.js
2831
// Output: /static/js/main.js
2932
function removeFileNameHash(fileName) {

scripts/eject.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ prompt(
4444
path.join('config', 'jest', 'transform.js'),
4545
path.join('scripts', 'build.js'),
4646
path.join('scripts', 'start.js'),
47+
path.join('scripts', 'utils', 'checkRequiredFiles.js'),
4748
path.join('scripts', 'utils', 'chrome.applescript'),
4849
path.join('scripts', 'utils', 'prompt.js'),
4950
path.join('scripts', 'utils', 'WatchMissingNodeModulesPlugin.js')

scripts/start.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
process.env.NODE_ENV = 'development';
1313

14-
var fs = require('fs');
1514
var path = require('path');
1615
var chalk = require('chalk');
1716
var webpack = require('webpack');
@@ -21,6 +20,7 @@ var httpProxyMiddleware = require('http-proxy-middleware');
2120
var execSync = require('child_process').execSync;
2221
var opn = require('opn');
2322
var detect = require('detect-port');
23+
var checkRequiredFiles = require('./utils/checkRequiredFiles');
2424
var prompt = require('./utils/prompt');
2525
var config = require('../config/webpack.config.dev');
2626
var paths = require('../config/paths');
@@ -171,20 +171,6 @@ function openBrowser(port, protocol) {
171171
opn(protocol + '://localhost:' + port + '/');
172172
}
173173

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-
}
188174
// We need to provide a custom onError function for httpProxyMiddleware.
189175
// It allows us to log custom error messages on the console.
190176
function onProxyError(proxy) {

scripts/utils/checkRequiredFiles.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @remove-on-eject-begin
2+
/**
3+
* Copyright (c) 2015-present, Facebook, Inc.
4+
* All rights reserved.
5+
*
6+
* This source code is licensed under the BSD-style license found in the
7+
* LICENSE file in the root directory of this source tree. An additional grant
8+
* of patent rights can be found in the PATENTS file in the same directory.
9+
*/
10+
// @remove-on-eject-end
11+
12+
const fs = require('fs');
13+
const path = require('path');
14+
const chalk = require('chalk');
15+
const paths = require('../../config/paths');
16+
17+
function checkRequiredFiles() {
18+
const filesPathToCheck = [paths.appHtml, paths.appIndexJs];
19+
filesPathToCheck.forEach(filePath => {
20+
try {
21+
fs.accessSync(filePath, fs.F_OK);
22+
} catch (err) {
23+
const dirName = path.dirname(filePath);
24+
const fileName = path.basename(filePath);
25+
console.log(chalk.red('Could not find a required file.'));
26+
console.log(chalk.red(' Name: ') + chalk.cyan(fileName));
27+
console.log(chalk.red(' Searched in: ') + chalk.cyan(dirName));
28+
process.exit(1);
29+
}
30+
});
31+
}
32+
33+
module.exports = checkRequiredFiles;

0 commit comments

Comments
 (0)