Package json version update
- shell-dsr/updateVersionFlow.sh
#!/usr/bin/bash
# get current pwd
pwd=$PWD
# sync mock json for mc
# . ./syncMockJson.sh
declare -A versionDic
versionDic=(
["net-pilot-ui-message-centre"]=""
# ["dynamic-form"]=""
)
# update repo version
for key in ${!versionDic[*]}
do
cd $pwd
. ./updateRepoVersion.sh $key ${versionDic[$key]}
done
# update net-pilot-ui version
cd $pwd
. ./updateUiVersion.sh
cd $pwd
shell-dsr/updateRepoVersion.sh
#!/usr/bin/bash
#################################################################################
# update Repo version auto
# use: ./updateRepoVersion.sh or ./updateRepoVersion.sh RepoName
#
# this shell script can auto update the package version base on the newest version
# and push the update to the remote repo
#
# Autho: Leon L Xiao
#################################################################################
# load utils
. ./util/utils.sh
. ./util/fileUtils.sh
. ./util/gitUtils.sh
# set branch
releaseBranch="release/hd220"
myBranch="hd220-leon"
defaultRepo="net-pilot-ui-message-centre"
# defaultRepo="dynamic-form-uitypes-blueprint"
# defaultRepo="dynamic-form"
# set directory and base info
basePath=/c/leon/hd210/net-pilot-ui/dev_modules
packageJson="package.json"
comment="update package.json version"
# build path and file
repoName=$([ -z $1 ] && echo "$defaultRepo" || echo "$1")
version=$([ -z $2 ] && echo "" || echo "$2")
repoPath="$basePath/$repoName/"
packageJsonFile="$repoPath$packageJson"
# update version
function updateVersion {
#find the line
local versionLineStr=$(grep "version" "$packageJsonFile")
# get the string after the last . to the end
local versionStr=${versionLineStr##*.}
# strip the last ',"' string
local number=${versionStr%"\","}
# get the new version
local newNumber=$[ $number + 1 ]
# build the new verion line
local newVersionLineStr=${versionLineStr%.*}.$newNumber\",
# update the version line
sed -i "/version/c\\${newVersionLineStr}" "$packageJsonFile"
# print version info
echoWarning "=== update package.json version on branch '$myBranch' ==="
}
function getVersion {
#find the line
local versionLineStr=$(grep "version" "$packageJsonFile")
# strip the front
local versionStrTemp=${versionLineStr#*\: \"}
# strip the end
local versionStr=${versionStrTemp%"\","}
# get the version
echo "$versionStr"
}
# specify the version
function updateSpecifyVersion {
local version=$1
sed -i "/version/c\ \"version\": \"$version\"," "$packageJsonFile"
}
function exportVersion {
if [ ! "${!versionDic[*]}" ]
then
echo
else
versionDic["$repoName"]=$(getVersion)
fi
}
function main {
# print repoName
echoSuccess "=== Curent Repo is $repoName ==="
# switch directory
goDirectory "$repoPath"
# get current branch
local currentBranch=$(getCurrentBranch)
# check repo is clean status before any operation
checkClean "$repoName"
if [ -n "$version" ]
then
switchBranch "$myBranch"
# update specify version
updateSpecifyVersion "$version"
else
# fetch new code
pullCode "$releaseBranch"
# merge branch
mergeBranch "$releaseBranch" "$myBranch"
# check conflict
checkConflict
# update version
updateVersion
fi
# push code
pushCode "$myBranch" "$packageJsonFile" "$comment"
# restore branch
restoreBranch "$repoPath" "$currentBranch"
# print info
echoSuccess "=== Success: update package version success! ==="
# export version to outside
exportVersion
}
main
# to do
shell-dsr/updateUiVersion.sh
#!/usr/bin/bash
# load utils
. ./util/utils.sh
. ./util/fileUtils.sh
. ./util/gitUtils.sh
# set branch
releaseBranch="release/hd220"
myBranch="hd220-leon"
# set update repo and version
# defaultUpdateRepo="net-pilot-ui-message-centre"
defaultUpdateRepo="dynamic-form-uitypes-blueprint"
defaultUpdateVersion=""
repo=$([ -z $1 ] && echo "$defaultUpdateRepo" || echo "$1")
version=$([ -z $2 ] && echo "$defaultUpdateVersion" || echo "$2")
# set directory and base info
basePath=/c/leon/hd210/net-pilot-ui/dev_modules
packageJson="package.json"
versionDicRepos="${!versionDic[*]}"
commentRepo=$([ -z "${versionDicRepos[*]}" ] && echo "$repo" || echo "${versionDicRepos[0]}")
comment="update package.json version for $commentRepo"
# build path and file
repoName="net-pilot-ui"
repoPath="$basePath/$repoName/"
packageJsonFile="$repoPath$packageJson"
# update version
function updateAutoVersion {
# get the repo name
local repo=$1
#find the line
local repoLineStr=$(grep "\"$repo\":" "$packageJsonFile")
# get the index of the '#'
local pos=$(expr index "$repoLineStr" "#")
# get the substring from the "#" to the end
local versionStr=${repoLineStr:$pos}
# strip the last ',"' string
local version=${versionStr%"\","}
# from the begin strip the long match str
local number=${version##*.}
# get the new version
local newNumber=$[ $number + 1 ]
# build the new repo line
local newRepoLineStr=${repoLineStr%.*}.$newNumber\",
# update the repo line version
sed -i "/\"$repo\":/c\\${newRepoLineStr}" "$packageJsonFile"
# print version info
echoWarning "=== update package.json version on branch '$myBranch' ==="
}
# specify the version
function updateSpecifyVersion {
# get the repo name
local repo=$1
# get the specific version
local version=$2
#find the line
local repoLineStr=$(grep "\"$repo\":" "$packageJsonFile")
# get the index of the '#'
local pos=$(expr index "$repoLineStr" "#")
# get the substring from the "#" to the end
local subStr=${repoLineStr:0:$pos}
# build new str
local newStr=$subStr$version\",
# update repo line version
sed -i "/\"$repo\":/c\\${newStr}" "$packageJsonFile"
# print version info
echoWarning "=== update package.json version on branch '$myBranch' ==="
}
# update default version
function updateDefaultVersion {
if [ ! "$repo" ]
then
echoError "Error: Please config the 'defaultUpdateRepo' !"
exit
fi
if [ ! "$version" ]
then
updateAutoVersion "$repo"
else
firstChar=${version:0:1}
version=$([ "$firstChar" = "v" ] && echo "$version" || echo "v$version")
updateSpecifyVersion "$repo" "$version"
fi
}
# update version
function updateVersion {
if [ ! "${!versionDic[*]}" ]
then
updateDefaultVersion
else
for key in ${!versionDic[*]}
do
updateSpecifyVersion "$key" "v${versionDic[$key]}"
done
fi
}
function main {
# print repoName
echoSuccess "=== Curent Repo is $repoName ==="
# directory check
goDirectory "$repoPath"
# get current branch
local currentBranch=$(getCurrentBranch)
# check repo is clean status before any operation
checkClean "$repoName"
# fetch new code
pullCode "$releaseBranch"
# merge branch
mergeBranch "$releaseBranch" "$myBranch"
# check conflict
checkConflict
# update repo version
updateVersion
# push code
pushCode "$myBranch" "$packageJsonFile" "$comment"
# restore branch
restoreBranch "$repoPath" "$currentBranch"
# print info
echoSuccess "=== Success: update package version success! ==="
}
main
# to do
- shell-dsr/updateTestVersion.sh
#!/usr/bin/bash
# load utils
. ./util/utils.sh
. ./util/fileUtils.sh
. ./util/gitUtils.sh
# set branch
releaseBranch="release/hd220"
myBranch="hd220-leon"
# set update repo and version
# defaultUpdateRepo="net-pilot-ui-message-centre"
defaultUpdateRepo="dynamic-form-uitypes-blueprint"
defaultUpdateVersion=""
repo=$([ -z $1 ] && echo "$defaultUpdateRepo" || echo "$1")
version=$([ -z $2 ] && echo "$defaultUpdateVersion" || echo "$2")
# set directory and base info
basePath=/c/leon/hd210/net-pilot-ui/dev_modules
packageJson="package.json"
versionDicRepos="${!versionDic[*]}"
commentRepo=$([ -z "${versionDicRepos[*]}" ] && echo "$repo" || echo "${versionDicRepos[0]}")
comment="update package.json version for $commentRepo"
# build path and file
repoName="net-pilot-ui"
repoPath="$basePath/$repoName/"
packageJsonFile="$repoPath$packageJson"
# update version
function updateAutoVersion {
# get the repo name
local repo=$1
#find the line
local repoLineStr=$(grep "\"$repo\":" "$packageJsonFile")
# get the index of the '#'
local pos=$(expr index "$repoLineStr" "#")
# get the substring from the "#" to the end
local versionStr=${repoLineStr:$pos}
# strip the last ',"' string
local version=${versionStr%"\","}
# from the begin strip the long match str
local number=${version##*.}
# get the new version
local newNumber=$[ $number + 1 ]
# build the new repo line
local newRepoLineStr=${repoLineStr%.*}.$newNumber\",
# update the repo line version
sed -i "/\"$repo\":/c\\${newRepoLineStr}" "$packageJsonFile"
# print version info
echoWarning "=== update package.json version on branch '$myBranch' ==="
}
# specify the version
function updateSpecifyVersion {
# get the repo name
local repo=$1
# get the specific version
local version=$2
#find the line
local repoLineStr=$(grep "\"$repo\":" "$packageJsonFile")
# get the index of the '#'
local pos=$(expr index "$repoLineStr" "#")
# get the substring from the "#" to the end
local subStr=${repoLineStr:0:$pos}
# build new str
local newStr=$subStr$version\",
# update repo line version
sed -i "/\"$repo\":/c\\${newStr}" "$packageJsonFile"
# print version info
echoWarning "=== update package.json version on branch '$myBranch' ==="
}
# update default version
function updateDefaultVersion {
if [ ! "$repo" ]
then
echoError "Error: Please config the 'defaultUpdateRepo' !"
exit
fi
if [ ! "$version" ]
then
updateAutoVersion "$repo"
else
firstChar=${version:0:1}
version=$([ "$firstChar" = "v" ] && echo "$version" || echo "v$version")
updateSpecifyVersion "$repo" "$version"
fi
}
# update version
function updateVersion {
if [ ! "${!versionDic[*]}" ]
then
updateDefaultVersion
else
for key in ${!versionDic[*]}
do
updateSpecifyVersion "$key" "v${versionDic[$key]}"
done
fi
}
function main {
# print repoName
echoSuccess "=== Curent Repo is $repoName ==="
# directory check
goDirectory "$repoPath"
# get current branch
local currentBranch=$(getCurrentBranch)
# check repo is clean status before any operation
checkClean "$repoName"
# fetch new code
pullCode "$releaseBranch"
# merge branch
mergeBranch "$releaseBranch" "$myBranch"
# check conflict
checkConflict
# update repo version
updateVersion
# push code
pushCode "$myBranch" "$packageJsonFile" "$comment"
# restore branch
restoreBranch "$repoPath" "$currentBranch"
# print info
echoSuccess "=== Success: update package version success! ==="
}
main
# to do
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
2022-02-14 shell编程 - 条件测试
2022-02-14 shell编程 - 条件语句