@pisell/common 0.0.21-bata → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.fatherrc.ts +7 -0
- package/CHANGELOG.md +14 -0
- package/README.md +1 -38
- package/es/bin/pisell.js +0 -0
- package/es/index.d.ts +2 -4
- package/es/index.js +1 -4
- package/es/script/utils/index.js +1 -1
- package/lib/index.d.ts +2 -4
- package/lib/index.js +8 -5
- package/lib/script/deploy.js +0 -2
- package/lib/script/release/index.js +0 -2
- package/lib/script/release/release.js +0 -2
- package/lib/script/uploadCode/index.js +0 -2
- package/lib/script/uploadCode/uploadCode.js +0 -2
- package/lib/script/utils/index.js +1 -1
- package/package.json +23 -74
- package/src/bin/pisell.js +3 -0
- package/src/index.ts +1 -0
- package/src/script/constants/index.js +14 -0
- package/src/script/deploy.js +29 -0
- package/src/script/index.js +45 -0
- package/src/script/package.json +4 -0
- package/src/script/release/index.js +119 -0
- package/src/script/release/release.js +84 -0
- package/src/script/uploadCode/index.js +244 -0
- package/src/script/uploadCode/uploadCode.js +217 -0
- package/src/script/utils/index.js +275 -0
- package/tsconfig.json +14 -0
- package/LICENSE +0 -21
- package/es/business-components/colorInput/index.d.ts +0 -21
- package/es/business-components/colorInput/index.js +0 -43
- package/es/business-components/colorInput/index.less +0 -10
- package/es/business-components/index.d.ts +0 -11
- package/es/business-components/index.js +0 -7
- package/es/business-components/rechargeOption/index.d.ts +0 -36
- package/es/business-components/rechargeOption/index.js +0 -132
- package/es/business-components/rechargeOption/index.less +0 -0
- package/es/business-components/selectTag/index.d.ts +0 -25
- package/es/business-components/selectTag/index.js +0 -179
- package/es/business-components/selectTag/index.less +0 -22
- package/es/business-components/sortModal/index.d.ts +0 -30
- package/es/business-components/sortModal/index.js +0 -85
- package/es/business-components/sortModal/index.less +0 -29
- package/es/business-components/statistics/index.d.ts +0 -12
- package/es/business-components/statistics/index.js +0 -38
- package/es/business-components/statistics/index.less +0 -64
- package/es/business-components/tagModal/index.d.ts +0 -17
- package/es/business-components/tagModal/index.js +0 -58
- package/es/business-hooks/index.d.ts +0 -2
- package/es/business-hooks/index.js +0 -2
- package/es/business-hooks/useModal/index.d.ts +0 -31
- package/es/business-hooks/useModal/index.js +0 -91
- package/es/business-hooks/useModal/index.less +0 -0
- package/es/business-hooks/useTagModal/index.d.ts +0 -17
- package/es/business-hooks/useTagModal/index.js +0 -47
- package/es/components/ColorPicker/index.d.ts +0 -22
- package/es/components/ColorPicker/index.js +0 -51
- package/es/components/ColorPicker/index.less +0 -17
- package/es/components/DragSort/index.js +0 -68
- package/es/components/EditorPreview/index.js +0 -14
- package/es/components/EditorPreview/index.less +0 -81
- package/es/components/Iconfont/index.d.ts +0 -6
- package/es/components/Iconfont/index.js +0 -29
- package/es/components/Iconfont/index.less +0 -0
- package/es/components/agreement/Detail/index.js +0 -77
- package/es/components/agreement/Detail/serve.d.ts +0 -1
- package/es/components/agreement/Detail/serve.js +0 -6
- package/es/components/agreement/index.d.ts +0 -11
- package/es/components/agreement/index.js +0 -45
- package/es/components/agreement/index.less +0 -20
- package/es/components/avatar/index.d.ts +0 -13
- package/es/components/avatar/index.js +0 -25
- package/es/components/button/index.js +0 -36
- package/es/components/card/index.js +0 -16
- package/es/components/card/index.less +0 -9
- package/es/components/checkbox/index.js +0 -43
- package/es/components/configProvider/index.d.ts +0 -113
- package/es/components/configProvider/index.js +0 -114
- package/es/components/datePicker/index.js +0 -17
- package/es/components/index.js +0 -16
- package/es/components/input/index.js +0 -97
- package/es/components/inputNumber/index.js +0 -17
- package/es/components/pagination/index.d.ts +0 -10
- package/es/components/pagination/index.js +0 -18
- package/es/components/radio/index.js +0 -28
- package/es/components/select/index.js +0 -17
- package/es/components/switch/index.d.ts +0 -10
- package/es/components/switch/index.js +0 -18
- package/es/config/index.js +0 -18
- package/es/config/request.d.ts +0 -7
- package/es/config/request.js +0 -67
- package/es/config/utils.d.ts +0 -0
- package/es/config/utils.js +0 -0
- package/es/hooks/index.d.ts +0 -8
- package/es/hooks/index.js +0 -8
- package/es/hooks/useCountDown/index.d.ts +0 -10
- package/es/hooks/useCountDown/index.js +0 -48
- package/es/hooks/useDocumentScroll/index.d.ts +0 -8
- package/es/hooks/useDocumentScroll/index.js +0 -41
- package/es/hooks/useDocumentScroll/index.less +0 -0
- package/es/hooks/useMousemove/index.d.ts +0 -8
- package/es/hooks/useMousemove/index.js +0 -61
- package/es/hooks/useResponsive/index.d.ts +0 -2
- package/es/hooks/useResponsive/index.js +0 -29
- package/es/hooks/useResponsive/index.less +0 -0
- package/es/hooks/useSize/index.d.ts +0 -2
- package/es/hooks/useSize/index.js +0 -27
- package/es/hooks/useSize/index.less +0 -0
- package/es/hooks/useStateMulti/index.d.ts +0 -2
- package/es/hooks/useStateMulti/index.js +0 -29
- package/es/hooks/useStateWithCb/index.d.ts +0 -2
- package/es/hooks/useStateWithCb/index.js +0 -42
- package/es/hooks/useTable/index.d.ts +0 -12
- package/es/hooks/useTable/index.js +0 -74
- package/es/hooks/useTable/index.less +0 -0
- package/es/hooks/useTableModal/index.d.ts +0 -12
- package/es/hooks/useTableModal/index.js +0 -25
- package/es/hooks/useTableModal/index.less +0 -0
- package/es/hooks/useUrlState/index.d.ts +0 -2
- package/es/hooks/useUrlState/index.js +0 -56
- package/es/hooks/useWebSocket/index.d.ts +0 -13
- package/es/hooks/useWebSocket/index.js +0 -121
- package/es/locales/en-US.d.ts +0 -11
- package/es/locales/en-US.js +0 -10
- package/es/locales/index.d.ts +0 -1
- package/es/locales/index.js +0 -23
- package/es/locales/zh-CN.d.ts +0 -11
- package/es/locales/zh-CN.js +0 -10
- package/es/locales/zh-TW.d.ts +0 -11
- package/es/locales/zh-TW.js +0 -10
- package/es/utils/index.d.ts +0 -3
- package/es/utils/index.js +0 -3
- package/es/utils/otherUtils.d.ts +0 -8
- package/es/utils/otherUtils.js +0 -12
- package/es/utils/storage.d.ts +0 -30
- package/es/utils/storage.js +0 -70
- package/es/utils/typeUtils.d.ts +0 -42
- package/es/utils/typeUtils.js +0 -86
- package/lib/business-components/colorInput/index.d.ts +0 -21
- package/lib/business-components/colorInput/index.js +0 -70
- package/lib/business-components/colorInput/index.less +0 -10
- package/lib/business-components/index.d.ts +0 -11
- package/lib/business-components/index.js +0 -54
- package/lib/business-components/rechargeOption/index.d.ts +0 -36
- package/lib/business-components/rechargeOption/index.js +0 -112
- package/lib/business-components/rechargeOption/index.less +0 -0
- package/lib/business-components/selectTag/index.d.ts +0 -25
- package/lib/business-components/selectTag/index.js +0 -181
- package/lib/business-components/selectTag/index.less +0 -22
- package/lib/business-components/sortModal/index.d.ts +0 -30
- package/lib/business-components/sortModal/index.js +0 -100
- package/lib/business-components/sortModal/index.less +0 -29
- package/lib/business-components/statistics/index.d.ts +0 -12
- package/lib/business-components/statistics/index.js +0 -63
- package/lib/business-components/statistics/index.less +0 -64
- package/lib/business-components/tagModal/index.d.ts +0 -17
- package/lib/business-components/tagModal/index.js +0 -66
- package/lib/business-hooks/index.d.ts +0 -2
- package/lib/business-hooks/index.js +0 -42
- package/lib/business-hooks/useModal/index.d.ts +0 -31
- package/lib/business-hooks/useModal/index.js +0 -68
- package/lib/business-hooks/useModal/index.less +0 -0
- package/lib/business-hooks/useTagModal/index.d.ts +0 -17
- package/lib/business-hooks/useTagModal/index.js +0 -61
- package/lib/components/ColorPicker/index.d.ts +0 -22
- package/lib/components/ColorPicker/index.js +0 -80
- package/lib/components/ColorPicker/index.less +0 -17
- package/lib/components/DragSort/index.js +0 -101
- package/lib/components/EditorPreview/index.js +0 -37
- package/lib/components/EditorPreview/index.less +0 -81
- package/lib/components/Iconfont/index.d.ts +0 -6
- package/lib/components/Iconfont/index.js +0 -48
- package/lib/components/Iconfont/index.less +0 -0
- package/lib/components/agreement/Detail/index.js +0 -86
- package/lib/components/agreement/Detail/serve.d.ts +0 -1
- package/lib/components/agreement/Detail/serve.js +0 -30
- package/lib/components/agreement/index.d.ts +0 -11
- package/lib/components/agreement/index.js +0 -82
- package/lib/components/agreement/index.less +0 -20
- package/lib/components/avatar/index.d.ts +0 -13
- package/lib/components/avatar/index.js +0 -42
- package/lib/components/button/index.js +0 -36
- package/lib/components/card/index.js +0 -42
- package/lib/components/card/index.less +0 -9
- package/lib/components/checkbox/index.js +0 -36
- package/lib/components/configProvider/index.d.ts +0 -113
- package/lib/components/configProvider/index.js +0 -159
- package/lib/components/datePicker/index.js +0 -31
- package/lib/components/index.js +0 -83
- package/lib/components/input/index.js +0 -53
- package/lib/components/inputNumber/index.js +0 -31
- package/lib/components/pagination/index.d.ts +0 -10
- package/lib/components/pagination/index.js +0 -42
- package/lib/components/radio/index.js +0 -36
- package/lib/components/select/index.js +0 -36
- package/lib/components/switch/index.d.ts +0 -10
- package/lib/components/switch/index.js +0 -42
- package/lib/config/index.js +0 -39
- package/lib/config/request.d.ts +0 -7
- package/lib/config/request.js +0 -76
- package/lib/config/utils.d.ts +0 -0
- package/lib/config/utils.js +0 -0
- package/lib/hooks/index.d.ts +0 -8
- package/lib/hooks/index.js +0 -57
- package/lib/hooks/useCountDown/index.d.ts +0 -10
- package/lib/hooks/useCountDown/index.js +0 -57
- package/lib/hooks/useDocumentScroll/index.d.ts +0 -8
- package/lib/hooks/useDocumentScroll/index.js +0 -54
- package/lib/hooks/useDocumentScroll/index.less +0 -0
- package/lib/hooks/useMousemove/index.d.ts +0 -8
- package/lib/hooks/useMousemove/index.js +0 -70
- package/lib/hooks/useResponsive/index.d.ts +0 -2
- package/lib/hooks/useResponsive/index.js +0 -47
- package/lib/hooks/useResponsive/index.less +0 -0
- package/lib/hooks/useSize/index.d.ts +0 -2
- package/lib/hooks/useSize/index.js +0 -45
- package/lib/hooks/useSize/index.less +0 -0
- package/lib/hooks/useStateMulti/index.d.ts +0 -2
- package/lib/hooks/useStateMulti/index.js +0 -43
- package/lib/hooks/useStateWithCb/index.d.ts +0 -2
- package/lib/hooks/useStateWithCb/index.js +0 -53
- package/lib/hooks/useTable/index.d.ts +0 -12
- package/lib/hooks/useTable/index.js +0 -75
- package/lib/hooks/useTable/index.less +0 -0
- package/lib/hooks/useTableModal/index.d.ts +0 -12
- package/lib/hooks/useTableModal/index.js +0 -43
- package/lib/hooks/useTableModal/index.less +0 -0
- package/lib/hooks/useUrlState/index.d.ts +0 -2
- package/lib/hooks/useUrlState/index.js +0 -59
- package/lib/hooks/useWebSocket/index.d.ts +0 -13
- package/lib/hooks/useWebSocket/index.js +0 -91
- package/lib/locales/en-US.d.ts +0 -11
- package/lib/locales/en-US.js +0 -36
- package/lib/locales/index.d.ts +0 -1
- package/lib/locales/index.js +0 -59
- package/lib/locales/zh-CN.d.ts +0 -11
- package/lib/locales/zh-CN.js +0 -36
- package/lib/locales/zh-TW.d.ts +0 -11
- package/lib/locales/zh-TW.js +0 -36
- package/lib/utils/index.d.ts +0 -3
- package/lib/utils/index.js +0 -21
- package/lib/utils/otherUtils.d.ts +0 -8
- package/lib/utils/otherUtils.js +0 -31
- package/lib/utils/storage.d.ts +0 -30
- package/lib/utils/storage.js +0 -63
- package/lib/utils/typeUtils.d.ts +0 -42
- package/lib/utils/typeUtils.js +0 -75
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
#!/usr/bin/env zx
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import 'zx/globals';
|
|
4
|
+
import Release from '../release/release.js';
|
|
5
|
+
import {
|
|
6
|
+
getCurrentProjectName,
|
|
7
|
+
getCurrentUserName,
|
|
8
|
+
sendWebhook,
|
|
9
|
+
} from '../utils/index.js';
|
|
10
|
+
import UploadCode from './uploadCode.js';
|
|
11
|
+
// {\"post\":{\"zh_cn\":{\"title\":\"my_pisell_shop release环境开始上传并发布\",\"content\":[[{\"text\":\"发布人:\",\"style\":[\"bold\"]},{\"text\":\"左胜杰\",\"style\":[\"bold\"]}],[{\"text\":\"版本号:\",\"style\":[\"bold\"]},{\"text\":\"1.0.71\",\"style\":[\"bold\"]}]]}}}
|
|
12
|
+
/**
|
|
13
|
+
* @Title: 选择器函数
|
|
14
|
+
* @Describe:
|
|
15
|
+
* @Author: Wzw
|
|
16
|
+
*/
|
|
17
|
+
const inquirerResult = () => {
|
|
18
|
+
return inquirer.prompt([
|
|
19
|
+
// {
|
|
20
|
+
// type: "list",
|
|
21
|
+
// message: "请选择项目",
|
|
22
|
+
// name: "project",
|
|
23
|
+
// choices: [
|
|
24
|
+
// {
|
|
25
|
+
// value: {
|
|
26
|
+
// path: "./",
|
|
27
|
+
// fileName: "my_pisel_shop"
|
|
28
|
+
// },
|
|
29
|
+
// name: "my_pisel_shop"
|
|
30
|
+
// },
|
|
31
|
+
// ],
|
|
32
|
+
// },
|
|
33
|
+
{
|
|
34
|
+
type: 'list',
|
|
35
|
+
message: '请选择发布环境',
|
|
36
|
+
name: 'env',
|
|
37
|
+
choices: ['release', 'pre', 'prod'],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'rawlist',
|
|
41
|
+
message: '请选择当前更新版本号',
|
|
42
|
+
name: 'version',
|
|
43
|
+
default: false,
|
|
44
|
+
choices: ['patch', 'minor', 'major'],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'input',
|
|
48
|
+
message: '请输入更新内容',
|
|
49
|
+
name: 'changelog',
|
|
50
|
+
default: 'update',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'list',
|
|
54
|
+
message: '上传之后是否执行发布',
|
|
55
|
+
name: 'is_release',
|
|
56
|
+
choices: [
|
|
57
|
+
{ value: true, name: '上传并发布' },
|
|
58
|
+
{ value: false, name: '只上传' },
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: 'confirm',
|
|
63
|
+
message: '确认信息无误',
|
|
64
|
+
name: 'is_confirm',
|
|
65
|
+
default: true,
|
|
66
|
+
},
|
|
67
|
+
]);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
async function init() {
|
|
71
|
+
let res = await inquirerResult();
|
|
72
|
+
|
|
73
|
+
if (!res.is_confirm) {
|
|
74
|
+
console.log('取消发布');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 之前选择项目模式改为获取当前主项目 */
|
|
79
|
+
res.project = {
|
|
80
|
+
path: './',
|
|
81
|
+
fileName: getCurrentProjectName(),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// const data = await $`curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"post","content":""}' https://open.feishu.cn/open-apis/bot/v2/hook/08349b0d-016c-4133-9442-9e95d4adc1e8`
|
|
85
|
+
|
|
86
|
+
// 删除本地在远程不存在的tag
|
|
87
|
+
await $`git fetch --prune-tags`;
|
|
88
|
+
|
|
89
|
+
const uploadCode = new UploadCode(res);
|
|
90
|
+
|
|
91
|
+
if (!(await uploadCode.check())) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.log('开始更新版本号');
|
|
96
|
+
const version = await uploadCode.updateVersion();
|
|
97
|
+
console.log('✅ 版本更新完成');
|
|
98
|
+
|
|
99
|
+
const currentUserName = await getCurrentUserName();
|
|
100
|
+
|
|
101
|
+
const result = await sendWebhook({
|
|
102
|
+
title: `${res.project.fileName} ${res.env}环境开始${
|
|
103
|
+
res.is_release ? '上传并发布' : '上传'
|
|
104
|
+
}`,
|
|
105
|
+
content: [
|
|
106
|
+
{
|
|
107
|
+
key: '发布人',
|
|
108
|
+
value: currentUserName.replace('\n', ''),
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
key: '更新内容',
|
|
112
|
+
value: res.changelog,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
key: '版本号',
|
|
116
|
+
value: version || '',
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
console.log(result, 'result');
|
|
121
|
+
try {
|
|
122
|
+
console.log('开始打包');
|
|
123
|
+
await uploadCode.build();
|
|
124
|
+
console.log('✅ 打包完成');
|
|
125
|
+
|
|
126
|
+
console.log('开始压缩');
|
|
127
|
+
await uploadCode.compress();
|
|
128
|
+
console.log('✅ 压缩完成');
|
|
129
|
+
|
|
130
|
+
console.log('开始连接服务器');
|
|
131
|
+
const conn = await uploadCode.connectServer();
|
|
132
|
+
console.log('✅ 连接服务器完成');
|
|
133
|
+
|
|
134
|
+
console.log('开始上传');
|
|
135
|
+
await uploadCode.serverUpload();
|
|
136
|
+
console.log('✅ 上传完成');
|
|
137
|
+
|
|
138
|
+
console.log('开始解压');
|
|
139
|
+
await uploadCode.serverUnpack();
|
|
140
|
+
|
|
141
|
+
if (res.is_release) {
|
|
142
|
+
const releaseInstance = new Release({
|
|
143
|
+
project: res.project,
|
|
144
|
+
env: res.env,
|
|
145
|
+
version,
|
|
146
|
+
conn,
|
|
147
|
+
});
|
|
148
|
+
console.log('开始发布');
|
|
149
|
+
await releaseInstance.release();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 断开连接
|
|
153
|
+
await uploadCode.disconnectServer();
|
|
154
|
+
|
|
155
|
+
await $`git pull --no-edit`;
|
|
156
|
+
|
|
157
|
+
await $`git push --follow-tags`;
|
|
158
|
+
console.log('✅ 成功后推送到git');
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.log(error, '执行出错 请排查重试');
|
|
161
|
+
await $`git reset HEAD~1`;
|
|
162
|
+
await $`git tag -d v${uploadCode.currentVersion}`;
|
|
163
|
+
await sendWebhook({
|
|
164
|
+
title: `${res.project.fileName} ${res.env}环境${
|
|
165
|
+
res.is_release ? '上传并发布' : '上传'
|
|
166
|
+
}失败`,
|
|
167
|
+
content: [
|
|
168
|
+
{
|
|
169
|
+
key: '发布人',
|
|
170
|
+
value: currentUserName.replace('\n', ''),
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
key: '更新内容',
|
|
174
|
+
value: res.changelog,
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
key: '版本号',
|
|
178
|
+
value: version || '',
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
await sendWebhook({
|
|
184
|
+
title: `${res.project.fileName} ${res.env}环境${
|
|
185
|
+
res.is_release ? '上传并发布' : '上传'
|
|
186
|
+
}成功`,
|
|
187
|
+
content: [
|
|
188
|
+
{
|
|
189
|
+
key: '发布人',
|
|
190
|
+
value: currentUserName.replace('\n', ''),
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
key: '更新内容',
|
|
194
|
+
value: res.changelog,
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
key: '版本号',
|
|
198
|
+
value: version || '',
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
});
|
|
202
|
+
uploadCode.deleteLocalZip();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export default init;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
*
|
|
209
|
+
* 上传
|
|
210
|
+
* 1. 选择项目 环境等.
|
|
211
|
+
* 2. 打包
|
|
212
|
+
* 3. 打包完成后生成dist文件压缩包
|
|
213
|
+
* 4. 重命名为当前版本号
|
|
214
|
+
* 5. 上传到服务器,并解压. 上传完成
|
|
215
|
+
*
|
|
216
|
+
*
|
|
217
|
+
*
|
|
218
|
+
* 服务器目录结构:
|
|
219
|
+
*
|
|
220
|
+
* project: 所有前端项目
|
|
221
|
+
*
|
|
222
|
+
* my_pisel_h5: 某个项目文件夹
|
|
223
|
+
*
|
|
224
|
+
* master: 当前线上环境指向的代码包
|
|
225
|
+
*
|
|
226
|
+
* v1.0.0: 某个版本
|
|
227
|
+
*
|
|
228
|
+
*
|
|
229
|
+
* 部署, 此部分可界面化.
|
|
230
|
+
* 1. 将master备份, 把对应版本的代码合并到master内.
|
|
231
|
+
* 2. 重启当前服务
|
|
232
|
+
*
|
|
233
|
+
*
|
|
234
|
+
* 回滚指定版本
|
|
235
|
+
*
|
|
236
|
+
* 1. 将master内文件清空并将某个版本的包解压到master内
|
|
237
|
+
* 2. 重启服务
|
|
238
|
+
*
|
|
239
|
+
* node端需要提供以下接口
|
|
240
|
+
*
|
|
241
|
+
* 1. 获取每个项目的所有版本包名称.
|
|
242
|
+
* 2. 通过 项目 + 版本包名称 将对应的包更新至maser 实现发布
|
|
243
|
+
* 3. 将操作记录写成日志存储.
|
|
244
|
+
*/
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import archiver from 'archiver';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { outPathMap } from '../constants/index.js';
|
|
4
|
+
import {
|
|
5
|
+
connectServer,
|
|
6
|
+
getGitCurrentBranch,
|
|
7
|
+
getServerConfig,
|
|
8
|
+
isWorkingTreeClean,
|
|
9
|
+
serverUnpack,
|
|
10
|
+
serverUpload,
|
|
11
|
+
} from '../utils/index.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @Title: 上传代码至服务器类
|
|
15
|
+
* @Describe:
|
|
16
|
+
* @Author: Zsj
|
|
17
|
+
*/
|
|
18
|
+
class UploadCode {
|
|
19
|
+
constructor(props) {
|
|
20
|
+
const { project, env, version, changelog, is_release } = props;
|
|
21
|
+
this.projectName = project.fileName;
|
|
22
|
+
this.projectRelativePath = project.path;
|
|
23
|
+
this.env = env;
|
|
24
|
+
this.version = version;
|
|
25
|
+
this.changelog = changelog;
|
|
26
|
+
this.is_release = is_release;
|
|
27
|
+
|
|
28
|
+
this.currentVersion = '';
|
|
29
|
+
this.projectAbsolutePath = '';
|
|
30
|
+
this.conn = null;
|
|
31
|
+
this.serverConfig = null;
|
|
32
|
+
|
|
33
|
+
this.outPath = outPathMap[this.projectName][this.env];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @Title: 设置服务器连接配置
|
|
38
|
+
* @Describe:
|
|
39
|
+
* @Author: Zsj
|
|
40
|
+
*/
|
|
41
|
+
setConfig(serverConfig) {
|
|
42
|
+
this.serverConfig = serverConfig;
|
|
43
|
+
return this.serverConfig;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @Title: 发布前检查环境和参数是否正确
|
|
48
|
+
* @Describe:
|
|
49
|
+
* @Author: Zsj
|
|
50
|
+
*/
|
|
51
|
+
async check() {
|
|
52
|
+
const serverConfigMap = await getServerConfig(this.projectName);
|
|
53
|
+
|
|
54
|
+
if (!serverConfigMap) {
|
|
55
|
+
console.log('未找到发布脚本!');
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
cd(this.projectRelativePath);
|
|
60
|
+
|
|
61
|
+
// const path = await $`pwd`;
|
|
62
|
+
|
|
63
|
+
// windows 下有问题
|
|
64
|
+
// this.projectAbsolutePath = path.stdout.replace('\n','');
|
|
65
|
+
|
|
66
|
+
this.projectAbsolutePath = process.cwd();
|
|
67
|
+
|
|
68
|
+
if (!(await isWorkingTreeClean())) {
|
|
69
|
+
console.log('工作区不干净, 请先提交代码');
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let serverConfig = this.setConfig(serverConfigMap[this.env]);
|
|
74
|
+
|
|
75
|
+
if (this.env === 'prod') {
|
|
76
|
+
serverConfig.privateKey = fs.readFileSync(
|
|
77
|
+
path.join(process.env.HOME, '.ssh', 'id_rsa'),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 选择release默认用国内cn服务器
|
|
82
|
+
if (this.env === 'release') {
|
|
83
|
+
serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!serverConfig) {
|
|
87
|
+
console.log('您当前没有权限!');
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log('当前主项目分支', await getGitCurrentBranch());
|
|
92
|
+
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @Title: 更新项目中version 并加入changelog
|
|
98
|
+
* @Describe:
|
|
99
|
+
* @Author: Zsj
|
|
100
|
+
*/
|
|
101
|
+
async updateVersion() {
|
|
102
|
+
if (this.env === 'prod') {
|
|
103
|
+
await $`npm version ${this.version} -m "%s ${this.changelog}"`;
|
|
104
|
+
let { version } = await fs.readJson('./package.json');
|
|
105
|
+
this.currentVersion = version;
|
|
106
|
+
}
|
|
107
|
+
if (this.env !== 'prod') {
|
|
108
|
+
await $`npm version ${this.version} --no-git-tag-version`;
|
|
109
|
+
await $`git add package.json`;
|
|
110
|
+
let { version } = await fs.readJson('./package.json');
|
|
111
|
+
this.currentVersion = version;
|
|
112
|
+
await $`git commit -m "chore: ${this.currentVersion} ${this.changelog}"`;
|
|
113
|
+
}
|
|
114
|
+
return this.currentVersion;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @Title: 根据env执行打包
|
|
119
|
+
* @Describe:
|
|
120
|
+
* @Author: Zsj
|
|
121
|
+
*/
|
|
122
|
+
async build() {
|
|
123
|
+
await $`npm run build:${this.env}`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @Title: 压缩dist文件为zip
|
|
128
|
+
* @Describe:
|
|
129
|
+
* @Author: Zsj
|
|
130
|
+
*/
|
|
131
|
+
async compress() {
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
const __dirname = process.cwd();
|
|
134
|
+
const zipFile = path.resolve(__dirname, `${this.currentVersion}.zip`);
|
|
135
|
+
const originFilePath = path.resolve(__dirname, 'dist');
|
|
136
|
+
const output = fs.createWriteStream(zipFile);
|
|
137
|
+
const archive = archiver('zip', {
|
|
138
|
+
zlib: { level: 9 }, // 设置压缩级别
|
|
139
|
+
});
|
|
140
|
+
archive.on('error', function (err) {
|
|
141
|
+
reject(err);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
output.on('close', function () {
|
|
145
|
+
resolve(true);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
archive.pipe(output);
|
|
149
|
+
|
|
150
|
+
archive.directory(originFilePath, '/dist'); //将srcPath路径对应的内容添加到zip包中/dist路径
|
|
151
|
+
|
|
152
|
+
archive.finalize();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @Title: 连接服务器
|
|
158
|
+
* @Describe:
|
|
159
|
+
* @Author: Zsj
|
|
160
|
+
*/
|
|
161
|
+
async connectServer() {
|
|
162
|
+
if (!this.serverConfig) {
|
|
163
|
+
console.log('未找到发布配置!');
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
this.conn = await connectServer(this.serverConfig);
|
|
167
|
+
return this.conn;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @Title: 本地zip文件上传到服务器
|
|
172
|
+
* @Describe:
|
|
173
|
+
* @Author: Zsj
|
|
174
|
+
*/
|
|
175
|
+
async serverUpload() {
|
|
176
|
+
const localPath = path.resolve(
|
|
177
|
+
this.projectAbsolutePath,
|
|
178
|
+
`${this.currentVersion}.zip`,
|
|
179
|
+
);
|
|
180
|
+
const remotePath = `${this.outPath}/${this.currentVersion}.zip`;
|
|
181
|
+
return await serverUpload(this.conn, { localPath, remotePath });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @Title: 服务器中解压文件
|
|
186
|
+
* @Describe:
|
|
187
|
+
* @Author: Zsj
|
|
188
|
+
*/
|
|
189
|
+
async serverUnpack() {
|
|
190
|
+
return await serverUnpack(this.conn, {
|
|
191
|
+
path: this.outPath,
|
|
192
|
+
fileName: `${this.currentVersion}`,
|
|
193
|
+
fullFileName: `${this.currentVersion}.zip`,
|
|
194
|
+
changelog: this.changelog,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* @Title: 删除本地zip文件
|
|
200
|
+
* @Describe:
|
|
201
|
+
* @Author: Zsj
|
|
202
|
+
*/
|
|
203
|
+
deleteLocalZip() {
|
|
204
|
+
return $`rm -rf ${this.currentVersion}.zip`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @Title: 断开服务连接
|
|
209
|
+
* @Describe:
|
|
210
|
+
* @Author: Zsj
|
|
211
|
+
*/
|
|
212
|
+
async disconnectServer() {
|
|
213
|
+
return await this.conn.end();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export default UploadCode;
|