-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
feat(create-docusaurus): ask user for preferred language when no language CLI option provided #9442
Merged
slorber
merged 7 commits into
facebook:main
from
Rafael-Martins:feature-language-selector-create-docussaurus
Feb 15, 2024
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e5f7b9b
feat(create-docusaurus): added a language prompt when no flag is info…
Rafael-Martins 0d38d2d
fix: address pr review
Rafael-Martins bd04865
Merge branch 'main' into feature-language-selector-create-docussaurus
slorber 7a3ce2a
Better handling of create-docusaurus javascript/typescript option + r…
slorber 6bbaecd
make sure generate examples is not prompted for js/ts language question
slorber 5e97cee
fix e2e test script
slorber fd41b61
lint
slorber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import prompts from 'prompts'; | ||
import logger from '@docusaurus/logger'; | ||
|
||
export type LanguagesOptions = { | ||
javascript?: boolean; | ||
typescript?: boolean; | ||
}; | ||
|
||
export async function getLanguage( | ||
languages: LanguagesOptions, | ||
noTsVersionAvailable?: boolean, | ||
): Promise<LanguagesOptions> { | ||
if (languages.typescript || languages.javascript) { | ||
return languages; | ||
} | ||
if (noTsVersionAvailable) { | ||
return {javascript: true}; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it's a good thing to have this thing here, will try to see where to move it |
||
const {language: selectedLanguage} = (await prompts( | ||
{ | ||
type: 'select', | ||
name: 'language', | ||
message: 'Which language do you want to use?', | ||
choices: [ | ||
{title: 'JavaScript', value: 'javascript'}, | ||
{title: 'TypeScript', value: 'typescript'}, | ||
], | ||
}, | ||
{ | ||
onCancel() { | ||
logger.info`Falling back to language=${'javascript'}`; | ||
}, | ||
}, | ||
)) as {language: keyof LanguagesOptions}; | ||
|
||
return {[selectedLanguage]: true}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is only used in create-docusaurus. Please don't put it in utils. (You even had to add an entire
prompts
dependency.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, I carried out this extraction in response to @slorber's comment, which suggested that it might be reused in another part of the code. If that's the case, I'm considering passing the 'prompt' function as a parameter to eliminate the dependency. What are your thoughts on this idea? I'm also open to the possibility of reintegrating it into 'create-docusaurus' if that's a better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, considering we also want this for swizzle it's fine to add it to docusaurus utils
see also related pr: #9681