11#! /bin/bash
22set -e
33
4+ # Usage: ./release.sh [major|minor|patch]
5+ release_type=${1:- patch}
6+ if [[ " $release_type " != " major" && " $release_type " != " minor" && " $release_type " != " patch" ]]; then
7+ echo " Usage: $0 [major|minor|patch]"
8+ exit 1
9+ fi
10+
411# Ensure jq is installed
512if ! command -v jq & > /dev/null; then
613 echo " Error: jq is required but not installed."
@@ -21,16 +28,35 @@ git tag "v$current_version"
2128# Split the current version into major, minor, and patch components
2229IFS=' .' read -r major minor patch <<< " $current_version"
2330
24- # Increment the patch version
25- new_patch=$(( patch + 1 ))
26- new_version=" ${major} .${minor} .${new_patch} "
31+ # Increment the version based on the release type
32+ case " $release_type " in
33+ major)
34+ major=$(( major + 1 ))
35+ minor=0
36+ patch=0
37+ ;;
38+ minor)
39+ minor=$(( minor + 1 ))
40+ patch=0
41+ ;;
42+ patch)
43+ patch=$(( patch + 1 ))
44+ ;;
45+ esac
46+
47+ new_version=" ${major} .${minor} .${patch} "
2748echo " New version: $new_version "
2849
2950# Update package.json with the new version
3051jq --arg new_version " $new_version " ' .version = $new_version' package.json > tmp.$$ .json && mv tmp.$$ .json package.json
3152
53+ # Update package-lock.json with the new version if it exists
54+ if [ -f package-lock.json ]; then
55+ jq --arg new_version " $new_version " ' .version = $new_version' package-lock.json > tmp.$$ .lock && mv tmp.$$ .lock package-lock.json
56+ fi
57+
3258# Stage and commit the version bump
33- git add package.json
59+ git add package.json package-lock.json
3460git commit -m " Bump version to $new_version "
3561
3662# Push the commit and the tag to the remote repository (assuming main branch)
0 commit comments