yarn 파헤치기 / yarn init

in #kr6 years ago (edited)

yarn init


이 글은 Yarn 공식 홈페이지의 CLI Config Document를 한글로 옮긴 것임을 먼저 알립니다.

package.json파일을 대화방식(interactively)으로 생성 또는 업데이트 한다.

yarn init

이 명령은 대화식 세션을 통해 package.json파일을 작성한다. yarn init-* config 설정에서 라이센스 및 초기 버전과 같은 일부 기본 값 세팅이 있다.?

다음은 testdir이라는 디렉토리 내부에서 명령을 실행하는 예시다.

yarn init
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.

이렇게하면 다음과 같은 기본 형태의 package.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 질문에 대한 답이 공백(입력하지 않고 엔터)으로 주어지면, private key가 package.json 파일에 추가되지 않는다.

기존 package.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"
}

interaction session에서는 다음과 같은 기본값으로 생성된다.

yarn init
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.

yarn init에 대한 기본값 설정하기

다음의 환경변수를 활용하여 yarn init의 기본값을 커스터마이징 할 수 있다.

  • init-author-name
  • init-author-email
  • init-author-url
  • init-version
  • init-license

yarn init --yes/-y

이 명령은 위에서 언급한 interactive session을 건너 뛰고 기본값을 기반으로 package.json을 생성한다.

일부 기본값은 위에서 언급한 yarn init-* config 설정을 함으로써 변경이 가능하다.

예를 들어, Yarn을 새로 설치하고 yarn-example 디렉토리에 다음과 같이 입력한다.

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.

yarn init --private/-p

package.json안에 private: true를 자동으로 추가한다.

yarn init --private/-p`

private flag가 달려있으면, private는 자동으로 ture로 설정되고, 그 다음 yarn init의 프로세스가 지속된다.

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.

{
"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
}

물론 yesprivate flag를 동시에 쓸 수도 있다.

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.

결과 package.json은 다음과 같다.

{
"name": "yarn-example",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true
}

Reference

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.032
BTC 62521.03
ETH 3025.04
USDT 1.00
SBD 3.97