-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
add yargs dep to allow programmatic prompt answering #1231
Conversation
If we make this more programmatic, I'm concerned about that implying an API that we won't want to stick with. E.g., if we add a new question that someone hasn't yet added an option for in their script, is this a breaking change because running create-svelte now expects user input and won't just run automatically. (The alternative would be to make it explicitly fail if some but not all options were specified on the command line, which would also be a breaking change.) If this tool always requires human interaction, we don't need to worry about having an API because we can always assume a human is reading the interactive prompts. |
I pulled up the docs for prompts which is leveraged in |
i believe the impl is that any questions not passed a matching CLI param would still be prompted, rather than breaking. but, yea, i guess the decision is how to break unfortunately |
This is a different kind of break in that a previously non-interactive process now requires interactivity. I do not personally know of a good solution to this (right now) besides asserting SvelteKit's beta nature means that the maintainers should be allowed to change and break things and other people are responsible with keeping up. |
i think the issue lies in deciding whether |
the alternative solution for me is to snapshot the skeleton app and leverage that in my generator. which additionally causes a maintenance point for me to keep in sync with |
anymore thoughts on this or is it effectively NACK'd? |
To be extremely vague, I can imagine |
Yeah I would definitely favor a purely interactive interface (what we have now) combined with a purely programmatic interface (which would be called from Node) rather than a hybrid CLI-with-command-line-arguments interface. It makes it very clear whether the intended behavior is for it to be interactive or not. And, if we have sensible defaults for all of the options, it lets us add further options without it being a breaking change and without surprising anyone about their automated script suddenly requiring manual interaction. For the time being, I would like to reserve the right to make breaking changes at any time (until Kit reaches 1.0), but after that I think it's reasonable for the as-yet-unwritten Node API form of create-svelte to follow semver, but not for the interactive CLI version of it to. |
Coming from #639 - What about each option having a default and defaults being used to answer the questions when a single Edit: I worked around this in my adapter tests with |
Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
Changesets
pnpx changeset
and following the promptsProblem
Running
npm init svelte@next
requires user interaction to a series of prompts. If a package wishes to leverage this scaffolding command, it would need to expose these prompts upstream. In some cases, it may be preferable to pass the options to the command instead of using an interactive prompt. Example: I plan to make a yeoman generator for use within our company to create scaffold sveltekit apps. We have decided that TS,eslint,prettier are all required and not optional. I wish not to burden our consumers with having to answer the prompts in ways that match our suggestions.Solution
Leveraging yargs it is fairly trivial to parse CLI flags passed into
bin.js
and use those to values in place of the prompts. This allows programmatic completion of thenpm init svelte@next
command. In our use case, this will allow us to hard code the answers and not burden our consumers with answering them.