seimin 5 months ago
parent
commit
f6ee9692fc
2 changed files with 51 additions and 0 deletions
  1. 1 0
      package.json
  2. 50 0
      upload/development120.js

+ 1 - 0
package.json

@@ -6,6 +6,7 @@
6 6
     "dev": "vite",
7 7
     "build": "vite build",
8 8
     "development": "node ./upload/development.js",
9
+    "development120": "node ./upload/development120.js",
9 10
     "production": "node ./upload/production.js",
10 11
     "preview": "vite preview"
11 12
   },

+ 50 - 0
upload/development120.js

@@ -0,0 +1,50 @@
1
+const shell = require('shelljs')
2
+const path = require('path');
3
+const config = {
4
+  ip: "192.168.3.120", // ssh地址
5
+  username: "root", // ssh 用户名
6
+  port: 22,      //端口
7
+  password: "100100", // ssh 密码
8
+  path: '/home/itsm/project/web/hsms/spreadSheet', // 上传地址,删除地址
9
+  buildPath: '../dist/spreadSheet' // 本地打包后文件地址
10
+}
11
+let Client = require('ssh2-sftp-client');
12
+
13
+function connectSSh() {
14
+  let sftp = new Client();
15
+  sftp.connect({
16
+    host: config.ip,
17
+    port: config.port,
18
+    username: config.username,
19
+    password: config.password
20
+  }).then(() => {
21
+    console.log("-----先执行删除服务器文件-----")
22
+    return sftp.rmdir(config.path, true);
23
+  }).then(() => {
24
+    // 上传文件
25
+    console.log("-----开始上传-----")
26
+    return sftp.uploadDir(path.resolve(__dirname, config.buildPath), config.path);
27
+  }).then((data) => {
28
+    console.log("-----上传完成-----");
29
+    sftp.end();
30
+  }).catch((err) => {
31
+    console.log(err, '-----失败-----');
32
+    sftp.end();
33
+  });
34
+}
35
+function runTask() {
36
+  //打包完成
37
+  console.log(`当前NodeJs版本是${process.version}`);
38
+  const isNodeVersionLt17 = parseInt(process.version.slice(1)) < 17;
39
+  const execStr = isNodeVersionLt17 ? 'npm run build' : 'npm run build';
40
+  if (shell.exec(execStr).code == 0) {
41
+    // if (shell.exec(`find dist -name '*.js' -print0 | xargs -0 gzip -k`).code == 0) {
42
+      // if (shell.exec(`find dist -name '*.css' -print0 | xargs -0 gzip -k`).code == 0) {
43
+        console.log("-----打包成功-----");
44
+        //提交上传
45
+        connectSSh();
46
+      // }
47
+    // }
48
+  }
49
+}
50
+runTask()