Skip to content

Instantly share code, notes, and snippets.

@jerkovicl
Created July 5, 2022 15:56
Show Gist options
  • Save jerkovicl/520f7d185e5fc9d7ad36f8aa4736a9e6 to your computer and use it in GitHub Desktop.
Save jerkovicl/520f7d185e5fc9d7ad36f8aa4736a9e6 to your computer and use it in GitHub Desktop.

LERNA COMMANDS

Versioning cheatsheet

  • MAJOR version when you make incompatible API changes,
  • MINOR version when you add functionality in a backward-compatible manner, and
  • PATCH version when you make backward-compatible bug fixes.

Commitizen scope cheatsheet

  • feat -> new feature
  • fix -> bug fix
  • docs -> documentation only changes
  • style -> changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • refactor -> code change that neither fixes a bug nor adds a feature
  • perf -> code change that improves performance
  • test -> adding missing tests or correcting existing tests
  • build -> changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
  • ci -> changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
  • chore -> other changes that don’t modify src or test files
  • revert -> reverts a previous commit

Commit messages examples

  • fix(button): jira-1234 fixed minor bug
  • chore(root) release v1.0.1

Version command

  • example npx lerna version $VERSION --exact --force-publish --no-git-tag-version --no-push --no-changelog --yes
// When run with this flag, lerna version will perform all changes on the current commit,
// instead of adding a new one. 
// This is useful during Continuous integration (CI) to reduce the number of commits in the projects history.
// In order to prevent unintended overwrites,
// this command will skip git push (i.e., it implies --no-push).
lerna version --amend
# commit message is retained, and `git push` is skipped.
lerna version -m "chore(release): publish %s"
# commit message = "chore(release): publish v1.0.0"

lerna version -m "chore(release): publish %v"
# commit message = "chore(release): publish 1.0.0"

# When versioning packages independently, no placeholders are replaced
lerna version -m "chore(release): publish"
# commit message = "chore(release): publish
#
# - [email protected]
# - [email protected]"

Publish command

  • Readme here
  • Create gitlab / github release, info here
lerna publish              # publish packages that have changed since the last release
lerna publish from-git     # explicitly publish packages tagged in the current commit
lerna publish from-package # explicitly publish packages where the latest version is not present in the registry

Lerna will never publish packages which are marked as private ("private": true in the package.json).

Add command

  • Add dependcy between libs lerna add button --scope=input

CI Script Example

# Build packages using lerna
npx lerna bootstrap
npx lerna version "${RELEASE_TAG}" --no-git-tag-version --no-push --yes
npx lerna run build

# Start local NPM registry
npx verdaccio >> "local_registry.log" &
sleep 10 # probably not needed

# Configure sample user
local username="test123"
local password="test123"
local email="[email protected]"
npx npm-cli-login -u "${username}" -p "${password}" -e "${email}" -r "${local_registry_url}"

# Execute publish in dry-run
npx lerna publish from-package \
    --registry "http://localhost:4873" \
    --no-git-tag-version --no-push --yes \
    --loglevel verbose

Generate changelogs before adding convetional commits

  • npx conventional-changelog --preset angular --release-count 0 --outfile ./CHANGELOG.md --verbose
  • npx lerna exec --concurrency 1 --stream -- 'conventional-changelog --preset angular --release-count 0 --commit-path ./ --pkg ./package.json --outfile ./CHANGELOG.md --verbose'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment