Bladeren bron

演示平台和本地一键发布

seimin 3 jaren geleden
bovenliggende
commit
96d40d4367
4 gewijzigde bestanden met toevoegingen van 56 en 15 verwijderingen
  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 2
   "name": "itsm-zy",
3 3
   "version": "0.0.0",
4 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 6
     "build": "ng build --prod",
9
-    "upload": "node ./upload/index.js",
7
+    "development": "node ./upload/development.js",
8
+    "production": "node ./upload/production.js",
10 9
     "test": "ng test",
11 10
     "lint": "ng lint",
12 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 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/pc', // 上传地址,删除地址
9
+  buildPath: '../dist/itsm-pc' // 本地打包后文件地址
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/itsm-pc'), 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();