update-web-projects (2654B)
1 #!/usr/bin/env bash 2 3 # Script to do all the steps for upgrade a list of web projects 4 # Why? Laziness! 5 # You MUST have Bash 4 or Up 6 7 echo "¤¤ NOT-TO-DO SOMETHING IS DOING SOMETHING ... ¤¤" && sleep 2 8 9 # The project list is a file with the path of each project per line 10 # Passes in first argument: 11 # Ex.: ./update-web-projects myprojectlistfile 12 # Paths must be relative to the $HOME directory. 13 # Ex.: my/project/relative/path 14 15 PROJECTLIST="$1" 16 17 # Projects path in a Array 18 unset -v "PROJECTS[*]" 19 declare -a PROJECTS 20 21 while read -r line ; do 22 echo "Processing ${line}" 23 24 PROJECTS+=("${line}") 25 done < "$PROJECTLIST" 26 27 # Do all these steps below for each project in projectListFile 28 for project in "${PROJECTS[@]}"; do 29 # Check if the current path point to a directory 30 [ ! -d "$HOME/$project" ] && echo "$HOME/$project is not a valid directory" && exit 1 31 32 echo "¤¤¤¤¤¤¤ $(basename "$HOME/$project") ¤¤¤¤¤¤¤" 33 34 # Go to the project directory 35 echo "Going to $(pwd)" 36 cd "$HOME/$project" || exit 37 38 # If there's a .git/ folder do a `pull origin` and a fetch 39 if [ -d "$HOME/$project/.git" ]; then 40 echo "¤ GIT artefacts found ¤" 41 git pull origin "$(git rev-parse --abbrev-ref HEAD)" && git fetch 42 fi 43 44 # If there's a composer.json do the `composer install` command 45 if [ -f "$HOME/$project/composer.json" ]; then 46 echo "¤ COMPOSER artefacts found ¤" 47 composer install 48 fi 49 50 # If there's a node_modules folder do a `rm -R node_modules` 51 if [ -d "$HOME/$project/node_modules" ]; then 52 echo "¤ NODE_MODULES artefacts found ¤" 53 rm -Rf node_modules/ 54 echo "¤ ./node_modules removed ¤" 55 fi 56 57 # If there's a yarn.lock do tne `yarn` command 58 # Or no yarn.lock but a package.json 59 if [ -f "$HOME/$project/yarn.lock" ]; then 60 echo "¤ YARN artefacts found ¤" 61 yarn 62 63 if [ -f "$HOME/$project/scripts/build.sh" ]; then 64 yarn build 65 fi 66 elif [ ! -f "$HOME/$project/yarn.lock" ] && [ -f "$HOME/$project/package.json" ]; then 67 echo "¤ NPM artefacts found ¤" 68 npm install 69 fi 70 71 # If there's a bower.json do tne `bower install` command 72 if [ -f "$HOME/$project/bower.json" ]; then 73 echo "¤ BOWER artefacts found ¤" 74 bower install 75 fi 76 77 # If there's a Gruntfile.js do tne `grunt build-dev` command 78 if [ -f "$HOME/$project/Gruntfile.js" ] && cat -u "$HOME/$project/Gruntfile.js" | grep -q 'build-dev'; then 79 echo "¤ Grunt artefacts found ¤" 80 grunt build-dev 81 fi 82 83 echo "¤¤ Done, $(basename "$HOME/$project") is updated ¤¤" 84 done