同步文件

  • syncMockJson.sh
#!/usr/bin/bash

# load utils 
. ./util/utils.sh
. ./util/fileUtils.sh
. ./util/gitUtils.sh

# config directory, file path and branch
########################################
dsrTemplatePath=/TemplatesPath/
mcPath=/RepoPath/

dsrFile=/TemplatesPath/template.json
mcFile=/RepoPath/repoFile.js

dsrReleaseBranch="release/hd231"
mcReleaseBranch="release/hd231"
mcBranch="hd231-leon"

# check the directory and file path set correctly
########################################
if [ -d $dsrTemplatePath ] && [ -d $mcPath ] && [ -f $dsrFile ] && [ -f $mcFile ]
then 
  echoSuccess "=== Success: Directory and file path set correctly! ==="
else
  echoError "=== Error: Please check the directory and file path config and make it set correctly! ==="
  exit
fi

# In DSRTemplate repo switch to the right branch and pull the new code
#####################################################
goDirectory "$dsrTemplatePath"
# print repoName
echoSuccess "=== Curent Repo is DSR-templates==="

dsrCurrentBranch=$(getCurrentBranch)

# check repo is clean status before any operation
checkClean "DSR-templates" 
# checkout branch and update code
pullCode "$dsrReleaseBranch"

# In mc repo switch to the right branch and sync json content
############################################################
goDirectory "$mcPath"
echoSuccess "=== Curent Repo is mc ==="
mcCurrentBranch=$(getCurrentBranch)

# check release branch
isBranchExist "$mcReleaseBranch"
if [ $? -eq 0 ]
then
  # check repo is clean status before any operation
  checkClean "mc" 
  pullCode "$mcReleaseBranch"
else 
  restoreBranch "$dsrTemplatePath" "$dsrCurrentBranch"
  echoError "=== Error: Please check the mc release branch correctly! ==="
  exit
fi

# check and merge branch
isBranchExist "$mcBranch"
if [ $? -eq 0 ]
then
  mergeBranch "$mcReleaseBranch" "$mcBranch"
  checkConflict
else 
  restoreBranch "$dsrTemplatePath" "$dsrCurrentBranch"
  echoError "=== Error: Please check the mc branch correctly! ==="
  exit
fi


# get json and sync json 
# jsonContent=$(cat $dsrFile)
# echo "export const drawdownFormDefination = $jsonContent" > $mcFile
# unix2dos "$mcFile"


# delete 2 to last line
# read dsrFile and append after the first line
sed -i "
2,\$d  
1r $dsrFile
" "$mcFile"

# delete the second line 
sed -i '2d' "$mcFile"

# convert the file format from unix to dos 
unix2dos "$mcFile"

echoSuccess "=== Sync json Success ==="

# check if have new code
diffContent=$(git diff -- $mcFile)
if [ -z $diffContent ]
then
  echoWarning "=== Warning: no code need to commit! ==="
  restoreBranch "$mcPath" "$mcCurrentBranch"
  restoreBranch "$dsrTemplatePath" "$dsrCurrentBranch"
else
  # push code
  pushCode "$mcBranch" "$mcFile" "sync mock json"
  # restore branch
  restoreBranch "$mcPath" "$mcCurrentBranch"
  restoreBranch "$dsrTemplatePath" "$dsrCurrentBranch"
  # print success info
  echoSuccess "=== Success: sync mock json success ==="
fi
posted @   箫笛  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示