|
@@ -0,0 +1,43 @@
|
|
1
|
+const shell = require('shelljs')
|
|
2
|
+const path = require('path');
|
|
3
|
+const config = {
|
|
4
|
+ ip: "192.168.3.120", // ssh地址
|
|
5
|
+ username: "root", // ssh 用户名
|
|
6
|
+ port: 22, //端口
|
|
7
|
+ password: "100100", // ssh 密码
|
|
8
|
+ path: '/home/itsm/project/web/hsms/largeScreen', // 上传地址,删除地址
|
|
9
|
+ buildPath: '../dist/largeScreen' // 本地打包后文件地址
|
|
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()
|