refactor(create): clean up logic when prompting for unspecified arguments #7374
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pre-flight checklist
Motivation
The create-docusaurus code is super messy, and because it's highly async and imperative, it's quite hard to refactor. Therefore, this refactor probably doesn't make the code any cleaner (😅), however, it aims to make the code more correct.
We get our input from two sources: CLI args, or prompt results. What happens when part of the arguments are provided from CLI, but we are missing information and need to prompt them? (e.g.
yarn create docusaurus --git-strategy shallow
) This PR will standardize the behavior in this case. (Previously, we would still prompt for the template, and would even acceptclassic
—but in this case, we should really only accept a git repo URL)What happens when you use a local template, and the local template contains a lockfile? We should definitely use the package manager for that, instead of still using heuristics. This PR fixes that behavior.
What happens when you enter a folder name as site name, but a path already exists? Previously, the process is aborted; now, it will simply reject the input and ask you to enter another.
What happens when you cancel the current prompt? Previously it would usually give a cryptic error, now it always correctly handles this case.
Test Plan
Tested locally
Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Related issues/PRs