seimin před 3 roky
rodič
revize
7933cb0dd0
4 změnil soubory, kde provedl 15042 přidání a 21 odebrání
  1. 14951 20
      package-lock.json
  2. 5 1
      package.json
  3. 43 0
      upload/development.js
  4. 43 0
      upload/production.js

Diff nebyl zobrazen, protože je příliš veliký
+ 14951 - 20
package-lock.json


+ 5 - 1
package.json

@@ -5,7 +5,9 @@
5 5
   "scripts": {
6 6
     "start": "vue-cli-service serve",
7 7
     "build": "vue-cli-service build",
8
-    "lint": "vue-cli-service lint"
8
+    "lint": "vue-cli-service lint",
9
+    "development": "node ./upload/development.js",
10
+    "production": "node ./upload/production.js"
9 11
   },
10 12
   "dependencies": {
11 13
     "axios": "^0.19.2",
@@ -30,6 +32,8 @@
30 32
     "eslint-plugin-vue": "^6.2.2",
31 33
     "less": "^3.0.4",
32 34
     "less-loader": "^5.0.0",
35
+    "shelljs": "^0.8.5",
36
+    "ssh2-sftp-client": "^7.2.0",
33 37
     "vue-template-compiler": "^2.6.11"
34 38
   }
35 39
 }

+ 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/largeScreen2', // 上传地址,删除地址
9
+  buildPath: '../dist/largeScreen2' // 本地打包后文件地址
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()

+ 43 - 0
upload/production.js

@@ -0,0 +1,43 @@
1
+const shell = require('shelljs')
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/largeScreen2', // 上传地址,删除地址
9
+  buildPath: '../dist/largeScreen2' // 本地打包后文件地址
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()