seimin 3 gadi atpakaļ
vecāks
revīzija
78c78755ac
4 mainītis faili ar 55 papildinājumiem un 12 dzēšanām
  1. 2 1
      package.json
  2. 0 8
      upload/config.js
  3. 43 0
      upload/development.js
  4. 10 3
      upload/index.js

+ 2 - 1
package.json

@@ -6,7 +6,8 @@
6 6
     "start": "vue-cli-service serve",
7 7
     "build": "vue-cli-service build",
8 8
     "lint": "vue-cli-service lint",
9
-    "upload": "node ./upload/index.js"
9
+    "development": "node ./upload/development.js",
10
+    "production": "node ./upload/production.js"
10 11
   },
11 12
   "dependencies": {
12 13
     "axios": "^0.20.0",

+ 0 - 8
upload/config.js

@@ -1,8 +0,0 @@
1
-module.exports = {
2
-  ip: "192.168.3.108", // ssh地址
3
-  username: "root", // ssh 用户名
4
-  port: 22,      //端口
5
-  password: "123456", // ssh 密码
6
-  path: '/home/itsm/project/itsm-web/specimenView', // 上传地址
7
-  rmpath: '/home/itsm/project/itsm-web/specimenView' // 删除地址
8
-}

+ 43 - 0
upload/development.js

@@ -0,0 +1,43 @@
1
+const shell = require('shelljs')
2
+const path = require('path');
3
+const config = {
4
+  ip: "192.168.3.108", // ssh地址
5
+  username: "root", // ssh 用户名
6
+  port: 22,      //端口
7
+  password: "123456", // ssh 密码
8
+  path: '/home/itsm/project/itsm-web/specimenView', // 上传地址,删除地址
9
+  buildPath: '../dist/specimenView' // 本地打包后文件地址
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
+  if (shell.exec(`npm run build`).code == 0) {
38
+    console.log("-----打包成功-----");
39
+    //提交上传
40
+    connectSSh();
41
+  }
42
+}
43
+runTask()

+ 10 - 3
upload/index.js

@@ -1,6 +1,13 @@
1
-const config = require('./config.js')
2 1
 const shell = require('shelljs')
3 2
 const path = require('path');
3
+const config = {
4
+  ip: "118.190.89.49", // ssh地址
5
+  username: "root", // ssh 用户名
6
+  port: 22,      //端口
7
+  password: "dstech@123", // ssh 密码
8
+  path: '/home/itsm_v2_/web/specimenView', // 上传地址,删除地址
9
+  buildPath: '../dist/specimenView' // 本地打包后文件地址
10
+}
4 11
 let Client = require('ssh2-sftp-client');
5 12
 
6 13
 function connectSSh() {
@@ -12,11 +19,11 @@ function connectSSh() {
12 19
     password: config.password
13 20
   }).then(() => {
14 21
     console.log("-----先执行删除服务器文件-----")
15
-    return sftp.rmdir(config.rmpath, true);
22
+    return sftp.rmdir(config.path, true);
16 23
   }).then(() => {
17 24
     // 上传文件
18 25
     console.log("-----开始上传-----")
19
-    return sftp.uploadDir(path.resolve(__dirname, '../dist/specimenView'), config.path);
26
+    return sftp.uploadDir(path.resolve(__dirname, config.buildPath), config.path);
20 27
   }).then((data) => {
21 28
     console.log("-----上传完成-----");
22 29
     sftp.end();