lerna를 사용하여 MonoRepo의 CHANGELOG를 자동화 한다.
MonoRepo 구조
Root
├─ ...
├─ packages
│ └─ @docs
│ └─ note
│ └─ @webapp
│ ├─ todo
lerna로 관리할 프로젝트는 packages 하위에 위치한다.
@docs/note
, @webapp/todo
lerna를 통한 CHANGELOG를 생성하면, 변경 사항에 따라 각 하위 패키지 별로 별도의 버전을 생성한다.
conventional-commit을 위한 commitlint와 이를 git hook
에서 사용하기 위해 husky를 설치해야한다.
Git Hook
git에서 특정 이벤트 (commit, push, etc)가 발생했을 때, hook을 통해 특정 스크립트를 실행할 수 있도록 도와준다.
yarn add @commitlint/cli @commitlint/config-conventional husky -DW
yarn
module.exports = {
hooks: {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
},
};
module.exports = {
extends: ["commitlint/config-conventional"],
};
commitlint와 husky를 지정해준다.
위와 같은 설정 후 commit을 진행하고 push까지 진행 후 lerna version을 사용하면 CHANGELOG
가 생성된다.
{
"packages": ["packages/**/*"], // lerna로 관리할 패키지들의 경로
"version": "1.1.0",
"npmClient": "yarn",
"useNx": true,
// cli 옵션
"command": {
"run": {
"npmClient": "yarn"
},
// lerna version에 대한 옵션
"version": {
"allowBranch": "master",
// conventional-commit 사용
"conventionalCommits": true,
// CHANGELOG 사전 설정
"changelogPreset": {
"name": "conventional-changelog-conventionalcommits",
"types": [
{
"type": "feat",
// Type에 따라 작성되는 타이틀을 커스텀
"section": ":rocket: New Features",
"hidden": false
},
{
"type": "fix",
"section": ":bug: Bug Fix",
"hidden": false
},
{
"type": "docs",
"section": ":memo: Documentation",
"hidden": false
},
{
"type": "style",
"section": ":sparkles: Styling",
"hidden": false
},
{
"type": "refactor",
"section": ":house: Code Refactoring",
"hidden": false
},
{
"type": "build",
"section": ":hammer: Build System",
"hidden": false
},
{
"type": "chore",
"section": ":mega: Other",
// chore등의 angular Type도 hidden 속성을 false로 지정하면 CHANGELOG에 작성된다.
"hidden": false
}
]
}
}
}
}
Conventional Commits를 적용하여 commit, push 진행 후 lerna version
을 실행하면 Lerna에서 CHANGELOG 생성 및 리모트 레포지토리에 push까지 진행한다.
ex)
git add .
git commit -m "feat: @docs/note Modify"
git push
lerna version
root/CHANGELOG
@docs/note/CHANGELOG
1.2.0 버전까지 업데이트 기록된 것을 확인할 수 있다.
@webapp/todo/CHANGELOG
1.2.1 버전까지 업데이트 기록된 것을 확인할 수 있다.