12yvan-vue-mobile.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. #set -x
  3. set -e
  4. codePath=/home/www/deploy/yvan-vue-mobile
  5. gitUrlArr=(
  6. "http://git.yvanui.com/jztd/yvan-vue-mobile.git"
  7. )
  8. branchArr=(
  9. "master"
  10. )
  11. positionArr=(
  12. "."
  13. )
  14. # 是否需要构建,-1:自动;0:不需要;1:需要
  15. needBuild=(
  16. "1"
  17. )
  18. echoPrefix="\033[36m+"
  19. echoSuffix="\033[0m"
  20. isChange="1"
  21. pullCode() {
  22. # Usage: pullCode "codePath" "gitUrl" "branch" "position"
  23. path=$1 # 代码保存路径
  24. gitUrl=$2 # git仓库地址
  25. branch=${3:-"master"} # git分支
  26. position=${4:-""} # 使用“.”clone到当前文件夹
  27. isChange="1"
  28. # 创建文件夹
  29. if [ ! -d "$path" ]; then
  30. echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix"
  31. exit
  32. fi
  33. # git clone
  34. echo -e "$echoPrefix cd $path $echoSuffix"
  35. cd $path
  36. if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then
  37. echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix"
  38. git clone $gitUrl $position
  39. isChange="2"
  40. fi
  41. # 进入文件夹,切换分支,git pull
  42. if [ "$position" != "" ]; then
  43. echo -e "$echoPrefix cd $position $echoSuffix"
  44. cd $position
  45. fi
  46. echo -e "$echoPrefix git checkout $branch $echoSuffix"
  47. git checkout $branch
  48. echo -e "$echoPrefix git checkout . $echoSuffix"
  49. git checkout .
  50. echo -e "$echoPrefix git pull $echoSuffix"
  51. if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then
  52. isChange="0"
  53. fi
  54. echo ""
  55. }
  56. buildCode() {
  57. # 构建 yvan-vue-mobile
  58. if [ "${needBuild[0]}" != "0" ]; then
  59. echo -e "$echoPrefix cd $codePath $echoSuffix"
  60. cd "$codePath"
  61. echo -e "$echoPrefix yarn $echoSuffix"
  62. yarn
  63. echo -e "$echoPrefix yarn link $echoSuffix"
  64. yarn link
  65. echo -e "$echoPrefix yarn build $echoSuffix"
  66. yarn build
  67. echo ""
  68. else
  69. echo "yvan-vue-mobile 文件未变化"
  70. fi
  71. }
  72. deployPull() {
  73. for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
  74. pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
  75. if [ "${needBuild[idx]}" == "-1" ]; then
  76. needBuild[idx]=$isChange
  77. fi
  78. done
  79. echo "###--代码更新完成--------------------------------------------------------------------------###"
  80. echo ""
  81. }
  82. cmd=$1
  83. if [ "$cmd" == "deploy" ];then
  84. deployPull
  85. buildCode
  86. elif [ "$cmd" == "pull" ];then
  87. deployPull
  88. else
  89. echo "输入操作参数: pull deploy"
  90. fi
  91. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/12yvan-vue-mobile.sh) [cmd]