Skip to content

Commit

Permalink
fix(react): fix nx init so that it works on Windows (#14586)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored and vsavkin committed Jan 24, 2023
1 parent c25bb3a commit 692ecb6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- e2e-angular-core
- e2e-angular-extensions
- e2e-nx-run,e2e-nx-misc,e2e-nx-plugin
- e2e-cra-to-nx
- e2e-make-angular-cli-faster
- e2e-jest
- e2e-linter
Expand Down
25 changes: 13 additions & 12 deletions packages/cra-to-nx/src/lib/cra-to-nx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execSync } from 'child_process';
import { join } from 'path';
import { copySync, moveSync, readdirSync, removeSync } from 'fs-extra';

import { fileExists, readJsonFile } from 'nx/src/utils/fileutils';
Expand Down Expand Up @@ -107,7 +108,7 @@ async function reorgnizeWorkspaceStructure(options: NormalizedOptions) {
execSync(`echo "node_modules" >> .gitignore`, { stdio: [0, 1, 2] });
execSync(`echo "dist" >> .gitignore`, { stdio: [0, 1, 2] });

process.chdir('../');
process.chdir('..');

copyFromTempWorkspaceToRoot();

Expand Down Expand Up @@ -154,10 +155,10 @@ async function reorgnizeWorkspaceStructure(options: NormalizedOptions) {
if (options.isVite) {
const indexPath = options.isStandalone
? 'index.html'
: `apps/${options.reactAppName}/index.html`;
: join('apps', options.reactAppName, 'index.html');
const oldIndexPath = options.isStandalone
? 'public/index.html'
: `apps/${options.reactAppName}/public/index.html`;
? join('public', 'index.html')
: join('apps', options.reactAppName, 'public', 'index.html');
output.note({
title: `A new ${indexPath} has been created. Compare it to the previous ${oldIndexPath} file and make any changes needed, then delete the previous file.`,
});
Expand Down Expand Up @@ -194,10 +195,10 @@ function createTempWorkspace(options: NormalizedOptions) {
output.log({ title: '🧹 Clearing unused files' });

copySync(
`temp-workspace/apps/${options.reactAppName}/project.json`,
join('temp-workspace', 'apps', options.reactAppName, 'project.json'),
'project.json'
);
removeSync(`temp-workspace/apps/${options.reactAppName}/`);
removeSync(join('temp-workspace', 'apps', options.reactAppName));
removeSync('node_modules');
}

Expand Down Expand Up @@ -226,8 +227,8 @@ function moveFilesToTempWorkspace(options: NormalizedOptions) {
moveSync(
f,
options.isStandalone
? `temp-workspace/${f}`
: `temp-workspace/apps/${options.reactAppName}/${f}`,
? join('temp-workspace', f)
: join('temp-workspace', 'apps', options.reactAppName, f),
{
overwrite: true,
}
Expand All @@ -239,7 +240,7 @@ function moveFilesToTempWorkspace(options: NormalizedOptions) {
}
});

process.chdir('temp-workspace/');
process.chdir('temp-workspace');
}

async function addBundler(options: NormalizedOptions) {
Expand Down Expand Up @@ -287,8 +288,8 @@ async function addBundler(options: NormalizedOptions) {
function copyFromTempWorkspaceToRoot() {
output.log({ title: '🚚 Folder restructuring.' });

readdirSync('./temp-workspace').forEach((f) => {
moveSync(`temp-workspace/${f}`, `./${f}`, { overwrite: true });
readdirSync('temp-workspace').forEach((f) => {
moveSync(join('temp-workspace', f), f, { overwrite: true });
});
}

Expand All @@ -305,7 +306,7 @@ function cleanUpUnusedFilesAndAddConfigFiles(options: NormalizedOptions) {
output.log({ title: '📃 Setup e2e tests' });
setupE2eProject(options.reactAppName);
} else {
removeSync(`apps/${options.reactAppName}-e2e`);
removeSync(join('apps', `${options.reactAppName}-e2e`));
execSync(`${options.pmc.rm} @nrwl/cypress eslint-plugin-cypress`);
}

Expand Down

0 comments on commit 692ecb6

Please sign in to comment.