@dypnb/dev-tools 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -17,46 +17,60 @@ async function getUploadServeConfig() {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
getUploadServeConfig().then(res => {
|
20
|
-
const
|
20
|
+
const {
|
21
|
+
projectInfo = { // 项目基本信息
|
22
|
+
name: '', // 项目名称
|
23
|
+
},
|
24
|
+
locaPath, // 本地上传地址
|
25
|
+
protocol = 'http', //协议 http、https
|
26
|
+
staticPath = {}, // 服务器静态资源地址
|
27
|
+
serverOption = {}, // 服务器配置
|
28
|
+
shell // shell 命令
|
29
|
+
} = res['uploadServeConfig'] || {};
|
30
|
+
|
21
31
|
const wxServerConfig = res['wxServerConfig'];
|
22
32
|
|
23
|
-
const isProduction = process.env.VUE_APP_PACK_ENV === "
|
33
|
+
const isProduction = process.env.VUE_APP_PACK_ENV === "production"; // 是否是生产环境
|
24
34
|
|
25
35
|
const lineVersion = process.env.VUE_APP_LINE_VERSION; //线上环境版本(多个显示环境可使用此字段区分)
|
26
36
|
|
27
37
|
const isNewPro = isProduction && +lineVersion === 2; // 是否是新的线上版本
|
28
38
|
|
29
|
-
const
|
30
|
-
|
31
|
-
const staticPath = !isProduction ? uploadServeConfig.staticPath.dev : uploadServeConfig.staticPath.pro;
|
39
|
+
const curtHost = !isNewPro ? serverOption.host[0] : serverOption.host[1];
|
32
40
|
|
33
|
-
const
|
41
|
+
const curtStaticPath = !isProduction ? staticPath.dev : staticPath.pro;
|
34
42
|
|
35
|
-
const
|
43
|
+
const onlinePath = `${protocol}://${curtHost}/${curtStaticPath}`;
|
36
44
|
|
37
45
|
const server = {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
pathNmae: `${
|
46
|
+
port: 22, // 端口默认22
|
47
|
+
...serverOption,
|
48
|
+
host: curtHost, // 服务器 ip
|
49
|
+
locaPath: `${process.env.PWD}${locaPath}`, // 本地打包文件的位置
|
50
|
+
pathNmae: `${serverOption.pathNmae}${curtStaticPath}` // 上传到服务器的位置
|
43
51
|
};
|
44
52
|
|
53
|
+
|
54
|
+
// 服务器删除静态资源命令
|
55
|
+
const shellCommand = !shell ? `rm -rf ${server.pathNmae}/*` : shell;
|
56
|
+
|
57
|
+
const gitInfo = getGitInfo();
|
58
|
+
|
59
|
+
|
45
60
|
const packInfo = {
|
46
|
-
...(
|
61
|
+
...(projectInfo || {}),
|
47
62
|
serverPath: server.pathNmae
|
48
63
|
}
|
49
64
|
|
50
65
|
|
51
66
|
function wxMsg(status) {
|
52
|
-
return `<div class="gray">${moment().format('lll')}</div><div class="highlight">${
|
67
|
+
return `<div class="gray">${moment().format('lll')}</div><div class="highlight">${projectInfo.name}${isProduction ? "生产" : "开发"}环境发布${status}</div><div class="normal">commitId:${gitInfo.commitId}</div><div class="normal">commitMsg:${gitInfo.commitMsg}</div><div class="normal">访问地址:${onlinePath}</div>`
|
53
68
|
}
|
54
69
|
|
55
70
|
|
56
71
|
cyanLog("本次打包信息 =>", packInfo);
|
57
72
|
|
58
73
|
|
59
|
-
|
60
74
|
const spinner = ora(
|
61
75
|
"正在发布到" + (isProduction ? "生产" : "开发") + "服务器..."
|
62
76
|
);
|
@@ -75,7 +89,7 @@ getUploadServeConfig().then(res => {
|
|
75
89
|
return false;
|
76
90
|
}
|
77
91
|
// 这里我拼接了放置服务器资源目录的位置 ,首选通过rm -rf删除了这个目录下的文件
|
78
|
-
conn.exec(
|
92
|
+
conn.exec(shellCommand, function(err, stream) {
|
79
93
|
warningLog("已删除服务端文件")
|
80
94
|
stream.on("close", function(code, signal) {
|
81
95
|
log("开始上传");
|
@@ -124,7 +138,7 @@ getUploadServeConfig().then(res => {
|
|
124
138
|
host: server.host,
|
125
139
|
port: server.port,
|
126
140
|
username: server.username,
|
127
|
-
password: server.password
|
128
|
-
|
141
|
+
password: server.password,
|
142
|
+
privateKey: server.privateKey || undefined //使用 私钥密钥登录 目前测试服务器不需要用到
|
129
143
|
});
|
130
144
|
})
|
@@ -1,130 +0,0 @@
|
|
1
|
-
#! /usr/bin/env node
|
2
|
-
|
3
|
-
// scp2 : https://www.npmjs.com/package/
|
4
|
-
// 引入scp2
|
5
|
-
import client from "scp2";
|
6
|
-
import ora from "ora";
|
7
|
-
import moment from "moment";
|
8
|
-
import { getGlobalConfig, getGitInfo, errorLog, magentaLog, log, warningLog, successLog, cyanLog } from "../utils/index.js";
|
9
|
-
import { wxNotify } from "../wx-server-notice/index.js";
|
10
|
-
import pkg from 'ssh2';
|
11
|
-
const { Client } = pkg;
|
12
|
-
|
13
|
-
moment.locale('zh-cn');
|
14
|
-
|
15
|
-
async function getUploadServeConfig() {
|
16
|
-
return await getGlobalConfig();
|
17
|
-
}
|
18
|
-
|
19
|
-
getUploadServeConfig().then(res => {
|
20
|
-
const uploadServeConfig = res['uploadServeConfig'];
|
21
|
-
const wxServerConfig = res['wxServerConfig'];
|
22
|
-
|
23
|
-
const isProduction = process.env.VUE_APP_PACK_ENV === "pro"; // 是否是生产环境
|
24
|
-
|
25
|
-
const lineVersion = process.env.VUE_APP_LINE_VERSION; //线上环境版本(多个显示环境可使用此字段区分)
|
26
|
-
|
27
|
-
const isNewPro = isProduction && +lineVersion === 2; // 是否是新的线上版本
|
28
|
-
|
29
|
-
const host = !isNewPro ? uploadServeConfig.host[0] : uploadServeConfig.host[1];
|
30
|
-
|
31
|
-
const staticPath = !isProduction ? uploadServeConfig.staticPath.dev : uploadServeConfig.staticPath.pro;
|
32
|
-
|
33
|
-
const onlinePath = `${uploadServeConfig.protocol}://${host}/${staticPath}`
|
34
|
-
|
35
|
-
const gitInfo = getGitInfo();
|
36
|
-
|
37
|
-
const server = {
|
38
|
-
host, // 服务器ip
|
39
|
-
port: "22", // 端口一般默认22
|
40
|
-
locaPath: `${process.env.PWD}${uploadServeConfig.locaPath}`, // 本地打包文件的位置
|
41
|
-
...uploadServeConfig.serverOption,
|
42
|
-
pathNmae: `${uploadServeConfig.serverOption.pathNmae}${staticPath}` // 上传到服务器的位置
|
43
|
-
};
|
44
|
-
|
45
|
-
const packInfo = {
|
46
|
-
...(uploadServeConfig.baseInfo || {}),
|
47
|
-
serverPath: server.pathNmae
|
48
|
-
}
|
49
|
-
|
50
|
-
|
51
|
-
function wxMsg(status) {
|
52
|
-
return `<div class="gray">${moment().format('lll')}</div><div class="highlight">${uploadServeConfig.projectTitle}${isProduction ? "生产" : "开发"}环境发布${status}</div><div class="normal">commitId:${gitInfo.commitId}</div><div class="normal">commitMsg:${gitInfo.commitMsg}</div><div class="normal">访问地址:${onlinePath}</div>`
|
53
|
-
}
|
54
|
-
|
55
|
-
|
56
|
-
cyanLog("本次打包信息 =>", packInfo);
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
const spinner = ora(
|
61
|
-
"正在发布到" + (isProduction ? "生产" : "开发") + "服务器..."
|
62
|
-
);
|
63
|
-
|
64
|
-
// 创建shell脚本
|
65
|
-
const conn = new Client();
|
66
|
-
|
67
|
-
magentaLog("正在建立连接");
|
68
|
-
|
69
|
-
conn
|
70
|
-
.on("ready", function() {
|
71
|
-
log("已连接");
|
72
|
-
if (!server.pathNmae) {
|
73
|
-
log("连接已关闭");
|
74
|
-
conn.end();
|
75
|
-
return false;
|
76
|
-
}
|
77
|
-
// 这里我拼接了放置服务器资源目录的位置 ,首选通过rm -rf删除了这个目录下的文件
|
78
|
-
conn.exec("rm -rf " + server.pathNmae + "/*", function(err, stream) {
|
79
|
-
warningLog("已删除服务端文件")
|
80
|
-
stream.on("close", function(code, signal) {
|
81
|
-
log("开始上传");
|
82
|
-
spinner.start();
|
83
|
-
client.scp(
|
84
|
-
server.locaPath,
|
85
|
-
{
|
86
|
-
host: server.host,
|
87
|
-
port: server.port,
|
88
|
-
username: server.username,
|
89
|
-
password: server.password,
|
90
|
-
path: server.pathNmae
|
91
|
-
},
|
92
|
-
err => {
|
93
|
-
spinner.stop();
|
94
|
-
if (!err) {
|
95
|
-
successLog("Success! 成功发布到" + (isProduction ? "生产" : "开发") + "服务器!", `访问地址====>${onlinePath}`)
|
96
|
-
wxNotify({
|
97
|
-
msgtype: "textcard",
|
98
|
-
textcard: {
|
99
|
-
title: "发布成功",
|
100
|
-
description: wxMsg('成功'),
|
101
|
-
url: onlinePath,
|
102
|
-
btntxt: "更多"
|
103
|
-
}
|
104
|
-
}, wxServerConfig);
|
105
|
-
} else {
|
106
|
-
errorLog("发布失败.\n", err);
|
107
|
-
wxNotify({
|
108
|
-
msgtype: "textcard",
|
109
|
-
textcard: {
|
110
|
-
title: "发布失败",
|
111
|
-
description: wxMsg('失败'),
|
112
|
-
url: onlinePath,
|
113
|
-
btntxt: "更多"
|
114
|
-
}
|
115
|
-
}, wxServerConfig);
|
116
|
-
}
|
117
|
-
conn.end(); // 结束命令
|
118
|
-
}
|
119
|
-
);
|
120
|
-
});
|
121
|
-
});
|
122
|
-
})
|
123
|
-
.connect({
|
124
|
-
host: server.host,
|
125
|
-
port: server.port,
|
126
|
-
username: server.username,
|
127
|
-
password: server.password
|
128
|
-
//privateKey: '' //使用 私钥密钥登录 目前测试服务器不需要用到
|
129
|
-
});
|
130
|
-
})
|