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

WIP: feat: Init for currently exising folders #1591

Conversation

kuzkokov
Copy link

@kuzkokov kuzkokov commented Apr 12, 2022

Summary:

Hey, guys. So, this is a third attempt at implementing project init in the existing folder.
Basically, I took #1446 and implement fixes from @grabbou code-review.

Then I realized that we should take underscored file names from templates into account and implemented it too.
And then I realized that we also change the template placeholder on the project name, including the renaming of folders and files, so we probably should take this into account as well.

But just now I came across this reply, and now I'm confused — do we even have to worry about any conflicts? If so, why?

So now it's more of an issue for discussion rather than PR to review because it most certainly will have some finalization or complete rewriting.

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

@kuzkokov kuzkokov changed the title Init for currently exising folders WIP: Init for currently exising folders Apr 12, 2022
@kuzkokov kuzkokov changed the title WIP: Init for currently exising folders WIP: feat: Init for currently exising folders Apr 15, 2022
@github-actions
Copy link

There hasn't been any activity on this pull request in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@github-actions github-actions bot added the stale label Nov 26, 2022
@thymikee thymikee removed the stale label Nov 28, 2022
@thymikee
Copy link
Member

@adamTrz mind having a look here? :)

@adamTrz
Copy link
Collaborator

adamTrz commented Dec 9, 2022

Hey @kuzkokov
Thanks for the PR :) Would you mind rebasing and resolving conflicts? 🙏

But just now I came across #1418 (comment), and now I'm confused — do we even have to worry about any conflicts? If so, why?

So now it's more of an issue for discussion rather than PR to review because it most certainly will have some finalization or complete rewriting.

I would say that maybe instead of throwing an error we could prompt the user with some kind of a warning that those files exists and ask them for confirmation?
Sth along those lines?
"The directory ${directoryName} contains files that could conflict, please confirm that you want to continue..."
WDYT?

# Conflicts:
#	__e2e__/init.test.ts
#	packages/cli/src/commands/init/editTemplate.ts
#	packages/cli/src/commands/init/init.ts
@kuzkokov kuzkokov requested a review from adamTrz as a code owner January 24, 2023 14:55
@kuzkokov
Copy link
Author

hey, @adamTrz
sorry for the long reply, just got my hands on it.
it sounds good, but then we can go further and remove all of the file-checking logic completely and just always ask for confirmation for an existing folder.
rephrasing your own words: "The directory ${directoryName} might contain files that could conflict, please confirm that you want to continue..."

the only thing here is that we will need to add an additional flag like --no-prompt with a default value, or maybe just a specific one for the case like --allow-existing-folder.

@kuzkokov
Copy link
Author

kuzkokov commented Jan 25, 2023

or, even a much simpler solution. we can just add the --allow-existing-folder flag, and:

  • if the flag is set, we don't care if the folder exists or not;
  • if it's not, then we throw the error as usual, with some info about the flag in the error

@adamTrz
Copy link
Collaborator

adamTrz commented Jan 25, 2023

@thymikee - pinging for second opinion here? WDYT? :D

@thymikee
Copy link
Member

thymikee commented Jan 27, 2023

As I understand the use case here: we're in some folder, run init MyApp and it turns out MyApp exists, right? Then I'd go with a prompt you mention instead of bailing and continue as usual. No need to overcomplicate it with flags that no one will use. Unless I'm missing something, then please let me know. It shouldn't normally happen on non-interactive environments like CI, and if it did, the prompt should give a good hint on why the job is stalled.

@kuzkokov
Copy link
Author

kuzkokov commented Jan 27, 2023

Well, actually, my use case seems to be exactly something that shouldn't normally happen.
I work at an outsourcing company, and we create new projects a lot, so we are trying to automate as much project-creating logic as possible.
And our current flow is our system inits a repository with some basic files like readme, etc., and then it runs the project initialization through our CI system. So what I personally need is to run npx react-native init MyApp --directory ./ inside of an already existing folder without any interactivity.

@kuzkokov
Copy link
Author

kuzkokov commented Feb 6, 2023

@thymikee so, any thoughts?

@github-actions
Copy link

github-actions bot commented May 8, 2023

There hasn't been any activity on this pull request in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@github-actions github-actions bot added the stale label May 8, 2023
@thymikee thymikee removed the stale label May 8, 2023
@github-actions
Copy link

github-actions bot commented Aug 7, 2023

There hasn't been any activity on this pull request in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@github-actions github-actions bot added the stale label Aug 7, 2023
@github-actions github-actions bot closed this Aug 15, 2023
@kuzkokov
Copy link
Author

well, it isn't stale actually, it's still might be merged

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

Successfully merging this pull request may close these issues.

4 participants