Last active
July 22, 2024 15:14
-
-
Save johnnyshankman/758eb0aaa073bce596785d44356bb446 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Input parameters | |
folders=$1 # Comma-separated list of folders | |
package_name=$2 # npm package name | |
version_string=$3 # Version string | |
if [ -z "$folders" ] || [ -z "$package_name" ] || [ -z "$version_string" ]; then | |
echo "Usage: $0 <folders> <package_name> <version_string>" | |
exit 1 | |
fi | |
# Sanitize the package name for branch name use | |
sanitized_package_name=$(echo "$package_name" | sed 's/[@\/]/-/g') | |
# Sanitize the version string for branch name use by removing '^' and '~' | |
sanitized_version_string=$(echo "$version_string" | sed 's/[\^~]//g') | |
# Convert comma-separated list into an array | |
IFS=',' read -r -a folder_array <<< "$folders" | |
for folder in "${folder_array[@]}"; do | |
if [ -d "$folder" ]; then | |
cd "$folder" || { echo "Failed to change directory to $folder"; exit 1; } | |
if [ -f "package.json" ]; then | |
echo "Processing $folder/package.json" | |
# Checkout main branch | |
git checkout main | |
# Pull latest changes | |
git pull | |
# Update the package version in package.json | |
jq ".dependencies[\"$package_name\"]=\"$version_string\"" package.json > tmp.$$.json && mv tmp.$$.json package.json | |
# Install updated packages | |
npm install | |
# Create a new git branch | |
branch_name="update-${sanitized_package_name}-${sanitized_version_string}" | |
git checkout -b "$branch_name" | |
# Add changes to git | |
git add package.json package-lock.json | |
# Commit changes | |
git commit -m "Update $package_name to $version_string" | |
# Push branch to remote | |
git push origin HEAD | |
# Switch back to main branch | |
git checkout main | |
else | |
echo "package.json not found in $folder" | |
fi | |
cd - > /dev/null || { echo "Failed to change directory back"; exit 1; } | |
else | |
echo "Folder $folder does not exist" | |
fi | |
done |
Manifold Example
./update-npm-pkgs.sh \
"studio-app-claim-v2,studio-app-burn-redeem-v2,studio-app-physicals-v2,studio-app-gachapon,studio-app-marketplace-v2,studio-app-curate-page,studio-app-thanks-page,studio-app-frame-edition,studio-app-batch-multi,studio-app-batch-edition,studio-app-edition,studio-app-one-of-one,studio-app-giveaways" \
"@manifoldxyz/studio-app-sdk-react" \
"^5.1.10"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements
Make sure you have brew installed
jq
Make sure the script has the right perms
Usage
Ensure all repos you want to work with are clean and do not contain unstaged changes. Then....
What does it do?
Does this in order for each repo in the list:
main
git pull
latest changes inupdate--pkgname-X.Y.Z
package.json
package.json
andpackage-lock.json
main
againCaveats
It will bonk if you have unstaged changes in any of the repos because it won't be able to
git checkout main
and thengit pull
.