Last active
March 1, 2021 07:17
-
-
Save iandark/abe1a971f5501ca4e91b05c8e312f113 to your computer and use it in GitHub Desktop.
Read file .txt with node repositories to update package.json and lock files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Because of cd inside script exec with ./ will not work. To exec this you can use . scriptname.sh or source scriptname.sh | |
| # Do not use the exit command because it then closes your connection | |
| # To use this you might update your npm to latest | |
| readFile() { | |
| filename=$1 | |
| dirAtual="$PWD" | |
| n=1 | |
| while read repoUrl; do | |
| repoFolder="" | |
| repoFolder="${repoUrl#*/}" | |
| repoFolder="${repoFolder/.git/}" | |
| repoFolder="$dirAtual/$repoFolder" | |
| echo "Verifying if directory exists..." | |
| echo $repoFolder | |
| if [ ! -d "$repoFolder" ]; | |
| then | |
| echo "Directory not exists, cloning..." | |
| git clone "$repoUrl" | |
| fi | |
| cd "$repoFolder/" | |
| repoMsg=$(ncu --packageFile "$repoFolder/package.json") | |
| repoMsg="${repoMsg#*All dependencies match the latest package versions}" | |
| repoMsg="$(echo -e "${repoMsg}" | tr -d '[:space:]')" | |
| if [ ":)" != "$repoMsg" ] | |
| then | |
| ncu -u --packageFile "$repoFolder/package.json" | |
| npm update | |
| npm install | |
| git add package.json | |
| git add package-lock.json | |
| git commit -m "fix: Update package.json and package-lock" | |
| git push | |
| fi | |
| cd $dirAtual | |
| n=$((n+1)) | |
| done < $filename | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment