#!/bin/bash
cd "$(dirname "$0")"
get_current_version() {
node -p "require('./package.json').version"
}
increment_version() {
local version=$1
local release=${2:-patch}
IFS='.' read -ra ver <<< "$version"
major=${ver[0]}
minor=${ver[1]}
patch=${ver[2]}
case $release in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
esac
echo "${major}.${minor}.${patch}"
}
current_version=$(get_current_version)
echo "Current version: $current_version"
echo "Choose version increment:"
echo "1) Patch (default)"
echo "2) Minor"
echo "3) Major"
echo "4) Use current version"
echo "5) Enter custom version"
read -p "Enter your choice (1-5): " choice
case $choice in
2)
new_version=$(increment_version "$current_version" minor)
;;
3)
new_version=$(increment_version "$current_version" major)
;;
4)
new_version=$current_version
;;
5)
read -p "Enter custom version: " new_version
;;
*)
new_version=$(increment_version "$current_version")
;;
esac
echo "Using version: $new_version"
npm run build
echo "{\"name\": \"my-app-dist\", \"version\": \"$new_version\"}" > dist/package.json
npm pack ./dist
rm dist/package.json
echo "Dist directory packed successfully with version $new_version!"
read -p "Do you want to update the main package.json with this new version? (y/n) " update_main
if [[ $update_main == "y" ]]; then
npm version $new_version --no-git-tag-version
echo "Main package.json updated to version $new_version"
fi