|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- ---
- id: docs_cli_init
- guide: docs_cli
- layout: guide
- ---
-
- {% include vars.html %}
-
- <p class="lead">Interactively creates or updates a package.json file.</p>
-
- ##### `yarn init` <a class="toc" id="toc-yarn-init" href="#toc-yarn-init"></a>
-
- This command walks you through an interactive session to create a
- `package.json` file. Some defaults such as the license and initial version are
- found in yarn's `init-*` config settings.
-
- Here's an example of running the command inside of a directory named `testdir`:
-
- ```sh
- $ yarn init
- ```
-
- ```sh
- question name (testdir): my-awesome-package
- question version (1.0.0):
- question description: The best package you will ever find.
- question entry point (index.js):
- question git repository: https://github.com/yarnpkg/example-yarn-package
- question author: Yarn Contributor
- question license (MIT):
- question private:
- success Saved package.json
- ✨ Done in 87.70s.
- ```
-
- This results in the following `package.json`:
-
- ```json
- {
- "name": "my-awesome-package",
- "version": "1.0.0",
- "description": "The best package you will ever find.",
- "main": "index.js",
- "repository": {
- "url": "https://github.com/yarnpkg/example-yarn-package",
- "type": "git"
- },
- "author": "Yarn Contributor",
- "license": "MIT"
- }
- ```
-
- > By default, if answer given to `question private` is passed in as empty, the `private` key will not be added to `package.json`
-
- If you already have an existing `package.json` file, then it will use the
- file's entries as defaults.
-
- The following existing `package.json`:
-
- ```json
- {
- "name": "my-existing-package",
- "version": "0.1",
- "description": "I exist therefore I am.",
- "repository": {
- "url": "https://github.com/yarnpkg/example-yarn-package",
- "type": "git"
- },
- "license": "BSD-2-Clause"
- }
- ```
-
- Results in the following defaults during the interactive session:
-
- ```sh
- $ yarn init
- ```
-
- ```sh
- question name (my-existing-package):
- question version (0.1):
- question description (I exist therefore I am.):
- question entry point (index.js):
- question git repository (https://github.com/yarnpkg/example-yarn-package):
- question author: Yarn Contributor
- question license (BSD-2-Clause):
- question private:
- success Saved package.json
- ✨ Done in 121.53s.
- ```
-
- ##### Setting defaults for `yarn init` <a class="toc" id="toc-setting-defaults-for-yarn-init" href="#toc-setting-defaults-for-yarn-init"></a>
-
- The following [config]({{url_base}}/docs/cli/config) variables can be used to
- customize the defaults for `yarn init`:
-
- - `init-author-name`
- - `init-author-email`
- - `init-author-url`
- - `init-version`
- - `init-license`
- <!--- `init-private` waiting for https://github.com/yarnpkg/yarn/pull/4377 -->
-
- ##### `yarn init --yes/-y` <a class="toc" id="toc-yarn-init-yes-y" href="#toc-yarn-init-yes-y"></a>
-
- This command skips the interactive session mentioned above and generates a
- `package.json` based on your defaults. Some defaults may be modified changing
- `init-*` config settings like mentioned above. For example, given a fresh
- install of Yarn and inside a `yarn-example` directory:
-
- ```sh
- $ yarn init --yes
- ```
-
- ```
- warning The yes flag has been set. This will automatically answer yes to all questions which may have security implications.
- success Saved package.json
- ✨ Done in 0.09s.
- ```
-
- Which produces the following `package.json`:
-
- ```json
- {
- "name": "yarn-example",
- "version": "1.0.0",
- "main": "index.js",
- "license": "MIT"
- }
- ```
-
- ##### `yarn init --private/-p` <a class="toc" id="toc-yarn-init-private-p" href="#toc-yarn-init-private-p"></a>
-
- > automatically add `private: true` to the `package.json`
-
- ```sh
- $ yarn init --private
- ```
-
- If the `private` flag is set, the `private` key will be automatically set to `true` and you still complete the rest of the init process.
-
- ```sh
- question name (testdir): my-awesome-package
- question version (1.0.0):
- question description: The best package you will ever find.
- question entry point (index.js):
- question git repository: https://github.com/yarnpkg/example-yarn-package
- question author: Yarn Contributor
- question license (MIT):
- success Saved package.json
- ✨ Done in 87.70s.
- ```
-
- ```json
- {
- "name": "my-awesome-package",
- "version": "1.0.0",
- "description": "The best package you will ever find.",
- "main": "index.js",
- "repository": {
- "url": "https://github.com/yarnpkg/example-yarn-package",
- "type": "git"
- },
- "author": "Yarn Contributor",
- "license": "MIT",
- "private": true
- }
- ```
-
- **You can use both the `yes` and the `private` flags at the same time**
-
- Like this:
-
- ```sh
- $ yarn init -yp
- ```
-
- ```
- warning The yes flag has been set. This will automatically answer yes to all questions which may have security implications.
- success Saved package.json
- ✨ Done in 0.05s.
- ```
-
- Which produces the following `package.json`:
-
- ```json
- {
- "name": "yarn-example",
- "version": "1.0.0",
- "main": "index.js",
- "license": "MIT",
- "private": true
- }
- ```
|