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] provide command line params to run npm init svelte non-interactively #2348

Closed
opensas opened this issue Sep 1, 2021 · 5 comments

Comments

@opensas
Copy link

opensas commented Sep 1, 2021

Describe the problem

I want to create a new SvelteKit app programatically, but I have to interact with the script to choose options

Describe the proposed solution

svelte-create should allow to specify options using command line parameters, like this:

-y || --no-interaction
-d || --demo-app
-s || --skeleton
-t || --ts || --no-ts
-e || --eslint || --no-eslint
-p || --prettier || --no-prettier

Alternatives considered

can't think of any

Importance

would make my life easier

Additional Information

inspiration take from https://github.com/rossyman/svelte-add-jest#%EF%B8%8F-options

@Conduitry
Copy link
Member

This has come up before but I can't find the issue right now.

My comment before was that I'm worried about committing to what is effectively a public API for this, with the potential for breaking changes. If we want to add other options, would it mean that previously non-interactive invocations of the command (with certain CLI options) would suddenly become interactive? That doesn't sound desirable, but neither does bumping a major version whenever we do something that might disrupt people attempting to use this in a non-interactive way.

We have a lot more freedom to adjust and improve the CLI if we make sure that it's only humans interacting with it, who can respond to prompts that change over time. If you have a need for non-interactive and reproducible starter projects, you should probably just run the CLI once yourself and save that somewhere and use that going forward.

@opensas
Copy link
Author

opensas commented Sep 2, 2021

Thanks a lot for pointing this out, I haven't though about it as a public API, but it really is.

I think one way to prevent, or at least attenuate, the effect of adding options would be to make all optiond default to NO when running non-interactively. That is, unless specified otherwise, npm init svelte@next -y command would create a completely barebone sveltekit app, and you would have to pass parameters to add features.

That way, when eventually new feature are added, the default behaviour would be the same.
Right now, all the interactive settings have a "no" default, and you have to opt in. (except the "which app template to use" that defaults to SvelteKit demo app, but could default to a barebones SvelteKit project. Anyway, the defaults for the interactive mode could differ from the non-interactive one, of course.

I think it's a nice feature to automatize the creation of apps, building scrtips, reporting errors, writing tutorials, etc.

@babichjacob
Copy link
Member

This has come up before but I can't find the issue right now.

#1231

@opensas what you want currently exists with svelte-add's app initializer:

npm init @svelte-add/kit@latest my-new-app -- --with typescript+eslint

for example.

@opensas
Copy link
Author

opensas commented Sep 6, 2021

Thanks a lot @babichjacob , that's exactly what I was looking for.

Could you tel me where are all available options documented?

BTW, I thinks svelte adders are one of sveltekit's killer features, GREAT JOB! I hope it gets properly documented (and promoted) once the stable version is released. It's really great to have all this common tasks already solved and supported by the community.

@ppo
Copy link

ppo commented Dec 26, 2022

@opensas

Could you tel me where are all available options documented?

npm init @svelte-add/kit@latest app-name -- --demos true --with typescript+eslint+prettier+playwright
  • --demos true|false => template default|skeleton (source)
  • --with typescript+eslint+prettier+playwright+vitest
    (source: trace the use of passedFeatures here).
    Note: vitest is not handled, see here)

You can see the parameters here: svelte-add/projects/create-kit/__init.js
That are coming from here (to see the real CLI names)

The actual parameters in create-svelte: kit/packages/create-svelte/bin.js at lines 51-125 and/or 133-160.

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

No branches or pull requests

4 participants