lerna-clean-changelogs-cli1.2.72

CLI application to cleanse the lerna/commitizen-generated changelogs

§ Use it

Once installed, call it one of two ways:

$ lcc
$ lernacleanchangelog

PS. That dollar sign above just means it's a terminal. Never type that dollar sign!

§ Purpose

This application performs the following cleaning steps on all encountered changelog.md's:

  1. It removes bump-only changelog entries that conventional-changelog generates. For example:

    **Note:** Version bump only for package ranges-apply
    

    These will be deleted along with their headings.

  2. It removes diff links from headings. Change the following:

    ## [2.9.1](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-apply/compare/[email protected]@2.9.1) (2018-12-27)
    

    into:

    ## 2.9.1 (2018-12-27)
    

    Diff links that changelog generator produces are not universal between GitLab, GitHub and BitBucket and sometimes there are bugs in them.

  3. Remove h1 headings and turn them into h2, with the exception of the first, main heading of the changelog.

    For exampe, change the following:

    # [2.0.0](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-apply/compare/[email protected]@1.9.1) (2018-12-27)
    

    into:

    ## 2.0.0 (2018-12-27)
    

    (notice how a second # character is added, beside link being removed)

§ The proof of the pudding is in the eating

Here's how we use it ourselves.

In short, GitLab CI calls package.json script and it cleanses the changelogs before npm package is published to npm and all builds are comitted from CI to git.

Have a look at our GitLab CI yml opens in a new tab:


#
# C O D S E N
#

thy_pipeline:
image: node:latest
stage: deploy
script:
##
## Create the SSH directory and give it the right permissions
##
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh

##
## Install ssh-agent if not already installed, it is required by Docker.
## (change apt-get to yum if you use an RPM-based image)
##
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'

##
## Write the private key
##
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa

##
## Set its permissions
##
- chmod 700 ~/.ssh/id_rsa

##
## Run ssh-agent inside the build environment
##
- eval "$(ssh-agent -s)"

##
## Add the SSH key
##
- ssh-add ~/.ssh/id_rsa

##
## Scan the keys of gitlab.com
##
- ssh-keyscan -H 'gitlab.com' >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts

##
## Start the helper to store credentials
##
# - git config --global credential.helper store

##
## Set up git remote
##
- git remote set-url origin [email protected]:codsen/codsen.git

##
## And git credentials
##
- git config --global user.email "$GITLAB_USER_EMAIL"
- git config --global user.name "$YOUR_NAME_SURNAME"
- echo "git user:"
- git config user.name

##
## Set up npm credentials
##
- npm set unsafe-perm true -g
- npm set //registry.npmjs.org/:_authToken $NPM_TOKEN -g
- npm set username $NPM_USERNAME -g
- npm set email $NPM_EMAIL -g
- echo "npm user:"
- npm whoami

##
## Fail early and loudly
##
- set -euo pipefail

##
## Checkout the repo
##
- git status
- git checkout master

##
## THE REAL ACTION STARTS
##

- echo '█████████████████████████████ 1/9 - bootstrap and test █████████████████████████████'
- git status
- npm run fresh

- echo '█████████████████████████████ 2/9 - readme █████████████████████████████'
- git status
- npm run readme:generate

- echo '█████████████████████████████ 3/9 - the first git add █████████████████████████████'
- git status
- git add packages
- git add stats
- git add README.md
- "git add package-lock.json || echo 'no package-lock.json'"
- "git diff-index --quiet HEAD || git commit -m '[skip ci] chore: automated build tasks' --no-verify"
- npm run pub:vers

- echo '█████████████████████████████ 4/9 - the last git add █████████████████████████████'
- git status
- git add packages
- git add README.md

- echo '█████████████████████████████ 5/9 - the last commit █████████████████████████████'
- git status
- "git commit -m '[skip ci] chore: automated build tasks' --no-verify"
- git status

- echo '█████████████████████████████ 6/9 - deploy █████████████████████████████'
- git status
- npm run republish

- echo '█████████████████████████████ 7/9 - push after deploy █████████████████████████████'
- git status
- git push origin master

- echo '█████████████████████████████ 8/9 - purge jsdelivr █████████████████████████████'
- "curl https://purge.jsdelivr.net/npm/detergent/dist/detergent.umd.js || echo 'detergent unreachable on jsdelivr'"
- "curl https://purge.jsdelivr.net/npm/html-crush/dist/html-crush.umd.js || echo 'html-crush unreachable on jsdelivr'"
- "curl https://purge.jsdelivr.net/npm/email-comb/dist/email-comb.umd.js || echo 'email-comb unreachable on jsdelivr'"
- "curl https://purge.jsdelivr.net/npm/string-strip-html/dist/string-strip-html.umd.js || echo 'string-strip-html unreachable on jsdelivr'"
- "curl https://purge.jsdelivr.net/npm/emlint/dist/emlint.umd.js || echo 'emlint unreachable on jsdelivr'"
- "curl https://purge.jsdelivr.net/npm/codsen-tokenizer/dist/codsen-tokenizer.umd.js || echo 'codsen-tokenizer unreachable on jsdelivr'"
- "curl https://purge.jsdelivr.net/npm/codsen-parser/dist/codsen-parser.umd.js || echo 'codsen-parser unreachable on jsdelivr'"
- "curl https://purge.jsdelivr.net/npm/json-variables/dist/json-variables.umd.js || echo 'json-variables unreachable on jsdelivr'"
- "curl -X POST $VERCEL_TRIGGER || echo 'vercel unreachable'"

- echo '█████████████████████████████ 9/9 - done ████████████████████████████'

There's a line:

- npm run pub:vers

That's how CI calls npm script. By the way, "lerna-clean-changelogs-cli" can be called at all because our monorepo root package.json opens in a new tab has it as a dev-dependency:

"devDependencies": {
  ...
  "lerna-clean-changelogs-cli": "^1.2.72",
  ...
}

In the package.json, pub:vers looks like this:

"pub:vers": "lerna version --conventional-commits --no-commit-hooks --yes && lernacleanchangelog '**'",

We call lerna version and then we call lernacleanchangelog — the call name for lerna-clean-changelogs-cli. We could also call lcc instead but it's more descriptive, considering you come back after months and wonder what is such and such command...

§ Changelog

See it in the monorepo opens in a new tab, on GitLab.

§ Licence

MIT opens in a new tab

Copyright © 2010–2020 Roy Revelt and other contributors

Related packages:

📦 lerna-clean-changelogs 1.3.62
Removes frivolous entries from commitizen generated changelogs
📦 lerna-link-dep 1.1.38
Like lerna add but does just the symlinking, works on CLI bins too
📦 update-versions 2.5.1
Like npm-check-updates but supports Lerna monorepos and enforces strict semver values