Skip to content

Instantly share code, notes, and snippets.

@iandark
Last active February 28, 2021 21:13
Show Gist options
  • Select an option

  • Save iandark/5245faab14608a2e167b6f6b28965e42 to your computer and use it in GitHub Desktop.

Select an option

Save iandark/5245faab14608a2e167b6f6b28965e42 to your computer and use it in GitHub Desktop.
Clone a repo and update your package.json and lock files in origin
#!/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
updatePackage() {
repoUrl="$1"
repoUrlToRemove="/$2/"
git clone "$repoUrl"
if [ "" = "$repoUrlToRemove" ]
then
repoFolder="${repoUrl/$repoUrlToRemove/}"
repoFolder="${repoFolder//\//}"
repoFolder="${repoFolder/.git/}"
else
repoFolder="${repoUrl#*/}"
repoFolder="${repoFolder/.git/}"
fi
dirAtual="$PWD"
cd "$dirAtual/$repoFolder/"
ncu -u
yarn install
npm install
git add .
git commit -m "fix: Update package.json and lock files"
git push
git log --name-status HEAD^..HEAD
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment