fix(react): fix nx init so that it works on Windows (#14586)

This commit is contained in:
Jack Hsu 2023-01-24 14:39:04 -05:00 committed by GitHub
parent b01aa846fb
commit b9ff26495d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 12 deletions

View File

@ -27,6 +27,7 @@ jobs:
- e2e-angular-core - e2e-angular-core
- e2e-angular-extensions - e2e-angular-extensions
- e2e-nx-run,e2e-nx-misc,e2e-nx-plugin - e2e-nx-run,e2e-nx-misc,e2e-nx-plugin
- e2e-cra-to-nx
- e2e-make-angular-cli-faster - e2e-make-angular-cli-faster
- e2e-jest - e2e-jest
- e2e-linter - e2e-linter

View File

@ -1,4 +1,5 @@
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import { join } from 'path';
import { copySync, moveSync, readdirSync, removeSync } from 'fs-extra'; import { copySync, moveSync, readdirSync, removeSync } from 'fs-extra';
import { fileExists, readJsonFile } from 'nx/src/utils/fileutils'; import { fileExists, readJsonFile } from 'nx/src/utils/fileutils';
@ -107,7 +108,7 @@ async function reorgnizeWorkspaceStructure(options: NormalizedOptions) {
execSync(`echo "node_modules" >> .gitignore`, { stdio: [0, 1, 2] }); execSync(`echo "node_modules" >> .gitignore`, { stdio: [0, 1, 2] });
execSync(`echo "dist" >> .gitignore`, { stdio: [0, 1, 2] }); execSync(`echo "dist" >> .gitignore`, { stdio: [0, 1, 2] });
process.chdir('../'); process.chdir('..');
copyFromTempWorkspaceToRoot(); copyFromTempWorkspaceToRoot();
@ -154,10 +155,10 @@ async function reorgnizeWorkspaceStructure(options: NormalizedOptions) {
if (options.isVite) { if (options.isVite) {
const indexPath = options.isStandalone const indexPath = options.isStandalone
? 'index.html' ? 'index.html'
: `apps/${options.reactAppName}/index.html`; : join('apps', options.reactAppName, 'index.html');
const oldIndexPath = options.isStandalone const oldIndexPath = options.isStandalone
? 'public/index.html' ? join('public', 'index.html')
: `apps/${options.reactAppName}/public/index.html`; : join('apps', options.reactAppName, 'public', 'index.html');
output.note({ 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.`, title: `A new ${indexPath} has been created. Compare it to the previous ${oldIndexPath} file and make any changes needed, then delete the previous file.`,
}); });
@ -194,10 +195,10 @@ function createTempWorkspace(options: NormalizedOptions) {
output.log({ title: '🧹 Clearing unused files' }); output.log({ title: '🧹 Clearing unused files' });
copySync( copySync(
`temp-workspace/apps/${options.reactAppName}/project.json`, join('temp-workspace', 'apps', options.reactAppName, 'project.json'),
'project.json' 'project.json'
); );
removeSync(`temp-workspace/apps/${options.reactAppName}/`); removeSync(join('temp-workspace', 'apps', options.reactAppName));
removeSync('node_modules'); removeSync('node_modules');
} }
@ -226,8 +227,8 @@ function moveFilesToTempWorkspace(options: NormalizedOptions) {
moveSync( moveSync(
f, f,
options.isStandalone options.isStandalone
? `temp-workspace/${f}` ? join('temp-workspace', f)
: `temp-workspace/apps/${options.reactAppName}/${f}`, : join('temp-workspace', 'apps', options.reactAppName, f),
{ {
overwrite: true, overwrite: true,
} }
@ -239,7 +240,7 @@ function moveFilesToTempWorkspace(options: NormalizedOptions) {
} }
}); });
process.chdir('temp-workspace/'); process.chdir('temp-workspace');
} }
async function addBundler(options: NormalizedOptions) { async function addBundler(options: NormalizedOptions) {
@ -287,8 +288,8 @@ async function addBundler(options: NormalizedOptions) {
function copyFromTempWorkspaceToRoot() { function copyFromTempWorkspaceToRoot() {
output.log({ title: '🚚 Folder restructuring.' }); output.log({ title: '🚚 Folder restructuring.' });
readdirSync('./temp-workspace').forEach((f) => { readdirSync('temp-workspace').forEach((f) => {
moveSync(`temp-workspace/${f}`, `./${f}`, { overwrite: true }); moveSync(join('temp-workspace', f), f, { overwrite: true });
}); });
} }
@ -305,7 +306,7 @@ function cleanUpUnusedFilesAndAddConfigFiles(options: NormalizedOptions) {
output.log({ title: '📃 Setup e2e tests' }); output.log({ title: '📃 Setup e2e tests' });
setupE2eProject(options.reactAppName); setupE2eProject(options.reactAppName);
} else { } else {
removeSync(`apps/${options.reactAppName}-e2e`); removeSync(join('apps', `${options.reactAppName}-e2e`));
execSync(`${options.pmc.rm} @nrwl/cypress eslint-plugin-cypress`); execSync(`${options.pmc.rm} @nrwl/cypress eslint-plugin-cypress`);
} }