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

create-svelte: Skip prompts by passing args to CLI #6982

Closed

Conversation

JReinhold
Copy link

This PR makes it possible to skip some or all prompts when creating a new SvelteKit project with the create-svelte package. eg.:

npm create svelte@latest my-app \
  --name=my-new-app \
  --template=default \
  --types=checkjs \
  --prettier  \
  --no-eslint \
  --no-playwright

The problem

In Storybook we have a system for creating new projects with the different frameworks programmatically, to continuously ensure Storybook works out of the box with all the frameworks. But that's a bit hard for us to do with SvelteKit, because create-svelte is an interactive experience and thus not easy to automate.

Instead of hacking around it internally in Storybook I thought it would be better to solve it for everyone. This is also useful in tutorial/guide situations where an author wants to simplify the learning path by removing prompts that a beginner might not understand.

The solution

As per the example in the prompts docs, yargs is used to implicitly override any of the prompts if they are passed as named arguments. The implicitness is important here, because it means that if we add or change the prompts later they will automatically be overwritable by args.

I have not documented this feature in the official docs because there didn't seem to be a good place to do it. I'm open to add it somewhere though if you think it makes sense.
It is however documented in the package's readme similarly to how the programmatic API is documented.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Sep 23, 2022

🦋 Changeset detected

Latest commit: 48b1e45

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines +26 to +28
const args = await yargs(hideBin(process.argv)).coerce('types', (arg) =>
arg === 'none' ? null : arg
).argv;
Copy link
Author

@JReinhold JReinhold Sep 23, 2022

Choose a reason for hiding this comment

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

this makes it so that --types=none ends up as { types: null } internally.

Alternatively we could make the arg match one-to-one either by making the arg null instead of "none", or changing the internal null to be "none" everywhere.

@JReinhold JReinhold marked this pull request as ready for review September 23, 2022 02:53
@Conduitry
Copy link
Member

Thank you, but this isn't something we want to add. See, most recently, #6117 (comment) for more information.

@Conduitry Conduitry closed this Sep 23, 2022
@JReinhold
Copy link
Author

Oh wow sorry for wasting your time. My searching came up empty.

@dummdidumm
Copy link
Member

Note that you can still use create-svelte programmatically, see the API section of its readme. That should help you; you can create a JS script that calls create-svelte the way you want and invoke that script.

@Ni55aN
Copy link

Ni55aN commented Jun 30, 2023

@dummdidumm the problem is that then you need to install the package and you can not use it through npx

@JReinhold JReinhold deleted the create-svelte-with-args branch July 3, 2023 09:56
@JReinhold
Copy link
Author

@Ni55aN I've created a separate package for this that might suit your needs. I attempt to keep it up-to-date regularly. https://github.com/storybookjs/create-svelte-with-args

@Ni55aN
Copy link

Ni55aN commented Jul 3, 2023

@JReinhold thanks, opted for this package ✔

https://github.com/retejs/rete-kit/blob/1f713d3431a994d8782c674133ad924d258c0402/src/app/stack/svelte/index.ts#L17-L23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants