Coder Social home page Coder Social logo

monorepo-practice's Introduction

youtubeにて勉強
このプロジェクトは下記URLのYouTuber Ben Awad さんの内容に沿って学習した内容です。

  1. Yarn Workspaces Tutorial
  2. How to Use Lerna

npx lerna init

lernaに必要なファイルやディレクトリが作成される

lerna run [script]

どの階層でいても全てのpackage.jsonの指定したscripteを実行してくれる

例、このプロジェクトの場合

% yarn test

yarn run v1.22.4
$ lerna run test
lerna notice cli v3.22.1
lerna info Executing command in 2 packages: "yarn run test"
lerna info run Ran npm script 'test' in '@walnut/common' in 0.4s:
$ echo testing common with version: $npm_package_version
testing common with version: 1.0.0
lerna info run Ran npm script 'test' in '@walnut/server' in 0.3s:
$ echo testing server with version: $npm_package_version
testing server with version: 1.0.0
lerna success run Ran npm script 'test' in 2 packages in 0.7s:
lerna success - @walnut/common
lerna success - @walnut/server
✨  Done in 2.15s.
---------------------------

--scopeでpackage.jsonを指定すると全体てはなく、個別にscriptを実行出来る

% yarn test:common  
yarn run v1.22.4
$ lerna run test --scope=@walnut/common
lerna notice cli v3.22.1
lerna notice filter including "@walnut/common"
lerna info filter [ '@walnut/common' ]
lerna info Executing command in 1 package: "yarn run test"
lerna info run Ran npm script 'test' in '@walnut/common' in 0.4s:
$ echo testing common with version: $npm_package_version
testing common with version: 1.0.0
lerna success run Ran npm script 'test' in 1 package in 0.4s:
lerna success - @walnut/common
✨  Done in 1.61s.

--scope={}で複数指定することも可能

% yarn tests

yarn run v1.22.4
$ lerna run test --scope={@walnut/common,@walnut/server}
lerna notice cli v3.22.1
lerna notice filter including ["@walnut/common","@walnut/server"]
lerna info filter [ '@walnut/common', '@walnut/server' ]
lerna info Executing command in 2 packages: "yarn run test"
lerna info run Ran npm script 'test' in '@walnut/common' in 0.6s:
$ echo testing common with version: $npm_package_version
testing common with version: 1.0.0
lerna info run Ran npm script 'test' in '@walnut/server' in 0.3s:
$ echo testing server with version: $npm_package_version
testing server with version: 1.0.0
lerna success run Ran npm script 'test' in 2 packages in 0.9s:
lerna success - @walnut/common
lerna success - @walnut/server
✨  Done in 2.47s.

git commit をした後にlerna version --conventional-commits --yesを実行するとVersionをアップしてリリースログを残すことが可能、自動でpushまでしてくれる

$ lerna version --conventional-commits --yes
lerna notice cli v3.22.1
lerna info current version 0.0.0
lerna info Assuming all packages changed
lerna info getChangelogConfig Successfully resolved preset "conventional-changelog-angular"

Changes:
 - @walnut/common: 1.0.0 => 1.0.1
 - @walnut/server: 1.0.0 => 1.0.1

lerna info auto-confirmed 
lerna info execute Skipping releases
lerna info git Pushing tags...
lerna success version finished
✨  Done in 12.36s.

lerca diff

コミット後に変更されたパッケージのログが見れる

yarn diff

yarn run v1.22.4
$ lerna diff
lerna notice cli v3.22.1
diff --git a/packages/common/index.js b/packages/common/index.js
index a120cf9..e81a19b 100644
--- a/packages/common/index.js
+++ b/packages/common/index.js
@@ -1,3 +1,4 @@
 module.exports = () => {
   console.log("hello from common 13");
+  console.log("hello from common 14");
 };
\ No newline at end of file
✨  Done in 1.59s.

monorepo-practice's People

Contributors

yuutakkuma avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.