@pisell/common 0.0.16 → 0.0.17-1

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.
@@ -20,6 +20,8 @@ export declare type PisellConfigType = {
20
20
  remove: RequestMethod;
21
21
  request: RequestMethod;
22
22
  };
23
+ /** 消息通知url */
24
+ webhookUrl?: string;
23
25
  };
24
26
  export interface RequestMethod {
25
27
  <T = any>(url: string, data?: Record<string, any>, config?: any): Promise<T>;
@@ -8,9 +8,9 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
8
8
  import inquirer from 'inquirer';
9
9
  import 'zx/globals';
10
10
  import Release from "../release/release.js";
11
- import { getCurrentProjectName } from "../utils/index.js";
11
+ import { getCurrentProjectName, getCurrentUserName, sendWebhook } from "../utils/index.js";
12
12
  import UploadCode from "./uploadCode.js";
13
-
13
+ // {\"post\":{\"zh_cn\":{\"title\":\"my_pisell_shop release环境开始上传并发布\",\"content\":[[{\"text\":\"发布人:\",\"style\":[\"bold\"]},{\"text\":\"左胜杰\",\"style\":[\"bold\"]}],[{\"text\":\"版本号:\",\"style\":[\"bold\"]},{\"text\":\"1.0.71\",\"style\":[\"bold\"]}]]}}}
14
14
  /**
15
15
  * @Title: 选择器函数
16
16
  * @Describe:
@@ -71,7 +71,7 @@ function init() {
71
71
  }
72
72
  function _init() {
73
73
  _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
74
- var res, uploadCode, version, conn, releaseInstance;
74
+ var res, uploadCode, version, currentUserName, conn, releaseInstance;
75
75
  return _regeneratorRuntime().wrap(function _callee$(_context) {
76
76
  while (1) switch (_context.prev = _context.next) {
77
77
  case 0:
@@ -92,6 +92,8 @@ function _init() {
92
92
  fileName: getCurrentProjectName()
93
93
  };
94
94
 
95
+ // 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`
96
+
95
97
  // 删除本地在远程不存在的tag
96
98
  _context.next = 9;
97
99
  return $(_templateObject || (_templateObject = _taggedTemplateLiteral(["git fetch --prune --prune-tags"])));
@@ -112,34 +114,53 @@ function _init() {
112
114
  case 17:
113
115
  version = _context.sent;
114
116
  console.log('✅ 版本更新完成');
115
- _context.prev = 19;
117
+ _context.next = 21;
118
+ return getCurrentUserName();
119
+ case 21:
120
+ currentUserName = _context.sent;
121
+ _context.next = 24;
122
+ return sendWebhook({
123
+ title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883\u5F00\u59CB").concat(res.is_release ? '上传并发布' : '上传'),
124
+ content: [{
125
+ key: '发布人',
126
+ value: currentUserName.replace('\n', '')
127
+ }, {
128
+ key: '更新内容',
129
+ value: res.changelog
130
+ }, {
131
+ key: '版本号',
132
+ value: version || ''
133
+ }]
134
+ });
135
+ case 24:
136
+ _context.prev = 24;
116
137
  console.log('开始打包');
117
- _context.next = 23;
138
+ _context.next = 28;
118
139
  return uploadCode.build();
119
- case 23:
140
+ case 28:
120
141
  console.log('✅ 打包完成');
121
142
  console.log('开始压缩');
122
- _context.next = 27;
143
+ _context.next = 32;
123
144
  return uploadCode.compress();
124
- case 27:
145
+ case 32:
125
146
  console.log('✅ 压缩完成');
126
147
  console.log('开始连接服务器');
127
- _context.next = 31;
148
+ _context.next = 36;
128
149
  return uploadCode.connectServer();
129
- case 31:
150
+ case 36:
130
151
  conn = _context.sent;
131
152
  console.log('✅ 连接服务器完成');
132
153
  console.log('开始上传');
133
- _context.next = 36;
154
+ _context.next = 41;
134
155
  return uploadCode.serverUpload();
135
- case 36:
156
+ case 41:
136
157
  console.log('✅ 上传完成');
137
158
  console.log('开始解压');
138
- _context.next = 40;
159
+ _context.next = 45;
139
160
  return uploadCode.serverUnpack();
140
- case 40:
161
+ case 45:
141
162
  if (!res.is_release) {
142
- _context.next = 45;
163
+ _context.next = 50;
143
164
  break;
144
165
  }
145
166
  releaseInstance = new Release({
@@ -149,37 +170,67 @@ function _init() {
149
170
  conn: conn
150
171
  });
151
172
  console.log('开始发布');
152
- _context.next = 45;
173
+ _context.next = 50;
153
174
  return releaseInstance.release();
154
- case 45:
155
- _context.next = 47;
175
+ case 50:
176
+ _context.next = 52;
156
177
  return uploadCode.disconnectServer();
157
- case 47:
158
- _context.next = 49;
178
+ case 52:
179
+ _context.next = 54;
159
180
  return $(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["git pull --no-edit"])));
160
- case 49:
161
- _context.next = 51;
181
+ case 54:
182
+ _context.next = 56;
162
183
  return $(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["git push --follow-tags"])));
163
- case 51:
184
+ case 56:
164
185
  console.log('✅ 成功后推送到git');
165
- _context.next = 61;
186
+ _context.next = 68;
166
187
  break;
167
- case 54:
168
- _context.prev = 54;
169
- _context.t0 = _context["catch"](19);
188
+ case 59:
189
+ _context.prev = 59;
190
+ _context.t0 = _context["catch"](24);
170
191
  console.log(_context.t0, '执行出错 请排查重试');
171
- _context.next = 59;
192
+ _context.next = 64;
172
193
  return $(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["git reset HEAD~1"])));
173
- case 59:
174
- _context.next = 61;
194
+ case 64:
195
+ _context.next = 66;
175
196
  return $(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["git tag -d v", ""])), uploadCode.currentVersion);
176
- case 61:
197
+ case 66:
198
+ _context.next = 68;
199
+ return sendWebhook({
200
+ title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u5931\u8D25"),
201
+ content: [{
202
+ key: '发布人',
203
+ value: currentUserName.replace('\n', '')
204
+ }, {
205
+ key: '更新内容',
206
+ value: res.changelog
207
+ }, {
208
+ key: '版本号',
209
+ value: version || ''
210
+ }]
211
+ });
212
+ case 68:
213
+ _context.next = 70;
214
+ return sendWebhook({
215
+ title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u6210\u529F"),
216
+ content: [{
217
+ key: '发布人',
218
+ value: currentUserName.replace('\n', '')
219
+ }, {
220
+ key: '更新内容',
221
+ value: res.changelog
222
+ }, {
223
+ key: '版本号',
224
+ value: version || ''
225
+ }]
226
+ });
227
+ case 70:
177
228
  uploadCode.deleteLocalZip();
178
- case 62:
229
+ case 71:
179
230
  case "end":
180
231
  return _context.stop();
181
232
  }
182
- }, _callee, null, [[19, 54]]);
233
+ }, _callee, null, [[24, 59]]);
183
234
  }));
184
235
  return _init.apply(this, arguments);
185
236
  }
@@ -1,9 +1,10 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- var _templateObject, _templateObject2;
2
+ var _templateObject, _templateObject2, _templateObject3;
3
3
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
4
4
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
5
5
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
6
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
7
+ import * as dotenv from 'dotenv';
7
8
  import ssh2 from 'ssh2';
8
9
 
9
10
  /**
@@ -241,4 +242,79 @@ var getCurrentProjectName = function getCurrentProjectName() {
241
242
  var loadJSON = function loadJSON(path) {
242
243
  return JSON.parse(fs.readFileSync(new URL(path, import.meta.url)));
243
244
  };
244
- export { isWorkingTreeClean, getServerConfig, connectServer, serverUpload, serverUnpack, versionSort, releaseProject, getGitCurrentBranch, getCurrentProjectName, loadJSON };
245
+ var getCurrentUserName = /*#__PURE__*/function () {
246
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
247
+ var _yield, stdout;
248
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
249
+ while (1) switch (_context4.prev = _context4.next) {
250
+ case 0:
251
+ _context4.next = 2;
252
+ return $(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["git config user.name"])));
253
+ case 2:
254
+ _yield = _context4.sent;
255
+ stdout = _yield.stdout;
256
+ return _context4.abrupt("return", stdout);
257
+ case 5:
258
+ case "end":
259
+ return _context4.stop();
260
+ }
261
+ }, _callee4);
262
+ }));
263
+ return function getCurrentUserName() {
264
+ return _ref7.apply(this, arguments);
265
+ };
266
+ }();
267
+ var createFeishuMessageContent = function createFeishuMessageContent(contentArr) {
268
+ return JSON.stringify(contentArr.map(function (item) {
269
+ return [{
270
+ tag: 'text',
271
+ text: "".concat(item.key)
272
+ }, {
273
+ tag: 'text',
274
+ text: "".concat(item.value)
275
+ }];
276
+ }));
277
+ };
278
+ var sendWebhook = /*#__PURE__*/function () {
279
+ var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref8) {
280
+ var _dotenv$config, _dotenv$config$parsed, _dotenv$config2, _dotenv$config2$parse;
281
+ var title, content, contentStr, response;
282
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
283
+ while (1) switch (_context5.prev = _context5.next) {
284
+ case 0:
285
+ title = _ref8.title, content = _ref8.content;
286
+ contentStr = createFeishuMessageContent(content);
287
+ if ((_dotenv$config = dotenv.config()) !== null && _dotenv$config !== void 0 && (_dotenv$config$parsed = _dotenv$config.parsed) !== null && _dotenv$config$parsed !== void 0 && _dotenv$config$parsed.WEBHOOK) {
288
+ _context5.next = 4;
289
+ break;
290
+ }
291
+ return _context5.abrupt("return");
292
+ case 4:
293
+ _context5.next = 6;
294
+ return fetch((_dotenv$config2 = dotenv.config()) === null || _dotenv$config2 === void 0 ? void 0 : (_dotenv$config2$parse = _dotenv$config2.parsed) === null || _dotenv$config2$parse === void 0 ? void 0 : _dotenv$config2$parse.WEBHOOK, {
295
+ headers: {
296
+ 'Content-Type': 'application/json'
297
+ },
298
+ method: 'POST',
299
+ body: JSON.stringify({
300
+ msg_type: 'post',
301
+ content: "{\"post\":{\"zh_cn\":{\"title\":\"".concat(title, "\",\"content\":\"").concat(contentStr, "\"}}}")
302
+ })
303
+ });
304
+ case 6:
305
+ response = _context5.sent;
306
+ _context5.next = 9;
307
+ return response.json();
308
+ case 9:
309
+ return _context5.abrupt("return", _context5.sent);
310
+ case 10:
311
+ case "end":
312
+ return _context5.stop();
313
+ }
314
+ }, _callee5);
315
+ }));
316
+ return function sendWebhook(_x) {
317
+ return _ref9.apply(this, arguments);
318
+ };
319
+ }();
320
+ export { isWorkingTreeClean, getServerConfig, connectServer, serverUpload, serverUnpack, versionSort, releaseProject, getGitCurrentBranch, getCurrentProjectName, loadJSON, getCurrentUserName, sendWebhook };
@@ -20,6 +20,8 @@ export declare type PisellConfigType = {
20
20
  remove: RequestMethod;
21
21
  request: RequestMethod;
22
22
  };
