Pārlūkot izejas kodu

演示平台和本地一键发布

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

+ 3 - 4
package.json

@@ -2,11 +2,10 @@
2
   "name": "itsm-zy",
2
   "name": "itsm-zy",
3
   "version": "0.0.0",
3
   "version": "0.0.0",
4
   "scripts": {
4
   "scripts": {
5
-    "210": "ng serve --proxy-config proxy.conf.json --port 4210 --disable-host-check --public-host=dashitech.com --host 0.0.0.0",
6
-    "ng": "ng",
7
-    "start": "ng serve",
5
+    "start": "ng serve --proxy-config proxy.conf.json --port 4210 --disable-host-check --public-host=dashitech.com --host 0.0.0.0",
8
     "build": "ng build --prod",
6
     "build": "ng build --prod",
9
-    "upload": "node ./upload/index.js",
7
+    "development": "node ./upload/development.js",
8
+    "production": "node ./upload/production.js",
10
     "test": "ng test",
9
     "test": "ng test",
11
     "lint": "ng lint",
10
     "lint": "ng lint",
12
     "e2e": "ng e2e",
11
     "e2e": "ng e2e",

+ 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/web', // 上传地址
7
-  rmpath: '/home/itsm/project/itsm-web/web' // 删除地址
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/web', // 上传地址,删除地址
9
+  buildPath: '../dist/itsm-pc' // 本地打包后文件地址
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
 const shell = require('shelljs')
1
 const shell = require('shelljs')
3
 const path = require('path');
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/pc', // 上传地址,删除地址
9
+  buildPath: '../dist/itsm-pc' // 本地打包后文件地址
10
+}
4
 let Client = require('ssh2-sftp-client');
11
 let Client = require('ssh2-sftp-client');
5
 
12
 
6
 function connectSSh() {
13
 function connectSSh() {
@@ -12,11 +19,11 @@ function connectSSh() {
12
     password: config.password
19
     password: config.password
13
   }).then(() => {
20
   }).then(() => {
14
     console.log("-----先执行删除服务器文件-----")
21
     console.log("-----先执行删除服务器文件-----")
15
-    return sftp.rmdir(config.rmpath, true);
22
+    return sftp.rmdir(config.path, true);
16
   }).then(() => {
23
   }).then(() => {
17
     // 上传文件
24
     // 上传文件
18
     console.log("-----开始上传-----")
25
     console.log("-----开始上传-----")
19
-    return sftp.uploadDir(path.resolve(__dirname, '../dist/itsm-pc'), config.path);
26
+    return sftp.uploadDir(path.resolve(__dirname, config.buildPath), config.path);
20
   }).then((data) => {
27
   }).then((data) => {
21
     console.log("-----上传完成-----");
28
     console.log("-----上传完成-----");
22
     sftp.end();
29
     sftp.end();