lizw 2 лет назад
Родитель
Сommit
f6bc91aefd
1 измененных файлов с 101 добавлено и 0 удалено
  1. 101 0
      00base/12yvan-vue-mobile.sh

+ 101 - 0
00base/12yvan-vue-mobile.sh

@@ -0,0 +1,101 @@
+#!/bin/bash
+#set -x
+set -e
+
+codePath=/home/www/deploy/yvan-vue-mobile
+gitUrlArr=(
+  "http://git.yvanui.com/jztd/yvan-vue-mobile.git"
+)
+
+branchArr=(
+  "master"
+)
+positionArr=(
+  "."
+)
+# 是否需要构建,-1:自动;0:不需要;1:需要
+needBuild=(
+"1"
+)
+
+echoPrefix="\033[36m+"
+echoSuffix="\033[0m"
+
+isChange="1"
+pullCode() {
+  # Usage: pullCode "codePath" "gitUrl" "branch" "position"
+  path=$1                   # 代码保存路径
+  gitUrl=$2                 # git仓库地址
+  branch=${3:-"master"}     # git分支
+  position=${4:-""}         # 使用“.”clone到当前文件夹
+  isChange="1"
+  # 创建文件夹
+  if [ ! -d "$path" ]; then
+    echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix"
+    exit
+  fi
+
+  # git clone
+  echo -e "$echoPrefix cd $path $echoSuffix"
+  cd $path
+  if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then
+    echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix"
+    git clone $gitUrl $position
+    isChange="2"
+  fi
+
+  # 进入文件夹,切换分支,git pull
+  if [ "$position" != "" ]; then
+    echo -e "$echoPrefix cd $position $echoSuffix"
+    cd $position
+  fi
+  echo -e "$echoPrefix git checkout $branch $echoSuffix"
+  git checkout $branch
+  echo -e "$echoPrefix git checkout . $echoSuffix"
+  git checkout .
+  echo -e "$echoPrefix git pull $echoSuffix"
+  if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then
+    isChange="0"
+  fi
+  echo ""
+}
+
+buildCode() {
+  # 构建 yvan-vue-mobile
+  if [ "${needBuild[0]}" != "0" ]; then
+    echo -e "$echoPrefix cd $codePath $echoSuffix"
+    cd "$codePath"
+    echo -e "$echoPrefix yarn $echoSuffix"
+    yarn
+    echo -e "$echoPrefix yarn link $echoSuffix"
+    yarn link
+    echo -e "$echoPrefix yarn build $echoSuffix"
+    yarn build
+    echo ""
+  else
+    echo "yvan-vue-mobile 文件未变化"
+  fi
+}
+
+deployPull() {
+  for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
+    pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
+    if [ "${needBuild[idx]}" == "-1" ]; then
+      needBuild[idx]=$isChange
+    fi
+  done
+  echo "###--代码更新完成--------------------------------------------------------------------------###"
+  echo ""
+}
+
+cmd=$1
+if [ "$cmd" == "deploy" ];then
+  deployPull
+  buildCode
+elif [ "$cmd" == "pull" ];then
+  deployPull
+else
+  echo "输入操作参数: pull deploy"
+fi
+
+# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/12yvan-vue-mobile.sh) [cmd]