@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.
Files changed (247) hide show
  1. package/.fatherrc.ts +7 -0
  2. package/CHANGELOG.md +14 -0
  3. package/README.md +1 -38
  4. package/es/bin/pisell.js +0 -0
  5. package/es/index.d.ts +2 -4
  6. package/es/index.js +1 -4
  7. package/es/script/utils/index.js +1 -1
  8. package/lib/index.d.ts +2 -4
  9. package/lib/index.js +8 -5
  10. package/lib/script/deploy.js +0 -2
  11. package/lib/script/release/index.js +0 -2
  12. package/lib/script/release/release.js +0 -2
  13. package/lib/script/uploadCode/index.js +0 -2
  14. package/lib/script/uploadCode/uploadCode.js +0 -2
  15. package/lib/script/utils/index.js +1 -1
  16. package/package.json +23 -74
  17. package/src/bin/pisell.js +3 -0
  18. package/src/index.ts +1 -0
  19. package/src/script/constants/index.js +14 -0
  20. package/src/script/deploy.js +29 -0
  21. package/src/script/index.js +45 -0
  22. package/src/script/package.json +4 -0
  23. package/src/script/release/index.js +119 -0
  24. package/src/script/release/release.js +84 -0
  25. package/src/script/uploadCode/index.js +244 -0
  26. package/src/script/uploadCode/uploadCode.js +217 -0
  27. package/src/script/utils/index.js +275 -0
  28. package/tsconfig.json +14 -0
  29. package/LICENSE +0 -21
  30. package/es/business-components/colorInput/index.d.ts +0 -21
  31. package/es/business-components/colorInput/index.js +0 -43
  32. package/es/business-components/colorInput/index.less +0 -10
  33. package/es/business-components/index.d.ts +0 -11
  34. package/es/business-components/index.js +0 -7
  35. package/es/business-components/rechargeOption/index.d.ts +0 -36
  36. package/es/business-components/rechargeOption/index.js +0 -132
  37. package/es/business-components/rechargeOption/index.less +0 -0
  38. package/es/business-components/selectTag/index.d.ts +0 -25
  39. package/es/business-components/selectTag/index.js +0 -179
  40. package/es/business-components/selectTag/index.less +0 -22
  41. package/es/business-components/sortModal/index.d.ts +0 -30
  42. package/es/business-components/sortModal/index.js +0 -85
  43. package/es/business-components/sortModal/index.less +0 -29
  44. package/es/business-components/statistics/index.d.ts +0 -12
  45. package/es/business-components/statistics/index.js +0 -38
  46. package/es/business-components/statistics/index.less +0 -64
  47. package/es/business-components/tagModal/index.d.ts +0 -17
  48. package/es/business-components/tagModal/index.js +0 -58
  49. package/es/business-hooks/index.d.ts +0 -2
  50. package/es/business-hooks/index.js +0 -2
  51. package/es/business-hooks/useModal/index.d.ts +0 -31
  52. package/es/business-hooks/useModal/index.js +0 -91
  53. package/es/business-hooks/useModal/index.less +0 -0
  54. package/es/business-hooks/useTagModal/index.d.ts +0 -17
  55. package/es/business-hooks/useTagModal/index.js +0 -47
  56. package/es/components/ColorPicker/index.d.ts +0 -22
  57. package/es/components/ColorPicker/index.js +0 -51
  58. package/es/components/ColorPicker/index.less +0 -17
  59. package/es/components/DragSort/index.js +0 -68
  60. package/es/components/EditorPreview/index.js +0 -14
  61. package/es/components/EditorPreview/index.less +0 -81
  62. package/es/components/Iconfont/index.d.ts +0 -6
  63. package/es/components/Iconfont/index.js +0 -29
  64. package/es/components/Iconfont/index.less +0 -0
  65. package/es/components/agreement/Detail/index.js +0 -77
  66. package/es/components/agreement/Detail/serve.d.ts +0 -1
  67. package/es/components/agreement/Detail/serve.js +0 -6
  68. package/es/components/agreement/index.d.ts +0 -11
  69. package/es/components/agreement/index.js +0 -45
  70. package/es/components/agreement/index.less +0 -20
  71. package/es/components/avatar/index.d.ts +0 -13
  72. package/es/components/avatar/index.js +0 -25
  73. package/es/components/button/index.js +0 -36
  74. package/es/components/card/index.js +0 -16
  75. package/es/components/card/index.less +0 -9
  76. package/es/components/checkbox/index.js +0 -43
  77. package/es/components/configProvider/index.d.ts +0 -113
  78. package/es/components/configProvider/index.js +0 -114
  79. package/es/components/datePicker/index.js +0 -17
  80. package/es/components/index.js +0 -16
  81. package/es/components/input/index.js +0 -97
  82. package/es/components/inputNumber/index.js +0 -17
  83. package/es/components/pagination/index.d.ts +0 -10
  84. package/es/components/pagination/index.js +0 -18
  85. package/es/components/radio/index.js +0 -28
  86. package/es/components/select/index.js +0 -17
  87. package/es/components/switch/index.d.ts +0 -10
  88. package/es/components/switch/index.js +0 -18
  89. package/es/config/index.js +0 -18
  90. package/es/config/request.d.ts +0 -7
  91. package/es/config/request.js +0 -67
  92. package/es/config/utils.d.ts +0 -0
  93. package/es/config/utils.js +0 -0
  94. package/es/hooks/index.d.ts +0 -8
  95. package/es/hooks/index.js +0 -8
  96. package/es/hooks/useCountDown/index.d.ts +0 -10
  97. package/es/hooks/useCountDown/index.js +0 -48
  98. package/es/hooks/useDocumentScroll/index.d.ts +0 -8
  99. package/es/hooks/useDocumentScroll/index.js +0 -41
  100. package/es/hooks/useDocumentScroll/index.less +0 -0
  101. package/es/hooks/useMousemove/index.d.ts +0 -8
  102. package/es/hooks/useMousemove/index.js +0 -61
  103. package/es/hooks/useResponsive/index.d.ts +0 -2
  104. package/es/hooks/useResponsive/index.js +0 -29
  105. package/es/hooks/useResponsive/index.less +0 -0
  106. package/es/hooks/useSize/index.d.ts +0 -2
  107. package/es/hooks/useSize/index.js +0 -27
  108. package/es/hooks/useSize/index.less +0 -0
  109. package/es/hooks/useStateMulti/index.d.ts +0 -2
  110. package/es/hooks/useStateMulti/index.js +0 -29
  111. package/es/hooks/useStateWithCb/index.d.ts +0 -2
  112. package/es/hooks/useStateWithCb/index.js +0 -42
  113. package/es/hooks/useTable/index.d.ts +0 -12
  114. package/es/hooks/useTable/index.js +0 -74
  115. package/es/hooks/useTable/index.less +0 -0
  116. package/es/hooks/useTableModal/index.d.ts +0 -12
  117. package/es/hooks/useTableModal/index.js +0 -25
  118. package/es/hooks/useTableModal/index.less +0 -0
  119. package/es/hooks/useUrlState/index.d.ts +0 -2
  120. package/es/hooks/useUrlState/index.js +0 -56
  121. package/es/hooks/useWebSocket/index.d.ts +0 -13
  122. package/es/hooks/useWebSocket/index.js +0 -121
  123. package/es/locales/en-US.d.ts +0 -11
  124. package/es/locales/en-US.js +0 -10
  125. package/es/locales/index.d.ts +0 -1
  126. package/es/locales/index.js +0 -23
  127. package/es/locales/zh-CN.d.ts +0 -11
  128. package/es/locales/zh-CN.js +0 -10
  129. package/es/locales/zh-TW.d.ts +0 -11
  130. package/es/locales/zh-TW.js +0 -10
  131. package/es/utils/index.d.ts +0 -3
  132. package/es/utils/index.js +0 -3
  133. package/es/utils/otherUtils.d.ts +0 -8
  134. package/es/utils/otherUtils.js +0 -12
  135. package/es/utils/storage.d.ts +0 -30
  136. package/es/utils/storage.js +0 -70
  137. package/es/utils/typeUtils.d.ts +0 -42
  138. package/es/utils/typeUtils.js +0 -86
  139. package/lib/business-components/colorInput/index.d.ts +0 -21
  140. package/lib/business-components/colorInput/index.js +0 -70
  141. package/lib/business-components/colorInput/index.less +0 -10
  142. package/lib/business-components/index.d.ts +0 -11
  143. package/lib/business-components/index.js +0 -54
  144. package/lib/business-components/rechargeOption/index.d.ts +0 -36
  145. package/lib/business-components/rechargeOption/index.js +0 -112
  146. package/lib/business-components/rechargeOption/index.less +0 -0
  147. package/lib/business-components/selectTag/index.d.ts +0 -25
  148. package/lib/business-components/selectTag/index.js +0 -181
  149. package/lib/business-components/selectTag/index.less +0 -22
  150. package/lib/business-components/sortModal/index.d.ts +0 -30
  151. package/lib/business-components/sortModal/index.js +0 -100
  152. package/lib/business-components/sortModal/index.less +0 -29
  153. package/lib/business-components/statistics/index.d.ts +0 -12
  154. package/lib/business-components/statistics/index.js +0 -63
  155. package/lib/business-components/statistics/index.less +0 -64
  156. package/lib/business-components/tagModal/index.d.ts +0 -17
  157. package/lib/business-components/tagModal/index.js +0 -66
  158. package/lib/business-hooks/index.d.ts +0 -2
  159. package/lib/business-hooks/index.js +0 -42
  160. package/lib/business-hooks/useModal/index.d.ts +0 -31
  161. package/lib/business-hooks/useModal/index.js +0 -68
  162. package/lib/business-hooks/useModal/index.less +0 -0
  163. package/lib/business-hooks/useTagModal/index.d.ts +0 -17
  164. package/lib/business-hooks/useTagModal/index.js +0 -61
  165. package/lib/components/ColorPicker/index.d.ts +0 -22
  166. package/lib/components/ColorPicker/index.js +0 -80
  167. package/lib/components/ColorPicker/index.less +0 -17
  168. package/lib/components/DragSort/index.js +0 -101
  169. package/lib/components/EditorPreview/index.js +0 -37
  170. package/lib/components/EditorPreview/index.less +0 -81
  171. package/lib/components/Iconfont/index.d.ts +0 -6
  172. package/lib/components/Iconfont/index.js +0 -48
  173. package/lib/components/Iconfont/index.less +0 -0
  174. package/lib/components/agreement/Detail/index.js +0 -86
  175. package/lib/components/agreement/Detail/serve.d.ts +0 -1
  176. package/lib/components/agreement/Detail/serve.js +0 -30
  177. package/lib/components/agreement/index.d.ts +0 -11
  178. package/lib/components/agreement/index.js +0 -82
  179. package/lib/components/agreement/index.less +0 -20
  180. package/lib/components/avatar/index.d.ts +0 -13
  181. package/lib/components/avatar/index.js +0 -42
  182. package/lib/components/button/index.js +0 -36
  183. package/lib/components/card/index.js +0 -42
  184. package/lib/components/card/index.less +0 -9
  185. package/lib/components/checkbox/index.js +0 -36
  186. package/lib/components/configProvider/index.d.ts +0 -113
  187. package/lib/components/configProvider/index.js +0 -159
  188. package/lib/components/datePicker/index.js +0 -31
  189. package/lib/components/index.js +0 -83
  190. package/lib/components/input/index.js +0 -53
  191. package/lib/components/inputNumber/index.js +0 -31
  192. package/lib/components/pagination/index.d.ts +0 -10
  193. package/lib/components/pagination/index.js +0 -42
  194. package/lib/components/radio/index.js +0 -36
  195. package/lib/components/select/index.js +0 -36
  196. package/lib/components/switch/index.d.ts +0 -10
  197. package/lib/components/switch/index.js +0 -42
  198. package/lib/config/index.js +0 -39
  199. package/lib/config/request.d.ts +0 -7
  200. package/lib/config/request.js +0 -76
  201. package/lib/config/utils.d.ts +0 -0
  202. package/lib/config/utils.js +0 -0
  203. package/lib/hooks/index.d.ts +0 -8
  204. package/lib/hooks/index.js +0 -57
  205. package/lib/hooks/useCountDown/index.d.ts +0 -10
  206. package/lib/hooks/useCountDown/index.js +0 -57
  207. package/lib/hooks/useDocumentScroll/index.d.ts +0 -8
  208. package/lib/hooks/useDocumentScroll/index.js +0 -54
  209. package/lib/hooks/useDocumentScroll/index.less +0 -0
  210. package/lib/hooks/useMousemove/index.d.ts +0 -8
  211. package/lib/hooks/useMousemove/index.js +0 -70
  212. package/lib/hooks/useResponsive/index.d.ts +0 -2
  213. package/lib/hooks/useResponsive/index.js +0 -47
  214. package/lib/hooks/useResponsive/index.less +0 -0
  215. package/lib/hooks/useSize/index.d.ts +0 -2
  216. package/lib/hooks/useSize/index.js +0 -45
  217. package/lib/hooks/useSize/index.less +0 -0
  218. package/lib/hooks/useStateMulti/index.d.ts +0 -2
  219. package/lib/hooks/useStateMulti/index.js +0 -43
  220. package/lib/hooks/useStateWithCb/index.d.ts +0 -2
  221. package/lib/hooks/useStateWithCb/index.js +0 -53
  222. package/lib/hooks/useTable/index.d.ts +0 -12
  223. package/lib/hooks/useTable/index.js +0 -75
  224. package/lib/hooks/useTable/index.less +0 -0
  225. package/lib/hooks/useTableModal/index.d.ts +0 -12
  226. package/lib/hooks/useTableModal/index.js +0 -43
  227. package/lib/hooks/useTableModal/index.less +0 -0
  228. package/lib/hooks/useUrlState/index.d.ts +0 -2
  229. package/lib/hooks/useUrlState/index.js +0 -59
  230. package/lib/hooks/useWebSocket/index.d.ts +0 -13
  231. package/lib/hooks/useWebSocket/index.js +0 -91
  232. package/lib/locales/en-US.d.ts +0 -11
  233. package/lib/locales/en-US.js +0 -36
  234. package/lib/locales/index.d.ts +0 -1
  235. package/lib/locales/index.js +0 -59
  236. package/lib/locales/zh-CN.d.ts +0 -11
  237. package/lib/locales/zh-CN.js +0 -36
  238. package/lib/locales/zh-TW.d.ts +0 -11
  239. package/lib/locales/zh-TW.js +0 -36
  240. package/lib/utils/index.d.ts +0 -3
  241. package/lib/utils/index.js +0 -21
  242. package/lib/utils/otherUtils.d.ts +0 -8
  243. package/lib/utils/otherUtils.js +0 -31
  244. package/lib/utils/storage.d.ts +0 -30
  245. package/lib/utils/storage.js +0 -63
  246. package/lib/utils/typeUtils.d.ts +0 -42
  247. 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;