Skip to content

Commit

Permalink
feat: allow step-by-step in bump-version method
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHardouin committed Nov 6, 2022
1 parent 19bf856 commit b981137
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions npm-bump
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ declare -a old_version_packages
declare -a new_version_packages
declare -a no_updated_packages
markdown=0
step_by_step=0

trap ctrl_c SIGINT

Expand Down Expand Up @@ -106,6 +107,27 @@ function get_newest_versions() {
read -r -d '\n' -a newest_versions < <( printf '%s\n' "${desc_newest_versions[@]}" | sort -V )
}

function install_version() {
echo "Try to bump $1 from $2 to $3"

if [ -z ${no_test} ]; then
npm install "$1"@"$3" && npm test
else
npm install "$1"@"$3"
fi

# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
commit_bump "$1" "$2" "$3"
add_updated_package_informations "$1" "$2" "$3"
status=0
else
no_updated_packages+=("$1")
undo_changes
status=1
fi
}

function bump_version() {
if [ -z ${exclude+x} ]; then
outdated_packages=$(npm outdated | tail -n +2)
Expand All @@ -115,24 +137,18 @@ function bump_version() {

if [ -n "$outdated_packages" ]; then
# shellcheck disable=SC2034
while read -r package actual_version coll3 latest_version col4; do
echo "Try to bump ${package} from ${actual_version} to ${latest_version}"

if [ -z ${no_test} ]; then
npm install "$package"@"$latest_version" && npm test
else
npm install "$package"@"$latest_version"
fi

# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
commit_bump "$package" "$actual_version" "$latest_version"
add_updated_package_informations "$package" "$actual_version" "$latest_version"
while read -r package actual_version col3 latest_version col4; do
if [ ${step_by_step} -eq 0 ]; then
install_version "${package}" "${actual_version}" "${latest_version}"
else
no_updated_packages+=("${package}")
undo_changes
get_newest_versions "${package}" "${actual_version}"
for version in "${newest_versions[@]}"; do
install_version "${package}" "${actual_version}" "${version}"
if [ ${status} -eq 1 ]; then
break
fi
done
fi

done <<<"$outdated_packages"
fi
}
Expand Down

0 comments on commit b981137

Please sign in to comment.