Skip to content

Commit

Permalink
fix(kkt): Fix --app-src args errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 20, 2021
1 parent 81b99b2 commit d648429
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
12 changes: 11 additions & 1 deletion core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,24 @@ KKT uses the `homepage` field to determine the root URL in the built HTML file.

### Development

Runs the project in development mode.

```bash
npm run hoist
npm run bootstrap
npm run build

npm run lib:watch
npm run kkt:watch
```

### Production

Builds the app for production to the build folder.

```bash
npm run build
```

### Acknowledgements

[@timarney](https://github.com/timarney) for having created [react-app-rewired](https://github.com/timarney/react-app-rewired).
Expand Down
36 changes: 36 additions & 0 deletions core/src/overrides/checkRequired.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import fs from 'fs';
import path from 'path';
import { reactDevUtils } from '../utils/path';
import { OverridePaths } from './paths';

/**
* [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) {
const checkRequiredFilesPath = `${reactDevUtils}/checkRequiredFiles`;
require(checkRequiredFilesPath);
require.cache[require.resolve(checkRequiredFilesPath)].exports = (files: fs.PathLike[]) => {
files = files.map(item => {
if (paths._oldPaths && item === paths._oldPaths.appIndexJs) {
return paths.appIndexJs
}
return item
});

let currentFilePath;
try {
files.forEach(filePath => {
currentFilePath = filePath;
fs.accessSync(filePath, fs.constants.F_OK);
});
return true;
} catch (err) {
var dirName = path.dirname(currentFilePath);
var 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;
}
};
}
2 changes: 1 addition & 1 deletion core/src/overrides/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type OverridePaths = Paths & {
* - [create-react-app/react-scripts/react-scripts/config/paths.js](https://github.com/facebook/create-react-app/blob/0f6fc2bc71d78f0dcae67f3f08ce98a42fc0a57c/packages/react-scripts/config/paths.js#L83-L105)
*/
export const overridePaths = (
argvs = undefined as ParsedArgs | undefined,
argvs?: ParsedArgs,
opts: Record<string, string> = {},
): OverridePaths => {
const pathsConfPath = `${reactScripts}/config/paths`;
Expand Down
4 changes: 3 additions & 1 deletion core/src/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { KKTRC } from '../utils/loaderConf';
import { reactScripts, isWebpackFactory } from '../utils/path';
import { overridePaths } from '../overrides/paths';
import { miniCssExtractPlugin } from '../utils/miniCssExtractPlugin';
import { checkRequiredFiles } from '../overrides/checkRequired';
import { BuildArgs } from '..';

export default async function build(argvs: BuildArgs) {
try {
const paths = await overridePaths(argvs);
await checkRequiredFiles(paths);
const webpackConfigPath = `${reactScripts}/config/webpack.config${!isWebpackFactory ? '.prod' : ''}`;
const createWebpackConfig: (env: string) => Configuration = require(webpackConfigPath);
const overrides = require('../overrides/config');
Expand All @@ -32,7 +34,7 @@ export default async function build(argvs: BuildArgs) {
}

// run original script
require(`${reactScripts}/scripts/build`);
await require(`${reactScripts}/scripts/build`);
} catch (error) {
console.log('KKT:BUILD:ERROR:', error);
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/scripts/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import { overridesClearConsole } from '../overrides/clearConsole';
import { overridesChoosePort } from '../overrides/choosePort';
import { miniCssExtractPlugin } from '../utils/miniCssExtractPlugin';
import { cacheData } from '../utils/cacheData';
import { checkRequiredFiles } from '../overrides/checkRequired';
import { StartArgs } from '..';

export default async function start(argvs: StartArgs) {
try {
const paths = await overridePaths(argvs);
await checkRequiredFiles(paths);
const webpackConfigPath = `${reactScripts}/config/webpack.config${!isWebpackFactory ? '.dev' : ''}`;
const devServerConfigPath = `${reactScripts}/config/webpackDevServer.config.js`;
const createWebpackConfig: (env: string) => Configuration = require(webpackConfigPath);
Expand Down

0 comments on commit d648429

Please sign in to comment.