liyongli 2 년 전
부모
커밋
7e3aa48798
3개의 변경된 파일114개의 추가작업 그리고 579개의 파일을 삭제
  1. 1 0
      package.json
  2. 66 576
      pnpm-lock.yaml
  3. 47 3
      saveOSSAGitte.js

+ 1 - 0
package.json

@@ -32,6 +32,7 @@
     "compression-webpack-plugin": "5.0.1",
     "eslint": "^6.7.2",
     "eslint-plugin-vue": "^7.0.0",
+    "ssh2-sftp-client": "^9.0.4",
     "typescript": "^4.3.5",
     "unplugin-auto-import": "^0.6.6",
     "unplugin-element-plus": "^0.1.0",

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 66 - 576
pnpm-lock.yaml


+ 47 - 3
saveOSSAGitte.js

@@ -1,12 +1,13 @@
-// const client = require("ali-oss");
+const client = require("ssh2-sftp-client");
 const path = require("path");
 const fs = require("fs");
+
 const { execSync } = require("child_process");
 
 (async function Init() {
   const localDir = "dist/";
   const dirPath = path.resolve(__dirname, "./" + localDir);
-  const list = []
+  const list = [];
 
   /**
    * 获取localDir下的所有文件路径
@@ -23,6 +24,48 @@ const { execSync } = require("child_process");
     }
   }
 
+  function upServer() {
+    const config = {
+      path: {
+        // 远程地址
+        romotePath: "/var/www/test",
+        // 本地地址
+        localPath: path.resolve(__dirname, "./dist"),
+      },
+      romote: {
+        // 服务器 ip 地址
+        host: "123.57.195.226",
+        // 端口号,默认是 22
+        port: 22,
+        // 登录的用户名
+        username: "root",
+        // 登录密码
+        password: "581100Li.",
+      },
+    };
+    const sftp = new client();
+    sftp
+      .connect(config.romote)
+      .then(() => {
+        console.log("连接成功,删除中... ");
+        return sftp.rmdir(config.path.romotePath, true);
+      })
+      .then(() => {
+        console.log("上传中... ");
+        return sftp.uploadDir(config.path.localPath, config.path.romotePath);
+      })
+      .then(data => {
+        console.log("上传完成", data);
+      })
+      .catch(err => {
+        console.log("出错了!!", err);
+      })
+      .finally(() => {
+        // 断开连接
+        sftp.end();
+      });
+  }
+
   /**
    * 上传git
    */
@@ -41,7 +84,8 @@ const { execSync } = require("child_process");
   execFun();
   try {
     await getFiles(dirPath);
-    console.log("获取文件路径---完成", list);
+    upServer();
+    console.log("获取文件路径---完成");
   } catch (err) {
     console.log("数据上传oss---失败");
   }

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.