|
@@ -1,45 +0,0 @@
|
1
|
|
-const shell = require('shelljs')
|
2
|
|
-const path = require('path');
|
3
|
|
-const config = {
|
4
|
|
- ip: "192.168.3.110", // ssh地址
|
5
|
|
- username: "root", // ssh 用户名
|
6
|
|
- port: 22, //端口
|
7
|
|
- password: "DStech@123", // ssh 密码
|
8
|
|
- // path: '/home/itsm/project/web/pc', // 上传地址,删除地址(第一次部署)
|
9
|
|
- path: '/home/itsm/project/web/pc/assets', // 上传地址,删除地址(bower_components太大,第二次以后的更新只更新assets,具体的灵活应变)
|
10
|
|
- // buildPath: '../dist' // 本地打包后文件地址(第一次部署)
|
11
|
|
- buildPath: '../dist/assets' // 本地打包后文件地址(bower_components太大,第二次以后的更新只更新assets,具体的灵活应变)
|
12
|
|
-}
|
13
|
|
-let Client = require('ssh2-sftp-client');
|
14
|
|
-
|
15
|
|
-function connectSSh() {
|
16
|
|
- let sftp = new Client();
|
17
|
|
- sftp.connect({
|
18
|
|
- host: config.ip,
|
19
|
|
- port: config.port,
|
20
|
|
- username: config.username,
|
21
|
|
- password: config.password
|
22
|
|
- }).then(() => {
|
23
|
|
- console.log("-----先执行删除服务器文件-----")
|
24
|
|
- return sftp.rmdir(config.path, true);
|
25
|
|
- }).then(() => {
|
26
|
|
- // 上传文件
|
27
|
|
- console.log("-----开始上传-----")
|
28
|
|
- return sftp.uploadDir(path.resolve(__dirname, config.buildPath), config.path);
|
29
|
|
- }).then((data) => {
|
30
|
|
- console.log("-----上传完成-----");
|
31
|
|
- sftp.end();
|
32
|
|
- }).catch((err) => {
|
33
|
|
- console.log(err, '-----失败-----');
|
34
|
|
- sftp.end();
|
35
|
|
- });
|
36
|
|
-}
|
37
|
|
-function runTask() {
|
38
|
|
- //打包完成
|
39
|
|
- if (shell.exec(`npm run build`).code == 0) {
|
40
|
|
- console.log("-----打包成功-----");
|
41
|
|
- //提交上传
|
42
|
|
- connectSSh();
|
43
|
|
- }
|
44
|
|
-}
|
45
|
|
-runTask()
|