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

feat(create-docusaurus): ask user for preferred language when no language CLI option provided #9442

Conversation

Rafael-Martins
Copy link
Contributor

Pre-flight checklist

Motivation

Following the issue #9401, I created a prompt that just shows up when neither --javascript or --typescript is passed

Usage screenshot

image

Related issues/PRs

#9401

@facebook-github-bot
Copy link
Contributor

Hi @Rafael-Martins!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@Rafael-Martins Rafael-Martins changed the title feat(create-docusaurus): added a language prompt when no flag is info… feat(create-docusaurus): added a language prompt when no flag is provided Oct 24, 2023
@netlify
Copy link

netlify bot commented Oct 24, 2023

[V2]

Name Link
🔨 Latest commit fd41b61
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/65cdfaa2d4de890008aa1172
😎 Deploy Preview https://deploy-preview-9442--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions
Copy link

github-actions bot commented Oct 24, 2023

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 67 🟢 98 🟢 96 🟢 100 🟠 88 Report
/docs/installation 🟠 89 🟢 96 🟢 100 🟢 100 🟠 88 Report
/docs/category/getting-started 🟠 76 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog 🟠 71 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 64 🟢 96 🟢 100 🟢 100 🟠 88 Report
/blog/tags/release 🟠 71 🟢 100 🟢 100 🟠 80 🟠 88 Report
/blog/tags 🟠 76 🟢 100 🟢 100 🟢 90 🟠 88 Report

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 24, 2023
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Thanks

It's probably working but the code flow is not super clear, I'd appreciate if you refactor it a bit more.

For example getSource should probably get a clear language: "javascript" | "typescript" attribute instead of overridden cli options


Not sure how hard this would be but if there's only a JS template option and no TS variant available for that template, maybe we could avoid the extra prompt because we'll ask an extra useless question

Comment on lines 461 to 481
let language: {javascript?: boolean; typescript?: boolean} = {};
if (!cliOptions.typescript && !cliOptions.javascript) {
const {language: selectedLanguage} = (await prompts(
{
type: 'select',
name: 'language',
message: 'What language you want to use?',
choices: [
{title: 'JavaScript', value: 'javascript'},
{title: 'TypeScript', value: 'typescript'},
],
},
{
onCancel() {
logger.info`Falling back to language=${'javascript'}`;
},
},
)) as {language: keyof Languages};

language = {[selectedLanguage]: true};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you encapsulate all this under an abstraction?

Something like:

async function getLanguage(languages: LanguagesOptions): Promise<"javascript" | "typescript">

We'll likely use in other places in the future, cf swizzle CLI:
#9402

So that's worth extracting this to docusaurus-utils > cliUtils.ts immediately IMHO so that we'll be able to reuse it in other places

packages/create-docusaurus/src/index.ts Outdated Show resolved Hide resolved
packages/create-docusaurus/src/index.ts Outdated Show resolved Hide resolved
extract language logic into cliUtils
consider template to decide if the prompt will show or not
@Rafael-Martins
Copy link
Contributor Author

Hey @slorber, I addressed the comments above, let me now if we can improve it even more!

typescript?: boolean;
};

export async function getLanguage(
Copy link
Collaborator

@Josh-Cena Josh-Cena Oct 29, 2023

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.)

Copy link
Contributor Author

@Rafael-Martins Rafael-Martins Oct 30, 2023

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.

Copy link
Collaborator

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

@slorber slorber added pr: new feature This PR adds a new API or behavior. to backport This PR is planned to be backported to a stable version of Docusaurus labels Jan 12, 2024
typescript?: boolean;
};

export async function getLanguage(
Copy link
Collaborator

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

Comment on lines 23 to 25
if (noTsVersionAvailable) {
return {javascript: true};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

@slorber
Copy link
Collaborator

slorber commented Feb 15, 2024

Thanks 👍

I took the opportunity to refactor a bit the CLI because it was quite messy 🤪

Also adjusting the way we prompt for the language choice because we are going to share some code with another related PR: #9681

will be in v3.2

@slorber slorber changed the title feat(create-docusaurus): added a language prompt when no flag is provided feat(create-docusaurus): ask user for preferred language when no language CLI option provided Feb 15, 2024
@slorber slorber merged commit 628752d into facebook:main Feb 15, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior. to backport This PR is planned to be backported to a stable version of Docusaurus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants