-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
checkRequired.ts
43 lines (42 loc) · 1.59 KB
/
checkRequired.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import fs from 'fs';
import path from 'path';
import 'react-dev-utils/checkRequiredFiles';
import { reactDevUtils } from '../utils/path';
import { OverridePaths } from './paths';
/**
* Fix `--app-src ./website`
* [create-react-app/react-dev-utils/checkRequiredFiles.js](https://github.com/facebook/create-react-app/blob/0f6fc2bc71d78f0dcae67f3f08ce98a42fc0a57c/packages/react-dev-utils/checkRequiredFiles.js#L14-L30)
*/
export function checkRequiredFiles(paths: OverridePaths, isNotCheckHTML: boolean) {
const checkRequiredFilesPath = `${reactDevUtils}/checkRequiredFiles`;
require.cache[require.resolve(checkRequiredFilesPath)].exports = (files: (fs.PathLike | undefined)[] = []) => {
files = files
.map((item) => {
if (/(\.html)$/.test(item as string) && isNotCheckHTML) {
return;
}
if (paths._oldPaths && item === paths._oldPaths.appIndexJs) {
return paths.appIndexJs;
}
return item;
})
.filter(Boolean);
let currentFilePath;
try {
files.forEach((filePath) => {
currentFilePath = filePath;
filePath && fs.accessSync(filePath, fs.constants.F_OK);
});
return true;
} catch (err) {
if (currentFilePath) {
const dirName = path.dirname(currentFilePath);
const fileName = path.basename(currentFilePath);
console.log('\x1b[1;31m Could not find a required file. \x1b[0m');
console.log(`\x1b[1;31m Name: \x1b[0m ${fileName}`);
console.log(`\x1b[1;31m Searched in: \x1b[0m \x1b[1;36m${dirName}\x1b[0m`);
}
return false;
}
};
}