@pisell/common 0.0.16 → 0.0.17-0
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/es/config/index.d.ts
CHANGED
|
@@ -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, currentUserName, uploadCode, version, conn, releaseInstance;
|
|
75
75
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
76
76
|
while (1) switch (_context.prev = _context.next) {
|
|
77
77
|
case 0:
|
|
@@ -92,54 +92,72 @@ function _init() {
|
|
|
92
92
|
fileName: getCurrentProjectName()
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
//
|
|
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
96
|
_context.next = 9;
|
|
97
|
-
return
|
|
97
|
+
return getCurrentUserName();
|
|
98
98
|
case 9:
|
|
99
|
-
|
|
99
|
+
currentUserName = _context.sent;
|
|
100
100
|
_context.next = 12;
|
|
101
|
-
return
|
|
101
|
+
return sendWebhook({
|
|
102
|
+
title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883\u5F00\u59CB").concat(res.is_release ? '上传并发布' : '上传'),
|
|
103
|
+
content: [{
|
|
104
|
+
key: '发布人',
|
|
105
|
+
value: currentUserName.replace('\n', '')
|
|
106
|
+
}, {
|
|
107
|
+
key: '更新内容',
|
|
108
|
+
value: res.changelog
|
|
109
|
+
}, {
|
|
110
|
+
key: '版本号',
|
|
111
|
+
value: version || ''
|
|
112
|
+
}]
|
|
113
|
+
});
|
|
102
114
|
case 12:
|
|
115
|
+
return _context.abrupt("return");
|
|
116
|
+
case 15:
|
|
117
|
+
uploadCode = new UploadCode(res);
|
|
118
|
+
_context.next = 18;
|
|
119
|
+
return uploadCode.check();
|
|
120
|
+
case 18:
|
|
103
121
|
if (_context.sent) {
|
|
104
|
-
_context.next =
|
|
122
|
+
_context.next = 20;
|
|
105
123
|
break;
|
|
106
124
|
}
|
|
107
125
|
return _context.abrupt("return");
|
|
108
|
-
case
|
|
126
|
+
case 20:
|
|
109
127
|
console.log('开始更新版本号');
|
|
110
|
-
_context.next =
|
|
128
|
+
_context.next = 23;
|
|
111
129
|
return uploadCode.updateVersion();
|
|
112
|
-
case
|
|
130
|
+
case 23:
|
|
113
131
|
version = _context.sent;
|
|
114
132
|
console.log('✅ 版本更新完成');
|
|
115
|
-
_context.prev =
|
|
133
|
+
_context.prev = 25;
|
|
116
134
|
console.log('开始打包');
|
|
117
|
-
_context.next =
|
|
135
|
+
_context.next = 29;
|
|
118
136
|
return uploadCode.build();
|
|
119
|
-
case
|
|
137
|
+
case 29:
|
|
120
138
|
console.log('✅ 打包完成');
|
|
121
139
|
console.log('开始压缩');
|
|
122
|
-
_context.next =
|
|
140
|
+
_context.next = 33;
|
|
123
141
|
return uploadCode.compress();
|
|
124
|
-
case
|
|
142
|
+
case 33:
|
|
125
143
|
console.log('✅ 压缩完成');
|
|
126
144
|
console.log('开始连接服务器');
|
|
127
|
-
_context.next =
|
|
145
|
+
_context.next = 37;
|
|
128
146
|
return uploadCode.connectServer();
|
|
129
|
-
case
|
|
147
|
+
case 37:
|
|
130
148
|
conn = _context.sent;
|
|
131
149
|
console.log('✅ 连接服务器完成');
|
|
132
150
|
console.log('开始上传');
|
|
133
|
-
_context.next =
|
|
151
|
+
_context.next = 42;
|
|
134
152
|
return uploadCode.serverUpload();
|
|
135
|
-
case
|
|
153
|
+
case 42:
|
|
136
154
|
console.log('✅ 上传完成');
|
|
137
155
|
console.log('开始解压');
|
|
138
|
-
_context.next =
|
|
156
|
+
_context.next = 46;
|
|
139
157
|
return uploadCode.serverUnpack();
|
|
140
|
-
case
|
|
158
|
+
case 46:
|
|
141
159
|
if (!res.is_release) {
|
|
142
|
-
_context.next =
|
|
160
|
+
_context.next = 51;
|
|
143
161
|
break;
|
|
144
162
|
}
|
|
145
163
|
releaseInstance = new Release({
|
|
@@ -149,37 +167,67 @@ function _init() {
|
|
|
149
167
|
conn: conn
|
|
150
168
|
});
|
|
151
169
|
console.log('开始发布');
|
|
152
|
-
_context.next =
|
|
170
|
+
_context.next = 51;
|
|
153
171
|
return releaseInstance.release();
|
|
154
|
-
case
|
|
155
|
-
_context.next =
|
|
172
|
+
case 51:
|
|
173
|
+
_context.next = 53;
|
|
156
174
|
return uploadCode.disconnectServer();
|
|
157
|
-
case
|
|
158
|
-
_context.next =
|
|
175
|
+
case 53:
|
|
176
|
+
_context.next = 55;
|
|
159
177
|
return $(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["git pull --no-edit"])));
|
|
160
|
-
case
|
|
161
|
-
_context.next =
|
|
178
|
+
case 55:
|
|
179
|
+
_context.next = 57;
|
|
162
180
|
return $(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["git push --follow-tags"])));
|
|
163
|
-
case
|
|
181
|
+
case 57:
|
|
164
182
|
console.log('✅ 成功后推送到git');
|
|
165
|
-
_context.next =
|
|
183
|
+
_context.next = 69;
|
|
166
184
|
break;
|
|
167
|
-
case
|
|
168
|
-
_context.prev =
|
|
169
|
-
_context.t0 = _context["catch"](
|
|
185
|
+
case 60:
|
|
186
|
+
_context.prev = 60;
|
|
187
|
+
_context.t0 = _context["catch"](25);
|
|
170
188
|
console.log(_context.t0, '执行出错 请排查重试');
|
|
171
|
-
_context.next =
|
|
189
|
+
_context.next = 65;
|
|
172
190
|
return $(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["git reset HEAD~1"])));
|
|
173
|
-
case
|
|
174
|
-
_context.next =
|
|
191
|
+
case 65:
|
|
192
|
+
_context.next = 67;
|
|
175
193
|
return $(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["git tag -d v", ""])), uploadCode.currentVersion);
|
|
176
|
-
case
|
|
194
|
+
case 67:
|
|
195
|
+
_context.next = 69;
|
|
196
|
+
return sendWebhook({
|
|
197
|
+
title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u5931\u8D25"),
|
|
198
|
+
content: [{
|
|
199
|
+
key: '发布人',
|
|
200
|
+
value: currentUserName.replace('\n', '')
|
|
201
|
+
}, {
|
|
202
|
+
key: '更新内容',
|
|
203
|
+
value: res.changelog
|
|
204
|
+
}, {
|
|
205
|
+
key: '版本号',
|
|
206
|
+
value: version || ''
|
|
207
|
+
}]
|
|
208
|
+
});
|
|
209
|
+
case 69:
|
|
210
|
+
_context.next = 71;
|
|
211
|
+
return sendWebhook({
|
|
212
|
+
title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u6210\u529F"),
|
|
213
|
+
content: [{
|
|
214
|
+
key: '发布人',
|
|
215
|
+
value: currentUserName.replace('\n', '')
|
|
216
|
+
}, {
|
|
217
|
+
key: '更新内容',
|
|
218
|
+
value: res.changelog
|
|
219
|
+
}, {
|
|
220
|
+
key: '版本号',
|
|
221
|
+
value: version || ''
|
|
222
|
+
}]
|
|
223
|
+
});
|
|
224
|
+
case 71:
|
|
177
225
|
uploadCode.deleteLocalZip();
|
|
178
|
-
case
|
|
226
|
+
case 72:
|
|
179
227
|
case "end":
|
|
180
228
|
return _context.stop();
|
|
181
229
|
}
|
|
182
|
-
}, _callee, null, [[
|
|
230
|
+
}, _callee, null, [[25, 60]]);
|
|
183
231
|
}));
|
|
184
232
|
return _init.apply(this, arguments);
|
|
185
233
|
}
|
package/es/script/utils/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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';
|
|
9
|
+
import { getConfig } from "../../config/index.js";
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* @Title: 项目工作区是否干净
|
|
@@ -241,4 +243,63 @@ var getCurrentProjectName = function getCurrentProjectName() {
|
|
|
241
243
|
var loadJSON = function loadJSON(path) {
|
|
242
244
|
return JSON.parse(fs.readFileSync(new URL(path, import.meta.url)));
|
|
243
245
|
};
|
|
244
|
-
|
|
246
|
+
var getCurrentUserName = /*#__PURE__*/function () {
|
|
247
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
248
|
+
var _yield, stdout;
|
|
249
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
250
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
251
|
+
case 0:
|
|
252
|
+
_context4.next = 2;
|
|
253
|
+
return $(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["git config user.name"])));
|
|
254
|
+
case 2:
|
|
255
|
+
_yield = _context4.sent;
|
|
256
|
+
stdout = _yield.stdout;
|
|
257
|
+
return _context4.abrupt("return", stdout);
|
|
258
|
+
case 5:
|
|
259
|
+
case "end":
|
|
260
|
+
return _context4.stop();
|
|
261
|
+
}
|
|
262
|
+
}, _callee4);
|
|
263
|
+
}));
|
|
264
|
+
return function getCurrentUserName() {
|
|
265
|
+
return _ref7.apply(this, arguments);
|
|
266
|
+
};
|
|
267
|
+
}();
|
|
268
|
+
var createFeishuMessageContent = function createFeishuMessageContent(contentArr) {
|
|
269
|
+
return JSON.stringify(contentArr.map(function (item) {
|
|
270
|
+
return [{
|
|
271
|
+
tag: 'text',
|
|
272
|
+
text: "".concat(item.key)
|
|
273
|
+
}, {
|
|
274
|
+
tag: 'text',
|
|
275
|
+
text: "".concat(item.value)
|
|
276
|
+
}];
|
|
277
|
+
}));
|
|
278
|
+
};
|
|
279
|
+
var sendWebhook = /*#__PURE__*/function () {
|
|
280
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(title, contentArr) {
|
|
281
|
+
var _dotenv$config;
|
|
282
|
+
var contentStr, response;
|
|
283
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
284
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
285
|
+
case 0:
|
|
286
|
+
contentStr = createFeishuMessageContent(contentArr);
|
|
287
|
+
console.log((_dotenv$config = dotenv.config()) === null || _dotenv$config === void 0 ? void 0 : _dotenv$config.webhook, title, contentStr, 'contentStr');
|
|
288
|
+
return _context5.abrupt("return");
|
|
289
|
+
case 5:
|
|
290
|
+
response = _context5.sent;
|
|
291
|
+
_context5.next = 8;
|
|
292
|
+
return response.json();
|
|
293
|
+
case 8:
|
|
294
|
+
return _context5.abrupt("return", _context5.sent);
|
|
295
|
+
case 9:
|
|
296
|
+
case "end":
|
|
297
|
+
return _context5.stop();
|
|
298
|
+
}
|
|
299
|
+
}, _callee5);
|
|
300
|
+
}));
|
|
301
|
+
return function sendWebhook(_x, _x2) {
|
|
302
|
+
return _ref8.apply(this, arguments);
|
|
303
|
+
};
|
|
304
|
+
}();
|
|
305
|
+
export { isWorkingTreeClean, getServerConfig, connectServer, serverUpload, serverUnpack, versionSort, releaseProject, getGitCurrentBranch, getCurrentProjectName, loadJSON, getCurrentUserName, sendWebhook };
|
package/lib/config/index.d.ts
CHANGED
|
@@ -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>;
|
|
@@ -100,6 +100,25 @@ async function init() {
|
|
|
100
100
|
path: "./",
|
|
101
101
|
fileName: (0, import_utils.getCurrentProjectName)()
|
|
102
102
|
};
|
|
103
|
+
const currentUserName = await (0, import_utils.getCurrentUserName)();
|
|
104
|
+
await (0, import_utils.sendWebhook)({
|
|
105
|
+
title: `${res.project.fileName} ${res.env}环境开始${res.is_release ? "上传并发布" : "上传"}`,
|
|
106
|
+
content: [
|
|
107
|
+
{
|
|
108
|
+
key: "发布人",
|
|
109
|
+
value: currentUserName.replace("\n", "")
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
key: "更新内容",
|
|
113
|
+
value: res.changelog
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
key: "版本号",
|
|
117
|
+
value: version || ""
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
103
122
|
await $`git fetch --prune --prune-tags`;
|
|
104
123
|
const uploadCode = new import_uploadCode.default(res);
|
|
105
124
|
if (!await uploadCode.check()) {
|
|
@@ -141,7 +160,41 @@ async function init() {
|
|
|
141
160
|
console.log(error, "执行出错 请排查重试");
|
|
142
161
|
await $`git reset HEAD~1`;
|
|
143
162
|
await $`git tag -d v${uploadCode.currentVersion}`;
|
|
163
|
+
await (0, import_utils.sendWebhook)({
|
|
164
|
+
title: `${res.project.fileName} ${res.env}环境${res.is_release ? "上传并发布" : "上传"}失败`,
|
|
165
|
+
content: [
|
|
166
|
+
{
|
|
167
|
+
key: "发布人",
|
|
168
|
+
value: currentUserName.replace("\n", "")
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
key: "更新内容",
|
|
172
|
+
value: res.changelog
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
key: "版本号",
|
|
176
|
+
value: version || ""
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
});
|
|
144
180
|
}
|
|
181
|
+
await (0, import_utils.sendWebhook)({
|
|
182
|
+
title: `${res.project.fileName} ${res.env}环境${res.is_release ? "上传并发布" : "上传"}成功`,
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
key: "发布人",
|
|
186
|
+
value: currentUserName.replace("\n", "")
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
key: "更新内容",
|
|
190
|
+
value: res.changelog
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
key: "版本号",
|
|
194
|
+
value: version || ""
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
});
|
|
145
198
|
uploadCode.deleteLocalZip();
|
|
146
199
|
}
|
|
147
200
|
var uploadCode_default = init;
|
|
@@ -31,17 +31,21 @@ 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"));
|
|
48
|
+
var import_config = require("../../config/index.js");
|
|
45
49
|
var import_meta = {};
|
|
46
50
|
var isWorkingTreeClean = async () => {
|
|
47
51
|
const v = await $`git status --porcelain`;
|
|
@@ -54,7 +58,7 @@ var getGitCurrentBranch = async () => {
|
|
|
54
58
|
var getServerConfig = async () => {
|
|
55
59
|
return await fs.readJson("../lm_config.json");
|
|
56
60
|
};
|
|
57
|
-
var connectServer = (
|
|
61
|
+
var connectServer = (config2) => {
|
|
58
62
|
const conn = new import_ssh2.default.Client();
|
|
59
63
|
return new Promise((resolve, reject) => {
|
|
60
64
|
conn.on("ready", () => {
|
|
@@ -62,7 +66,7 @@ var connectServer = (config) => {
|
|
|
62
66
|
}).on("error", (err) => {
|
|
63
67
|
console.log(err, "connect error");
|
|
64
68
|
reject();
|
|
65
|
-
}).connect(
|
|
69
|
+
}).connect(config2);
|
|
66
70
|
});
|
|
67
71
|
};
|
|
68
72
|
var serverUpload = (conn, { localPath, remotePath }) => {
|
|
@@ -197,15 +201,48 @@ var getCurrentProjectName = () => {
|
|
|
197
201
|
return loadJSON(`${process.env.PWD}/package.json`).name;
|
|
198
202
|
};
|
|
199
203
|
var loadJSON = (path) => JSON.parse(fs.readFileSync(new URL(path, import_meta.url)));
|
|
204
|
+
var getCurrentUserName = async () => {
|
|
205
|
+
const { stdout } = await $`git config user.name`;
|
|
206
|
+
return stdout;
|
|
207
|
+
};
|
|
208
|
+
var createFeishuMessageContent = (contentArr) => {
|
|
209
|
+
return JSON.stringify(
|
|
210
|
+
contentArr.map((item) => {
|
|
211
|
+
return [
|
|
212
|
+
{ tag: "text", text: `${item.key}` },
|
|
213
|
+
{ tag: "text", text: `${item.value}` }
|
|
214
|
+
];
|
|
215
|
+
})
|
|
216
|
+
);
|
|
217
|
+
};
|
|
218
|
+
var sendWebhook = async (title, contentArr) => {
|
|
219
|
+
var _a;
|
|
220
|
+
const contentStr = createFeishuMessageContent(contentArr);
|
|
221
|
+
console.log((_a = dotenv.config()) == null ? void 0 : _a.webhook, title, contentStr, "contentStr");
|
|
222
|
+
return;
|
|
223
|
+
const response = await fetch((0, import_config.getConfig)().webhookUrl, {
|
|
224
|
+
headers: {
|
|
225
|
+
"Content-Type": "application/json"
|
|
226
|
+
},
|
|
227
|
+
method: "POST",
|
|
228
|
+
body: JSON.stringify({
|
|
229
|
+
msg_type: "post",
|
|
230
|
+
content: `{"post":{"zh_cn":{"title":"${title}","content":"${contentStr}"}}}`
|
|
231
|
+
})
|
|
232
|
+
});
|
|
233
|
+
return await response.json();
|
|
234
|
+
};
|
|
200
235
|
// Annotate the CommonJS export names for ESM import in node:
|
|
201
236
|
0 && (module.exports = {
|
|
202
237
|
connectServer,
|
|
203
238
|
getCurrentProjectName,
|
|
239
|
+
getCurrentUserName,
|
|
204
240
|
getGitCurrentBranch,
|
|
205
241
|
getServerConfig,
|
|
206
242
|
isWorkingTreeClean,
|
|
207
243
|
loadJSON,
|
|
208
244
|
releaseProject,
|
|
245
|
+
sendWebhook,
|
|
209
246
|
serverUnpack,
|
|
210
247
|
serverUpload,
|
|
211
248
|
versionSort
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pisell/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17-0",
|
|
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",
|