Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- #
- # Author: Dmytro Borysovskyi (bbbara10@gmail.com)
- # Date : 04.09.2019
- #
- # Description: The following script installs and configures `commitlint` and `husky` into your project.
- #
- VERSION=0.0.2
- # just a helper for echo
- function print {
- echo -e "$1"
- }
- # colorize console
- GREEN='\033[0;32m'
- YELLOW='\033[1;33m'
- RED='\033[0;31m'
- NC='\033[0m'
- CWD=$0
- DIR=$1
- #
- # Validate argument (path to repo)
- #
- shift $((OPTIND - 1))
- if [ ! "${DIR}" ]
- then
- print "${RED}Please provide the repository path."
- exit 2
- fi
- if [ ! -d "${DIR}" ]
- then
- print "${RED}${DIR}: No such directory"
- exit 2
- fi
- cd $DIR || exit
- print "${GREEN}I'm going to update your project:"
- print "📂 ${PWD}${NC}\n"
- # prompt whether to proceed or not
- read -e -p "Are you sure you want to continue? [Y/n] " YN </dev/tty
- [[ $YN != "y" && $YN != "Y" && $YN != "" ]] && exit
- print "\nChecking your environment..."
- print "node version $(node -v)"
- print "npm version $(npm -v)"
- git --version
- print "\nSeems like we are ready to proceed, so let's do it. Please fasten your seatbelt 🚀🚀🚀 \n"
- npm install --save-dev --loglevel=error --unsafe-perm=true --allow-root @commitlint/cli @commitlint/config-conventional husky
- COMMITLINT_CONFIG_FILENAME="commitlint.config.js"
- COMMITLINT_CONFIG_CONTENT="module.exports = {
- extends: ['@commitlint/config-conventional'],
- rules: {
- 'type-enum': [
- 2,
- 'always',
- [
- 'build',
- 'chore',
- 'ci',
- 'docs',
- 'feat',
- 'fix',
- 'perf',
- 'refactor',
- 'revert',
- 'style',
- 'test'
- ]
- ]
- }
- }"
- printf '%s' "$COMMITLINT_CONFIG_CONTENT" > "$PWD/$COMMITLINT_CONFIG_FILENAME"
- HUSKY_CONFIG='husky: {"hooks": {"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"}}'
- node -p "JSON.stringify(
- (({ scripts: { prepush, ...scripts }, ...props }) => ({
- ...props,
- scripts,
- ...{
- husky: {
- hooks: {
- 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
- },
- },
- },
- }))(require('./package.json')),
- null,
- 2,
- )" | cat > package-copy.json && mv package-copy.json package.json
- print "${GREEN} Great! Everything is ready. Enjoy 😌"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement