Path: blob/main/public/games/files/pacman/bump_version.sh
1036 views
#!/bin/bash12#region globalvars3option=$14abort=false5currentVersion=''6newVersion=''7currentDateTime=$(date +"%Y-%m-%d %T")8currentDate=$(date +"%Y-%m-%d")910#region functions1112function showHelp {13echo 'Parameter invalid / missing.'14echo ''15echo 'usage:'16echo ''17echo ' bump_version [patch|minor|major]'18echo ''19}2021function checkParameters {22# check if parameter provided23if [ -z $option ];24then25showHelp26abort=true27else28case $option in29patch)30# echo "patch"31;;32minor)33# echo "minor"34;;35major)36# echo "major"37;;38*)39showHelp40abort=true41return42;;43esac44echo "bump ${option} version"45fi46}4748# use package.json as the source of truth49function read_current_version {50currentVersion=$(echo "$var1" | (grep version package.json | sed 's/.*"version": "\(.*\)".*/\1/'))51echo "currentVersion=${currentVersion}"52}5354function get_new_version {55local currentMajor=$(echo "$var1" | (echo "${currentVersion}" | awk -F'.' '{print $1}'))56local currentMinor=$(echo "$var1" | (echo "${currentVersion}" | awk -F'.' '{print $2}'))57local currentPatch=$(echo "$var1" | (echo "${currentVersion}" | awk -F'.' '{print $3}'))5859echo "${currentMajor} ${currentMinor} ${currentPatch}"60case $option in61patch)62let "newPatch = $currentPatch + 1"63newVersion="${currentMajor}.${currentMinor}.${newPatch}"64echo "newVersion=${newVersion}"65;;66minor)67let "newMinor = $currentMinor + 1"68newVersion="${currentMajor}.${newMinor}.0"69echo "newVersion=${newVersion}"70;;71major)72let "newMajor = $currentMajor + 1"73newVersion="${newMajor}.0.0"74echo "newVersion=${newVersion}"75;;76esac77}7879function search_replace_in_file {80local file=$181local search=$282local replace=$38384sed -i "" "s/${search}/${replace}/g" $file85}8687function write_new_version {8889echo ""90echo "Update files to ${newVersion} (${currentDateTime}):"9192echo " package.json"93local line="\"version\": \".*\""94local rep="\"version\": \"${newVersion}\""95sed -i "" "s/${line}/${rep}/g" package.json9697# in package-lock.json we only want to replace the very first occurence98echo " package-lock.json"99sed -e "/${line}/{s//${rep}/;:a" -e '$!N;$!ba' -e '}' package-lock.json > tmp && mv tmp package-lock.json100101102# TODO: update last_update103echo " web-app-manifest.json"104sed -i "" "s/${line}/${rep}/g" web-app-manifest.json105106# TODO: update last_update107echo " manifest.json"108sed -i "" "s/${line}/${rep}/g" manifest.json109110# TODO: update last_update111echo " pacman-canvas.webapp"112sed -i "" "s/${line}/${rep}/g" pacman-canvas.webapp113114echo " cache.manifest"115local line="# Pacman .*"116local rep="# Pacman ${newVersion} ${currentDateTime}"117sed -i "" "s/${line}/${rep}/g" cache.manifest118119echo " index.htm"120local line="<span class=\"app-version\">.*<\/span>"121local rep="<span class=\"app-version\">${newVersion} (${currentDate})<\/span>"122sed -i "" "s/${line}/${rep}/g" index.htm123124echo ""125echo "All files up to date. New Version ${newVersion} (${currentDateTime})."126echo "Don't forget to update README.md and to set the git tag."127}128129function run {130# local option="${1}"131132echo "run ${option}"133134checkParameters135136if [[ ${abort} == true ]];137then138return139fi140141echo "bump version $option"142143read_current_version144get_new_version145146# TODO: user confirmation147148write_new_version149}150151#endregion152153#region main154155run156157#endregion158159