23
+ /** 消息通知url */
24
+ webhookUrl?: string;
23
25
  };
24
26
  export interface RequestMethod {
25
27
  <T = any>(url: string, data?: Record<string, any>, config?: any): Promise<T>;
@@ -108,6 +108,24 @@ async function init() {
108
108
  console.log("开始更新版本号");
109
109
  const version = await uploadCode.updateVersion();
110
110
  console.log("✅ 版本更新完成");
111
+ const currentUserName = await (0, import_utils.getCurrentUserName)();
112
+ await (0, import_utils.sendWebhook)({
113
+ title: `${res.project.fileName} ${res.env}环境开始${res.is_release ? "上传并发布" : "上传"}`,
114
+ content: [
115
+ {
116
+ key: "发布人",
117
+ value: currentUserName.replace("\n", "")
118
+ },
119
+ {
120
+ key: "更新内容",
121
+ value: res.changelog
122
+ },
123
+ {
124
+ key: "版本号",
125
+ value: version || ""
126
+ }
127
+ ]
128
+ });
111
129
  try {
112
130
  console.log("开始打包");
113
131
  await uploadCode.build();
@@ -141,7 +159,41 @@ async function init() {
141
159
  console.log(error, "执行出错 请排查重试");
142
160
  await $`git reset HEAD~1`;
143
161
  await $`git tag -d v${uploadCode.currentVersion}`;
162
+ await (0, import_utils.sendWebhook)({
163
+ title: `${res.project.fileName} ${res.env}环境${res.is_release ? "上传并发布" : "上传"}失败`,
164
+ content: [
165
+ {
166
+ key: "发布人",
167
+ value: currentUserName.replace("\n", "")
168
+ },
169
+ {
170
+ key: "更新内容",
171
+ value: res.changelog
172
+ },
173
+ {
174
+ key: "版本号",
175
+ value: version || ""
176
+ }
177
+ ]
178
+ });
144
179
  }
180
+ await (0, import_utils.sendWebhook)({
181
+ title: `${res.project.fileName} ${res.env}环境${res.is_release ? "上传并发布" : "上传"}成功`,
182
+ content: [
183
+ {
184
+ key: "发布人",
185
+ value: currentUserName.replace("\n", "")
186
+ },
187
+ {
188
+ key: "更新内容",
189
+ value: res.changelog
190
+ },
191
+ {
192
+ key: "版本号",
193
+ value: version || ""
194
+ }
195
+ ]
196
+ });
145
197
  uploadCode.deleteLocalZip();
146
198
  }
147
199
  var uploadCode_default = init;
@@ -31,16 +31,19 @@ var utils_exports = {};
31
31
  __export(utils_exports, {
32
32
  connectServer: () => connectServer,
33
33
  getCurrentProjectName: () => getCurrentProjectName,
34
+ getCurrentUserName: () => getCurrentUserName,
34
35
  getGitCurrentBranch: () => getGitCurrentBranch,
35
36
  getServerConfig: () => getServerConfig,
36
37
  isWorkingTreeClean: () => isWorkingTreeClean,
37
38
  loadJSON: () => loadJSON,
38
39
  releaseProject: () => releaseProject,
40
+ sendWebhook: () => sendWebhook,
39
41
  serverUnpack: () => serverUnpack,
40
42
  serverUpload: () => serverUpload,
41
43
  versionSort: () => versionSort
42
44
  });
43
45
  module.exports = __toCommonJS(utils_exports);
46
+ var dotenv = __toESM(require("dotenv"));
44
47
  var import_ssh2 = __toESM(require("ssh2"));
45
48
  var import_meta = {};
46
49
  var isWorkingTreeClean = async () => {
@@ -54,7 +57,7 @@ var getGitCurrentBranch = async () => {
54
57
  var getServerConfig = async () => {
55
58
  return await fs.readJson("../lm_config.json");
56
59
  };
57
- var connectServer = (config) => {
60
+ var connectServer = (config2) => {
58
61
  const conn = new import_ssh2.default.Client();
59
62
  return new Promise((resolve, reject) => {
60
63
  conn.on("ready", () => {
@@ -62,7 +65,7 @@ var connectServer = (config) => {
62
65
  }).on("error", (err) => {
63
66
  console.log(err, "connect error");
64
67
  reject();
65
- }).connect(config);
68
+ }).connect(config2);
66
69
  });
67
70
  };
68
71
  var serverUpload = (conn, { localPath, remotePath }) => {
@@ -197,15 +200,48 @@ var getCurrentProjectName = () => {
197
200
  return loadJSON(`${process.env.PWD}/package.json`).name;
198
201
  };
199
202
  var loadJSON = (path) => JSON.parse(fs.readFileSync(new URL(path, import_meta.url)));
203
+ var getCurrentUserName = async () => {
204
+ const { stdout } = await $`git config user.name`;
205
+ return stdout;
206
+ };
207
+ var createFeishuMessageContent = (contentArr) => {
208
+ return JSON.stringify(
209
+ contentArr.map((item) => {
210
+ return [
211
+ { tag: "text", text: `${item.key}` },
212
+ { tag: "text", text: `${item.value}` }
213
+ ];
214
+ })
215
+ );
216
+ };
217
+ var sendWebhook = async ({ title, content }) => {
218
+ var _a, _b, _c, _d;
219
+ const contentStr = createFeishuMessageContent(content);
220
+ if (!((_b = (_a = dotenv.config()) == null ? void 0 : _a.parsed) == null ? void 0 : _b.WEBHOOK))
221
+ return;
222
+ const response = await fetch((_d = (_c = dotenv.config()) == null ? void 0 : _c.parsed) == null ? void 0 : _d.WEBHOOK, {
223
+ headers: {
224
+ "Content-Type": "application/json"
225
+ },
226
+ method: "POST",
227
+ body: JSON.stringify({
228
+ msg_type: "post",
229
+ content: `{"post":{"zh_cn":{"title":"${title}","content":"${contentStr}"}}}`
230
+ })
231
+ });
232
+ return await response.json();
233
+ };
200
234
  // Annotate the CommonJS export names for ESM import in node:
201
235
  0 && (module.exports = {
202
236
  connectServer,
203
237
  getCurrentProjectName,
238
+ getCurrentUserName,
204
239
  getGitCurrentBranch,
205
240
  getServerConfig,
206
241
  isWorkingTreeClean,
207
242
  loadJSON,
208
243
  releaseProject,
244
+ sendWebhook,
209
245
  serverUnpack,
210
246
  serverUpload,
211
247
  versionSort
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/common",
3
- "version": "0.0.16",
3
+ "version": "0.0.17-1",
4
4
  "description": "A collection of reusable UI components for web development",
5
5
  "license": "MIT",
6
6
  "sideEffects": [
@@ -61,6 +61,7 @@
61
61
  "antd5": "npm:antd@^5.5.0",
62
62
  "archiver": "^5.3.1",
63
63
  "array-move": "^3.0.1",
64
+ "dotenv": "^16.0.3",
64
65
  "inquirer": "^9.2.6",
65
66
  "react-beautiful-dnd": "^13.1.0",
66
67
  "react-color": "^2.19.3",