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: use default prompts values on non-interactive mode #630

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

patzick
Copy link

@patzick patzick commented Oct 7, 2020

Hey!
We have a CLI process, which uses create-nuxt-app in non-interactive mode to prepare a new empty project. Unfortunately, providing --answers causes that all default values from prompts are omitted, so it's kinda "all or nothing", so adding any value to prompts is a breaking change for CI process.

In this PR I jumped into a case, when --answers flag is provided. Then I extract all default answers from prompts and overwrite them only by values provided in answers flag.
So users are able now to invoke non-interactive mode just by passing an empty object and project with default values will be created.

One thing I wasn't sure how to approach was interpolated default values. I added cliDefault property inside the prompt object, to provide a static default value as, at this point, I had no access to these values.

Hope you'll like that :) cheers!

Copy link
Member

@clarkdo clarkdo left a comment

Choose a reason for hiding this comment

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

Looks this will be solved in saojs v2 by using mock: true.
https://saojs.org/#testing-prompts

@egoist Is that possible to make use default prompts value and answers object a formal option rather than mock for testing purpose ?

@clarkdo
Copy link
Member

clarkdo commented Oct 7, 2020

@patzick BTW, you can import create-nuxt-app/lib/prompts into you cli script to get default prompts values and customise the answers object for now.

@patzick
Copy link
Author

patzick commented Oct 9, 2020

Hey, @clarkdo thanks for jumping in!
Hopefully, this can be removed after saojs upgrade. Still, for now, it's a recurring problem which is breaking our CLI, as every time new version of create-nuxt-app introduces new param it breaks whole app initialization on our side.

Solution with importing prompts is unfortunately not a suitable workaround for our case. We're using npx create-nuxt-app to have always the newest version, so even if I'd add this to CLI dependency and prepare default answers importing create-nuxt-app/lib/prompts then after new release we would still break the process until we'd release new CLI version with updated create-nuxt-app dependency. So the same problem we have now.
This would be okay if I could do something like this

const myAnswers // combination of provided answers and defaults from create-nuxt-app/lib/prompts
const createNuxtApp = require('create-nuxt-app')
await createNuxtApp(myAnswers)

this would ensure we're always using the same version, but it cannot be done this way.

If you have any other suggestions for solving that problem, I'd love to listen, but for now, only this PR is solving this problem and allowing to create new nuxt project via npx passing always the same answers as param.

@clarkdo
Copy link
Member

clarkdo commented Oct 9, 2020

Hi @patzick , I think you can specify npx -p create-nuxt-app and the script you pasted, then you’ll always use latest create-nuxt-app.

@clarkdo
Copy link
Member

clarkdo commented Oct 9, 2020

I ll review this shortly and also ask other team members review, if team agrees with this fix, I think we can merge it for now as a quick fix and remove when saojs released better solution.

@clarkdo clarkdo requested review from atinux and pi0 October 19, 2020 13:56
@clarkdo
Copy link
Member

clarkdo commented Oct 19, 2020

@nuxt/framework Can you please review and take a look at above comments ?

@atinux
Copy link
Member

atinux commented Oct 20, 2020

I like the idea but instead I would create another flag named --defaults instead of --answers.

npx create-nuxt-app my-app --defaults

@atinux atinux added the pending label Dec 25, 2020 — with Volta.net
Copy link
Member

atinux commented Jan 25, 2021

Shall we close it since we have no response from the author?

@patzick
Copy link
Author

patzick commented Jan 25, 2021

hey @atinux flag --answers already exist, it's not a new flag. Creating --defaults flag doesn't do much, as you not always want to have "only default" settings. Sometimes you just want to put 2-3 settings by --answers.
What the problem is really about is that with every new param in CLI this is actually a breaking change, as you need to provide all the answers, CLI is currently unable to take default values in this case and it's a simple fix for that.

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.

3 participants