Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. #
  3. # Author: Dmytro Borysovskyi (bbbara10@gmail.com)
  4. # Date : 04.09.2019
  5. #
  6. # Description: The following script installs and configures `commitlint` and `husky` into your project.
  7. #
  8. VERSION=0.0.2
  9.  
  10. # just a helper for echo
  11. function print {
  12. echo -e "$1"
  13. }
  14.  
  15. # colorize console
  16. GREEN='\033[0;32m'
  17. YELLOW='\033[1;33m'
  18. RED='\033[0;31m'
  19. NC='\033[0m'
  20.  
  21. CWD=$0
  22. DIR=$1
  23.  
  24. #
  25. # Validate argument (path to repo)
  26. #
  27. shift $((OPTIND - 1))
  28.  
  29. if [ ! "${DIR}" ]
  30. then
  31. print "${RED}Please provide the repository path."
  32. exit 2
  33. fi
  34.  
  35. if [ ! -d "${DIR}" ]
  36. then
  37. print "${RED}${DIR}: No such directory"
  38. exit 2
  39. fi
  40.  
  41. cd $DIR || exit
  42.  
  43. print "${GREEN}I'm going to update your project:"
  44. print "📂 ${PWD}${NC}\n"
  45.  
  46. # prompt whether to proceed or not
  47. read -e -p "Are you sure you want to continue? [Y/n] " YN </dev/tty
  48. [[ $YN != "y" && $YN != "Y" && $YN != "" ]] && exit
  49.  
  50.  
  51. print "\nChecking your environment..."
  52. print "node version $(node -v)"
  53. print "npm version $(npm -v)"
  54. git --version
  55.  
  56. print "\nSeems like we are ready to proceed, so let's do it. Please fasten your seatbelt 🚀🚀🚀 \n"
  57.  
  58. npm install --save-dev --loglevel=error --unsafe-perm=true --allow-root @commitlint/cli @commitlint/config-conventional husky
  59.  
  60. COMMITLINT_CONFIG_FILENAME="commitlint.config.js"
  61. COMMITLINT_CONFIG_CONTENT="module.exports = {
  62. extends: ['@commitlint/config-conventional'],
  63. rules: {
  64. 'type-enum': [
  65. 2,
  66. 'always',
  67. [
  68. 'build',
  69. 'chore',
  70. 'ci',
  71. 'docs',
  72. 'feat',
  73. 'fix',
  74. 'perf',
  75. 'refactor',
  76. 'revert',
  77. 'style',
  78. 'test'
  79. ]
  80. ]
  81. }
  82. }"
  83.  
  84. printf '%s' "$COMMITLINT_CONFIG_CONTENT" > "$PWD/$COMMITLINT_CONFIG_FILENAME"
  85.  
  86. HUSKY_CONFIG='husky: {"hooks": {"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"}}'
  87.  
  88. node -p "JSON.stringify(
  89. (({ scripts: { prepush, ...scripts }, ...props }) => ({
  90. ...props,
  91. scripts,
  92. ...{
  93. husky: {
  94. hooks: {
  95. 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
  96. },
  97. },
  98. },
  99. }))(require('./package.json')),
  100. null,
  101. 2,
  102. )" | cat > package-copy.json && mv package-copy.json package.json
  103.  
  104. print "${GREEN} Great! Everything is ready. Enjoy 😌"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement