skip to Main Content

I want to run "npm init -y vue" in bash script, and make everything auto answer without any manually input.

I found this link with setting the default values in npm init but it is not enough:
https://dev.to/atapas/tips-to-customize-npm-init-to-make-it-your-own-253h

When running:

# npm init -y vue

The following prompts will ask "No/Yes", and manually hit enter to "No" by default:

Vue.js - The Progressive JavaScript Framework

✔ Project name: … vue-project
✔ Add TypeScript? … No / Yes
✔ Add JSX Support? … No / Yes
✔ Add Vue Router for Single Page Application development? … No / Yes
✔ Add Pinia for state management? … No / Yes
✔ Add Vitest for Unit Testing? … No / Yes
✔ Add an End-to-End Testing Solution? › No
✔ Add ESLint for code quality? … No / Yes
✔ Add Vue DevTools 7 extension for debugging? (experimental) … No / Yes

How to auto answer with "Yes" in all the above prompts?

2

Answers


  1. The yes command repeatedly outputs a string (by default, "y") until it’s terminated.

    yes | npm init -y vue
    

    Here is the reference : https://askubuntu.com/questions/805067/is-there-a-way-to-force-yes-to-any-prompts-when-installing-from-apt-get-from

    Login or Signup to reply.
  2. The yes command is what you are looking for. It has been designed around writing y constantly to STDOUT until terminated. But if you want to accept the default values, without providing an actual value, you can modify the default behaviour. Check the man-page for more information.

    For your use-case to simulate "" keystrokes, you can run the following command

    yes "" | npm init -y vue
    

    Further information:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search