Bladeren bron

更改编译模式

ZaiZai 1 jaar geleden
bovenliggende
commit
ceaa9a3b43
5 gewijzigde bestanden met toevoegingen van 136 en 16 verwijderingen
  1. 18 0
      build/main.sh
  2. 102 0
      build/online.sh
  3. 9 11
      build/test.sh
  4. 6 4
      package.json
  5. 1 1
      public/version.json

+ 18 - 0
build/main.sh

@@ -0,0 +1,18 @@
+#!/bin/bash
+
+# 打包前的准备
+node ./scripts/build.js
+
+# 执行打包命令
+vite build
+
+# 恢复配置文件
+node ./scripts/restore.js
+
+# 排除打包文件
+if [ $1 == "wgt" ]; then
+    node ./scripts/public.js
+fi
+
+# 执行打包为zip
+node ./scripts/zip.js

+ 102 - 0
build/online.sh

@@ -0,0 +1,102 @@
+#!/bin/bash
+
+#本地压缩文件名
+file_name="measure.zip"
+
+#服器上的目录地址
+file_path="measure.hczcxx.cn"
+
+#服务器演示地址
+demo_url="http://measure.hczcxx.cn/"
+
+#服务器登录密码
+passwd="%CX0&qPRk2BitWPH^tCa5jxZKPYuST"
+
+# 打包前的准备
+node ./scripts/build.js
+
+# 执行打包命令
+vite build
+
+# 恢复配置文件
+node ./scripts/restore.js
+
+# 排除打包文件
+if [ $1 == "wgt" ]; then
+    node ./scripts/public.js
+fi
+
+# 执行打包为zip
+node ./scripts/zip.js
+
+ # 上传到测试服务器
+function uploadServer() {
+    expect -c "
+        spawn scp ./zip/${file_name} root@47.110.251.215:/www/wwwroot/${file_path}
+        expect {
+            \"yes/no\" {send \"yes\r\";exp_continue;}
+            \"*password\" {set timeout 500;send \"${passwd}\r\";}
+        }
+    expect eof"
+
+#服务器上的相关操作
+/usr/bin/expect << EOF
+    set time 30
+    spawn ssh root@47.110.251.215
+    expect {
+        "*yes/no" { send "yes\r"; exp_continue }
+        "*password:" { send "${passwd}\r" }
+    }
+
+    # 进入当前项目的目录
+    expect "*]#"
+    send "cd /www/wwwroot/${file_path}\r"
+
+    # 删除 static 目录
+    expect "*]#"
+    send "rm -rf static\r"
+
+    # 解压上传的文件压缩包
+    expect "*]#"
+    send "unzip -o ${file_name}\r"
+
+    # 退出
+    send "exit\r"
+    expect eof
+EOF
+    echo "编译打包后自动部署到服务器上完成"
+    echo "服务器地址:${demo_url}"
+}
+
+# 删除 plugins 等目录
+function delPublic() {
+    echo "准备移除 plugins 等目录"
+#服务器上的相关操作
+/usr/bin/expect << EOF
+    set time 30
+    spawn ssh root@47.110.251.215
+    expect {
+        "*yes/no" { send "yes\r"; exp_continue }
+        "*password:" { send "${passwd}\r" }
+    }
+
+    # 进入当前项目的目录
+    expect "*]#"
+    send "cd /www/wwwroot/${file_path}\r"
+
+    # 删除 plugins 目录
+    expect "*]#"
+    send "rm -rf plugins\r"
+
+    # 退出
+    send "exit\r"
+    expect eof
+EOF
+    echo "plugins 等目录移除完成"
+}
+
+# 上传到测试服务器
+if [ $1 == "all" ]; then
+    delPublic
+fi
+uploadServer

+ 9 - 11
scripts/build.sh → build/test.sh

@@ -14,21 +14,23 @@ passwd="admin123@"
 
 # 打包前的准备
 node ./scripts/build.js
+
 # 执行打包命令
 vite build
+
 # 恢复配置文件
 node ./scripts/restore.js
+
 # 排除打包文件
 if [ $1 == "wgt" ]; then
     node ./scripts/public.js
 fi
+
 # 执行打包为zip
 node ./scripts/zip.js
 
-current_time=$(date "+%Y%m%d%H%M%S")
-
  # 上传到测试服务器
-function testServer() {
+function uploadServer() {
     expect -c "
         spawn scp ./zip/${file_name} root@192.168.0.109:/www/wwwroot/${file_path}
         expect {
@@ -93,12 +95,8 @@ EOF
     echo "plugins 等目录移除完成"
 }
 
- # 上传到测试服务器
-if [ $2 == "test" ]; then
-    if [ $1 == "all" ]; then
-        delPublic
-    fi
-    testServer
-else
-    echo "编译完成"
+# 上传到测试服务器
+if [ $1 == "all" ]; then
+    delPublic
 fi
+uploadServer

+ 6 - 4
package.json

@@ -6,10 +6,12 @@
         "dev": "vite",
         "build": "vite build",
         "yarn:install": "yarn --ignore-engines",
-        "build:zip": "sh ./scripts/build.sh all",
-        "build:zip:wgt": "sh ./scripts/build.sh wgt",
-        "build:test": "sh ./scripts/build.sh all test",
-        "build:test:wgt": "sh ./scripts/build.sh wgt test",
+        "build:zip": "sh ./build/main.sh all",
+        "build:zip:wgt": "sh ./build/main.sh wgt",
+        "build:test": "sh ./build/test.sh all",
+        "build:test:wgt": "sh ./build/test.sh wgt",
+        "build:online": "sh ./build/online.sh all",
+        "build:online:wgt": "sh ./build/online.sh wgt",
         "lint": "eslint --ext .js,.vue src",
         "lint:fix": "eslint . --fix"
     },

+ 1 - 1
public/version.json

@@ -1,3 +1,3 @@
 {
-  "value": "20240104114458"
+  "value": "20240104143232"
 }