Why Lerna in Advertorial
How do you share front-end components across various projects within an organisation?

One Option:
A repo for each components
An example
// inside the super-button NPM package + repo
import SuperText from 'super-text'
const SuperButton = props => (
<button>
<SuperText value="Click me!" />
</button>
)
export default SuperButton
// inside the super-text NPM package + repo
const SuperText = props => (
<span>
{props.value}
</span>
)
export default SuperText
Setup Process
- Testing
- Linting
- Build process
- Publish process
- Continuous Integration
- ......

Add new Feature Process
- Make changes to each repo
-
Update tests
-
Update the versions
- Get them code reviewed
- Publish the packages
- Update Super Application to use them
- Send out PR
- Wait for PR approval
- .......
But wait
Requirements change slightly!!!
Lerna to the rescue
What is Lerna?
Lerna is a tool that optimizes the workflow around managing multi-package repositories with git and npm."
What is monorepos?
monorepos also called multi-package repos
one repository with all packages
babel-6.2.0/
packages/
babel-core/
babel-cli/
babel-plugin-syntax-flow/
babel-.../
What does a Lerna repo look like
Why monorepos?
Pros
- Single release process
- Cross-package changes are easier
- Single place to report issues
- Development setup
- Cross-package tests are easier
- Reduce space for duplicated dependencies
Cons
- Codebase looks more intimidating
- Repo is bigger in size
Who use Lerna?
- babel
- jest
- create-react-app
- react-router
- storybook
- ...
- RUI Advdertorial
What can Lerna do
- Lerna Run
One Useful Command
- Lerna Bootstrap
- Lerna Publish
Two Primary Commands
Lerna Bootstrap
- Installs all external dependencies
- Links all of your sub-packages together
Lerna Publish
- Publishes all packages to npm
- Does some other magic to update git tags
All the magic about Publish
- Find packages need to be published.
- Increment `version` in lerna.json
- Update the package.json of all updated packages to their new versions.
- Update all dependencies of the updated packages with the new versions.
- Create a new git commit and tag for the new version.
- Publish updated packages to npm.
Lerna Changelog

<type>[optional scope]: <description>
type could be: feat, bug, BREAKING CHANGE
git commit -m "feat: Add interface for plugin in rui-advertorial"
How it works
- Fixed/Locked mode (default)
- Independent mode
Lerna in Advertorial
advertorial/
packages/
tracker/
package.json
advertorial/
package.json
targeter/
package.json
What are the benefits?
- Single setup for all packages
- Single release process
- One pipeline for all packages
- Cross-package features are easier to manage
- Reduce the time and space requirements

When to use Lerna?
- Project which is not too big
- Project contains multiple plugins or modules
- Trust among teams
Thanks
Lerna
By jingliu
Lerna
- 381