Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init for current/existing folders #1446

Closed
wants to merge 2 commits into from
Closed

Init for current/existing folders #1446

wants to merge 2 commits into from

Conversation

andrewtsar0w
Copy link

@andrewtsar0w andrewtsar0w commented Jul 14, 2021

Summary:

This PR brings the ability to create new apps in existing and/or current folder.

Issue: #1418.

TBD:

  • Linter
  • Fix existing tests
  • Cover new cases with tests

Test Plan:

Current empty folder:

  1. Create an empty folder mkdir TestApp1.
  2. Go to a newly created folder cd TestApp1.
  3. Init a new app react-native init TestApp1 --directory .
  4. As a result a new app gets created in TestApp1 folder.

Non-current empty existing folder:

  1. Create an empty folder mkdir TestApp2.
  2. Init a new app react-native init TestApp2 --directory TestApp2
  3. As a result a new app gets created in TestApp2 folder.

Current folder with conflicting files:

  1. Create an empty folder mkdir TestApp3.
  2. Go to a newly created folder cd TestApp3.
  3. Create some conflicting files mkdir android && touch android/gradlew && touch App.js && touch package.json.
  4. Init a new app react-native init TestApp3 --directory .
  5. As a result get a crash with corresponding error saying that some files are conflicting.

Screenshot 2021-07-15 at 00 31 28

@thymikee
Copy link
Member

Cool, thanks! Linter and unit tests are not happy

@@ -9372,6 +9377,15 @@ plist@^3.0.1:
xmlbuilder "^9.0.7"
xmldom "0.1.x"

plist@^3.0.2:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why the deps changed 🤔

@grabbou
Copy link
Member

grabbou commented Aug 4, 2021

How is this different from #1421? Any chance we can join this into a single PR?

Copy link
Member

@grabbou grabbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I decided to close the other PR due to inactivity and also, after taking another pass at this PR, I like this solution.

I left a review to help you move forward with this PR. Please let me know if you're still interested in working on this PR.


const readdir = promisify(fs.readdir);

export async function getDirectoryFilesRecursive(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about executing a simple find ${dir} -print command? For example, running find ios -print on my React Native project gave me the following:

ios
ios/react-native-hello-world-generated.mm
ios/HelloWorld.h
ios/HelloWorld.mm
ios/react-native-hello-world.h
ios/HelloWorld.xcodeproj
ios/HelloWorld.xcodeproj/project.pbxproj

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to simplify this function as it looks a bit complex (while it certainly gets the job done).

}
if (conflictingFiles.length > 0) {
throw new ConflictingFilesError(projectDirectory, conflictingFiles);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a conceptual suggestion.

How about we move all this code into a function checkDirectoryForConflictingFiles (name is just a recommendation) and call it from an else block of this conditional: https://github.com/react-native-community/cli/pull/1446/files#diff-5b5591728aa944b7a0f0a9a01b281bdf3e9f51bded73219124ace0edad8afd7eR48

Basically, I want to minimise the number of files affected. If directory exists - validate for conflicts - otherwise - create it. Everything stays in a single conditional.

@grabbou
Copy link
Member

grabbou commented Feb 15, 2022

I am going to close this PR due to inactivity and the PR review that remains unanswered for some time. I would be happy to accept a new PR with the requests addressed.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants