@pisell/common 1.0.18 → 1.0.20
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/CHANGELOG.md +14 -0
- package/es/index.d.ts +0 -1
- package/es/script/aws/index.js +218 -0
- package/es/script/constants/index.js +19 -2
- package/es/script/release/release.js +5 -2
- package/es/script/uploadCode/index.js +69 -33
- package/es/script/uploadCode/uploadCode.js +7 -2
- package/es/script/utils/index.js +58 -3
- package/lib/index.d.ts +0 -1
- package/lib/script/aws/index.js +125 -0
- package/lib/script/constants/index.js +27 -1
- package/lib/script/release/release.js +3 -1
- package/lib/script/uploadCode/index.js +27 -3
- package/lib/script/uploadCode/uploadCode.js +2 -3
- package/lib/script/utils/index.js +39 -1
- package/package.json +5 -2
- package/src/script/aws/index.js +138 -0
- package/src/script/constants/index.js +26 -2
- package/src/script/release/release.js +4 -1
- package/src/script/uploadCode/index.js +30 -3
- package/src/script/uploadCode/uploadCode.js +7 -4
- package/src/script/utils/index.js +46 -1
- package/es/index.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @pisell/common
|
|
2
2
|
|
|
3
|
+
## 1.0.20
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [d000328]
|
|
8
|
+
- @pisell/utils@1.0.21
|
|
9
|
+
|
|
10
|
+
## 1.0.19
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [b879dad]
|
|
15
|
+
- @pisell/utils@1.0.20
|
|
16
|
+
|
|
3
17
|
## 1.0.18
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/es/index.d.ts
CHANGED
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
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; }
|
|
6
|
+
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); } }
|
|
7
|
+
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); }); }; }
|
|
8
|
+
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import mime from 'mime-types';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import { getServerConfig } from "../utils/index.js";
|
|
13
|
+
var filterFiles = ['index.html', 'umi.server.js', 'umi.server.d.ts'];
|
|
14
|
+
var __dirname = process.cwd();
|
|
15
|
+
var s3Client = null;
|
|
16
|
+
var bucketName = '';
|
|
17
|
+
|
|
18
|
+
/*******
|
|
19
|
+
* @title: 初始化
|
|
20
|
+
* @description:
|
|
21
|
+
* @return {*}
|
|
22
|
+
* @Author: zhiwei.Wang
|
|
23
|
+
* @Date: 2023-11-24 14:05
|
|
24
|
+
*/
|
|
25
|
+
var init = /*#__PURE__*/function () {
|
|
26
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
27
|
+
var serverConfig, awsConfig;
|
|
28
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
29
|
+
while (1) switch (_context.prev = _context.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
_context.prev = 0;
|
|
32
|
+
_context.next = 3;
|
|
33
|
+
return getServerConfig('admin');
|
|
34
|
+
case 3:
|
|
35
|
+
serverConfig = _context.sent;
|
|
36
|
+
// aws配置
|
|
37
|
+
awsConfig = serverConfig.aws;
|
|
38
|
+
if (!awsConfig) {
|
|
39
|
+
_context.next = 12;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
bucketName = awsConfig.bucketName;
|
|
43
|
+
|
|
44
|
+
// 创建实例
|
|
45
|
+
s3Client = new S3Client({
|
|
46
|
+
region: awsConfig.region,
|
|
47
|
+
credentials: {
|
|
48
|
+
accessKeyId: awsConfig.accessKeyId,
|
|
49
|
+
secretAccessKey: awsConfig.secretAccessKey
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
console.log('aws 初始化成功');
|
|
53
|
+
return _context.abrupt("return", serverConfig.aws);
|
|
54
|
+
case 12:
|
|
55
|
+
console.log('未获取到aws权限');
|
|
56
|
+
return _context.abrupt("return", false);
|
|
57
|
+
case 14:
|
|
58
|
+
_context.next = 20;
|
|
59
|
+
break;
|
|
60
|
+
case 16:
|
|
61
|
+
_context.prev = 16;
|
|
62
|
+
_context.t0 = _context["catch"](0);
|
|
63
|
+
console.log(_context.t0);
|
|
64
|
+
return _context.abrupt("return", false);
|
|
65
|
+
case 20:
|
|
66
|
+
case "end":
|
|
67
|
+
return _context.stop();
|
|
68
|
+
}
|
|
69
|
+
}, _callee, null, [[0, 16]]);
|
|
70
|
+
}));
|
|
71
|
+
return function init() {
|
|
72
|
+
return _ref.apply(this, arguments);
|
|
73
|
+
};
|
|
74
|
+
}();
|
|
75
|
+
|
|
76
|
+
// 上传文件到S3指定目录
|
|
77
|
+
var uploadFile = /*#__PURE__*/function () {
|
|
78
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(directory, fileKey, filePath) {
|
|
79
|
+
var fileStream, contentType, uploadParams, command, response;
|
|
80
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
81
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
82
|
+
case 0:
|
|
83
|
+
fileStream = fs.createReadStream(filePath); // 根据文件扩展名获取MIME类型
|
|
84
|
+
contentType = mime.lookup(filePath);
|
|
85
|
+
uploadParams = {
|
|
86
|
+
Bucket: bucketName,
|
|
87
|
+
Key: "".concat(directory, "/").concat(fileKey),
|
|
88
|
+
// 指定目录路径
|
|
89
|
+
Body: fileStream,
|
|
90
|
+
ContentType: contentType,
|
|
91
|
+
ContentDisposition: 'inline',
|
|
92
|
+
ACL: 'public-read' // 设置ACL权限为公共读取
|
|
93
|
+
};
|
|
94
|
+
command = new PutObjectCommand(uploadParams);
|
|
95
|
+
_context2.prev = 4;
|
|
96
|
+
_context2.next = 7;
|
|
97
|
+
return s3Client.send(command);
|
|
98
|
+
case 7:
|
|
99
|
+
response = _context2.sent;
|
|
100
|
+
console.log("\u4E0A\u4F20\u6210\u529F: ".concat(fileKey));
|
|
101
|
+
return _context2.abrupt("return", {
|
|
102
|
+
fileName: fileKey,
|
|
103
|
+
location: response.Location
|
|
104
|
+
});
|
|
105
|
+
case 12:
|
|
106
|
+
_context2.prev = 12;
|
|
107
|
+
_context2.t0 = _context2["catch"](4);
|
|
108
|
+
console.error("\u4E0A\u4F20\u5931\u8D25: ".concat(fileKey), _context2.t0);
|
|
109
|
+
throw new Error("\u4E0A\u4F20\u5931\u8D25: ".concat(fileKey, ", ").concat(_context2.t0.message));
|
|
110
|
+
case 16:
|
|
111
|
+
case "end":
|
|
112
|
+
return _context2.stop();
|
|
113
|
+
}
|
|
114
|
+
}, _callee2, null, [[4, 12]]);
|
|
115
|
+
}));
|
|
116
|
+
return function uploadFile(_x, _x2, _x3) {
|
|
117
|
+
return _ref2.apply(this, arguments);
|
|
118
|
+
};
|
|
119
|
+
}();
|
|
120
|
+
|
|
121
|
+
/*******
|
|
122
|
+
* @title: 递归上传文件夹内容
|
|
123
|
+
* @description:
|
|
124
|
+
* @return {*}
|
|
125
|
+
* @Author: zhiwei.Wang
|
|
126
|
+
* @Date: 2023-11-24 14:06
|
|
127
|
+
*/
|
|
128
|
+
export var uploadFolderContents = /*#__PURE__*/function () {
|
|
129
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(directory) {
|
|
130
|
+
var folderPath,
|
|
131
|
+
files,
|
|
132
|
+
uploadPromises,
|
|
133
|
+
_iterator,
|
|
134
|
+
_step,
|
|
135
|
+
file,
|
|
136
|
+
filePath,
|
|
137
|
+
fileStats,
|
|
138
|
+
fileKey,
|
|
139
|
+
uploadPromise,
|
|
140
|
+
subDirectory,
|
|
141
|
+
subFolderPromise,
|
|
142
|
+
_args3 = arguments;
|
|
143
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
144
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
145
|
+
case 0:
|
|
146
|
+
folderPath = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : path.resolve(__dirname, 'dist');
|
|
147
|
+
files = fs.readdirSync(folderPath); // promise all 储存
|
|
148
|
+
uploadPromises = [];
|
|
149
|
+
_iterator = _createForOfIteratorHelper(files);
|
|
150
|
+
try {
|
|
151
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
152
|
+
file = _step.value;
|
|
153
|
+
filePath = path.join(folderPath, file);
|
|
154
|
+
fileStats = fs.statSync(filePath); // 文件上传, 文件夹递归循环
|
|
155
|
+
if (fileStats.isFile()) {
|
|
156
|
+
fileKey = path.relative(folderPath, filePath); // 过滤不需要上传的文件
|
|
157
|
+
if (!filterFiles.includes(fileKey)) {
|
|
158
|
+
uploadPromise = uploadFile(directory, fileKey, filePath);
|
|
159
|
+
uploadPromises.push(uploadPromise);
|
|
160
|
+
}
|
|
161
|
+
// 文件夹
|
|
162
|
+
} else if (fileStats.isDirectory()) {
|
|
163
|
+
subDirectory = path.join(directory, file);
|
|
164
|
+
subFolderPromise = uploadFolderContents(subDirectory, filePath);
|
|
165
|
+
uploadPromises.push(subFolderPromise);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
} catch (err) {
|
|
169
|
+
_iterator.e(err);
|
|
170
|
+
} finally {
|
|
171
|
+
_iterator.f();
|
|
172
|
+
}
|
|
173
|
+
return _context3.abrupt("return", Promise.all(uploadPromises).then(function (res) {
|
|
174
|
+
console.log('全部上传完成', res.length);
|
|
175
|
+
return res;
|
|
176
|
+
}).catch(function (err) {
|
|
177
|
+
throw new Error("\u4E0A\u4F20cdn\u5931\u8D25: ".concat(err.message));
|
|
178
|
+
}));
|
|
179
|
+
case 6:
|
|
180
|
+
case "end":
|
|
181
|
+
return _context3.stop();
|
|
182
|
+
}
|
|
183
|
+
}, _callee3);
|
|
184
|
+
}));
|
|
185
|
+
return function uploadFolderContents(_x4) {
|
|
186
|
+
return _ref3.apply(this, arguments);
|
|
187
|
+
};
|
|
188
|
+
}();
|
|
189
|
+
|
|
190
|
+
/*******
|
|
191
|
+
* @title: 上传资源到oss
|
|
192
|
+
* @description:
|
|
193
|
+
* @return {*}
|
|
194
|
+
* @Author: zhiwei.Wang
|
|
195
|
+
* @Date: 2023-11-24 14:04
|
|
196
|
+
*/
|
|
197
|
+
export var uploadStaticToOSS = /*#__PURE__*/function () {
|
|
198
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(directory) {
|
|
199
|
+
var folderPath,
|
|
200
|
+
_args4 = arguments;
|
|
201
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
202
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
203
|
+
case 0:
|
|
204
|
+
folderPath = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : path.resolve(__dirname, 'dist');
|
|
205
|
+
_context4.next = 3;
|
|
206
|
+
return init();
|
|
207
|
+
case 3:
|
|
208
|
+
return _context4.abrupt("return", uploadFolderContents(directory, folderPath));
|
|
209
|
+
case 4:
|
|
210
|
+
case "end":
|
|
211
|
+
return _context4.stop();
|
|
212
|
+
}
|
|
213
|
+
}, _callee4);
|
|
214
|
+
}));
|
|
215
|
+
return function uploadStaticToOSS(_x5) {
|
|
216
|
+
return _ref4.apply(this, arguments);
|
|
217
|
+
};
|
|
218
|
+
}();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var outPathMap = {
|
|
2
2
|
my_pisel_shop: {
|
|
3
|
-
prod: '../data/release/project/
|
|
3
|
+
prod: '../data/release/project/my_pisel_shop',
|
|
4
4
|
release: '../data/release/project/my_pisel_shop',
|
|
5
5
|
pre: '../data/release/project/my_pisel_shop'
|
|
6
6
|
},
|
|
@@ -8,6 +8,23 @@ var outPathMap = {
|
|
|
8
8
|
prod: '../../data/project/pisell2',
|
|
9
9
|
release: '../data/release/project/pisell_v2',
|
|
10
10
|
pre: '../data/release/project/pisell_v2'
|
|
11
|
+
},
|
|
12
|
+
my_pisel_pc_v2: {
|
|
13
|
+
prod: '../data/release/project/my_pisel_pc_v2',
|
|
14
|
+
release: '../data/release/project/my_pisel_pc_v2',
|
|
15
|
+
pre: '../data/release/project/my_pisel_pc_v2'
|
|
16
|
+
},
|
|
17
|
+
my_pisel_h5_v2: {
|
|
18
|
+
prod: '../data/release/project/my_pisel_h5_v2',
|
|
19
|
+
release: '../data/release/project/my_pisel_h5_v2',
|
|
20
|
+
pre: '../data/release/project/my_pisel_h5_v2'
|
|
11
21
|
}
|
|
12
22
|
};
|
|
13
|
-
|
|
23
|
+
var isSsrMap = {
|
|
24
|
+
my_pisel_shop: false,
|
|
25
|
+
admin: false,
|
|
26
|
+
my_pisel_pc_v2: true,
|
|
27
|
+
my_pisel_h5_v2: true
|
|
28
|
+
};
|
|
29
|
+
var checkPackages = ['@pisell/date-picker', '@pisell/lowcode-renderer', '@pisell/common', '@pisell/utils'];
|
|
30
|
+
export { outPathMap, isSsrMap, checkPackages };
|
|
@@ -7,7 +7,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
7
7
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
8
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
9
9
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
|
-
import { outPathMap } from "../constants/index.js";
|
|
10
|
+
import { isSsrMap, outPathMap } from "../constants/index.js";
|
|
11
11
|
import { connectServer as _connectServer, getServerConfig, releaseProject } from "../utils/index.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -27,6 +27,8 @@ var Release = /*#__PURE__*/function () {
|
|
|
27
27
|
this.version = version;
|
|
28
28
|
this.conn = conn;
|
|
29
29
|
this.outPath = outPathMap[this.projectName][this.env];
|
|
30
|
+
// 是否是ssr项目
|
|
31
|
+
this.isSSR = isSsrMap[this.projectName];
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
/**
|
|
@@ -115,7 +117,8 @@ var Release = /*#__PURE__*/function () {
|
|
|
115
117
|
_context3.next = 2;
|
|
116
118
|
return releaseProject(this.conn, {
|
|
117
119
|
path: this.outPath,
|
|
118
|
-
fileName: "".concat(this.version)
|
|
120
|
+
fileName: "".concat(this.version),
|
|
121
|
+
isSSR: this.isSSR
|
|
119
122
|
});
|
|
120
123
|
case 2:
|
|
121
124
|
return _context3.abrupt("return", _context3.sent);
|
|
@@ -7,6 +7,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
7
7
|
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); }); }; }
|
|
8
8
|
import inquirer from 'inquirer';
|
|
9
9
|
import 'zx/globals';
|
|
10
|
+
import { uploadStaticToOSS } from "../aws/index.js";
|
|
10
11
|
import Release from "../release/release.js";
|
|
11
12
|
import { getCurrentProjectName, getCurrentUserName, sendWebhook } from "../utils/index.js";
|
|
12
13
|
import UploadCode from "./uploadCode.js";
|
|
@@ -59,6 +60,17 @@ var inquirerResult = function inquirerResult() {
|
|
|
59
60
|
value: false,
|
|
60
61
|
name: '只上传'
|
|
61
62
|
}]
|
|
63
|
+
}, {
|
|
64
|
+
type: 'list',
|
|
65
|
+
message: '是否执行build打包',
|
|
66
|
+
name: 'whether_build',
|
|
67
|
+
choices: [{
|
|
68
|
+
value: true,
|
|
69
|
+
name: '执行打包'
|
|
70
|
+
}, {
|
|
71
|
+
value: false,
|
|
72
|
+
name: '不执行打包,使用项目根目录/dist文件夹'
|
|
73
|
+
}]
|
|
62
74
|
}, {
|
|
63
75
|
type: 'confirm',
|
|
64
76
|
message: '确认信息无误',
|
|
@@ -71,7 +83,7 @@ function init() {
|
|
|
71
83
|
}
|
|
72
84
|
function _init() {
|
|
73
85
|
_init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
74
|
-
var res, uploadCode, version, currentUserName, result, conn, releaseInstance;
|
|
86
|
+
var res, uploadCode, version, currentUserName, result, _fileName, conn, releaseInstance;
|
|
75
87
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
76
88
|
while (1) switch (_context.prev = _context.next) {
|
|
77
89
|
case 0:
|
|
@@ -136,33 +148,57 @@ function _init() {
|
|
|
136
148
|
result = _context.sent;
|
|
137
149
|
console.log(result, 'result');
|
|
138
150
|
_context.prev = 26;
|
|
151
|
+
if (!res.whether_build) {
|
|
152
|
+
_context.next = 34;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
139
155
|
console.log('开始打包');
|
|
140
|
-
_context.next =
|
|
156
|
+
_context.next = 31;
|
|
141
157
|
return uploadCode.build();
|
|
142
|
-
case
|
|
158
|
+
case 31:
|
|
143
159
|
console.log('✅ 打包完成');
|
|
160
|
+
_context.next = 35;
|
|
161
|
+
break;
|
|
162
|
+
case 34:
|
|
163
|
+
console.log('使用本地/dist');
|
|
164
|
+
case 35:
|
|
165
|
+
if (!(res.env === 'prod')) {
|
|
166
|
+
_context.next = 41;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
_fileName = res.project.fileName;
|
|
170
|
+
if (res.env === 'pre') {
|
|
171
|
+
_fileName = 'pre_' + _fileName;
|
|
172
|
+
}
|
|
173
|
+
if (_fileName === 'admin') {
|
|
174
|
+
_fileName = 'my_pisell_v2';
|
|
175
|
+
}
|
|
176
|
+
// 上传oss
|
|
177
|
+
_context.next = 41;
|
|
178
|
+
return uploadStaticToOSS(_fileName);
|
|
179
|
+
case 41:
|
|
144
180
|
console.log('开始压缩');
|
|
145
|
-
_context.next =
|
|
181
|
+
_context.next = 44;
|
|
146
182
|
return uploadCode.compress();
|
|
147
|
-
case
|
|
183
|
+
case 44:
|
|
148
184
|
console.log('✅ 压缩完成');
|
|
149
185
|
console.log('开始连接服务器');
|
|
150
|
-
_context.next =
|
|
186
|
+
_context.next = 48;
|
|
151
187
|
return uploadCode.connectServer();
|
|
152
|
-
case
|
|
188
|
+
case 48:
|
|
153
189
|
conn = _context.sent;
|
|
154
190
|
console.log('✅ 连接服务器完成');
|
|
155
191
|
console.log('开始上传');
|
|
156
|
-
_context.next =
|
|
192
|
+
_context.next = 53;
|
|
157
193
|
return uploadCode.serverUpload();
|
|
158
|
-
case
|
|
194
|
+
case 53:
|
|
159
195
|
console.log('✅ 上传完成');
|
|
160
196
|
console.log('开始解压');
|
|
161
|
-
_context.next =
|
|
197
|
+
_context.next = 57;
|
|
162
198
|
return uploadCode.serverUnpack();
|
|
163
|
-
case
|
|
199
|
+
case 57:
|
|
164
200
|
if (!res.is_release) {
|
|
165
|
-
_context.next =
|
|
201
|
+
_context.next = 62;
|
|
166
202
|
break;
|
|
167
203
|
}
|
|
168
204
|
releaseInstance = new Release({
|
|
@@ -172,32 +208,32 @@ function _init() {
|
|
|
172
208
|
conn: conn
|
|
173
209
|
});
|
|
174
210
|
console.log('开始发布');
|
|
175
|
-
_context.next =
|
|
211
|
+
_context.next = 62;
|
|
176
212
|
return releaseInstance.release();
|
|
177
|
-
case
|
|
178
|
-
_context.next =
|
|
213
|
+
case 62:
|
|
214
|
+
_context.next = 64;
|
|
179
215
|
return uploadCode.disconnectServer();
|
|
180
|
-
case
|
|
181
|
-
_context.next =
|
|
216
|
+
case 64:
|
|
217
|
+
_context.next = 66;
|
|
182
218
|
return $(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["git pull --no-edit"])));
|
|
183
|
-
case
|
|
184
|
-
_context.next =
|
|
219
|
+
case 66:
|
|
220
|
+
_context.next = 68;
|
|
185
221
|
return $(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["git push --follow-tags"])));
|
|
186
|
-
case
|
|
222
|
+
case 68:
|
|
187
223
|
console.log('✅ 成功后推送到git');
|
|
188
|
-
_context.next =
|
|
224
|
+
_context.next = 80;
|
|
189
225
|
break;
|
|
190
|
-
case
|
|
191
|
-
_context.prev =
|
|
226
|
+
case 71:
|
|
227
|
+
_context.prev = 71;
|
|
192
228
|
_context.t0 = _context["catch"](26);
|
|
193
229
|
console.log(_context.t0, '执行出错 请排查重试');
|
|
194
|
-
_context.next =
|
|
230
|
+
_context.next = 76;
|
|
195
231
|
return $(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["git reset HEAD~1"])));
|
|
196
|
-
case
|
|
197
|
-
_context.next =
|
|
232
|
+
case 76:
|
|
233
|
+
_context.next = 78;
|
|
198
234
|
return $(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["git tag -d v", ""])), uploadCode.currentVersion);
|
|
199
|
-
case
|
|
200
|
-
_context.next =
|
|
235
|
+
case 78:
|
|
236
|
+
_context.next = 80;
|
|
201
237
|
return sendWebhook({
|
|
202
238
|
title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u5931\u8D25"),
|
|
203
239
|
content: [{
|
|
@@ -211,8 +247,8 @@ function _init() {
|
|
|
211
247
|
value: version || ''
|
|
212
248
|
}]
|
|
213
249
|
});
|
|
214
|
-
case
|
|
215
|
-
_context.next =
|
|
250
|
+
case 80:
|
|
251
|
+
_context.next = 82;
|
|
216
252
|
return sendWebhook({
|
|
217
253
|
title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u6210\u529F"),
|
|
218
254
|
content: [{
|
|
@@ -226,13 +262,13 @@ function _init() {
|
|
|
226
262
|
value: version || ''
|
|
227
263
|
}]
|
|
228
264
|
});
|
|
229
|
-
case
|
|
265
|
+
case 82:
|
|
230
266
|
uploadCode.deleteLocalZip();
|
|
231
|
-
case
|
|
267
|
+
case 83:
|
|
232
268
|
case "end":
|
|
233
269
|
return _context.stop();
|
|
234
270
|
}
|
|
235
|
-
}, _callee, null, [[26,
|
|
271
|
+
}, _callee, null, [[26, 71]]);
|
|
236
272
|
}));
|
|
237
273
|
return _init.apply(this, arguments);
|
|
238
274
|
}
|
|
@@ -11,7 +11,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
|
|
|
11
11
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
12
|
import archiver from "archiver";
|
|
13
13
|
import path from "path";
|
|
14
|
-
import { outPathMap } from "../constants/index.js";
|
|
14
|
+
import { isSsrMap, outPathMap } from "../constants/index.js";
|
|
15
15
|
import { connectServer as _connectServer, getGitCurrentBranch, getServerConfig, isWorkingTreeClean, serverUnpack as _serverUnpack, serverUpload as _serverUpload } from "../utils/index.js";
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -37,6 +37,8 @@ var UploadCode = /*#__PURE__*/function () {
|
|
|
37
37
|
this.projectAbsolutePath = "";
|
|
38
38
|
this.conn = null;
|
|
39
39
|
this.serverConfig = null;
|
|
40
|
+
// 是否是ssr项目
|
|
41
|
+
this.isSSR = isSsrMap[this.projectName];
|
|
40
42
|
this.outPath = outPathMap[this.projectName][this.env];
|
|
41
43
|
}
|
|
42
44
|
|
|
@@ -99,7 +101,10 @@ var UploadCode = /*#__PURE__*/function () {
|
|
|
99
101
|
serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
|
|
100
102
|
}
|
|
101
103
|
if (this.env === "prod") {
|
|
102
|
-
serverConfig
|
|
104
|
+
serverConfig = this.setConfig(serverConfigMap['prod3']);
|
|
105
|
+
// serverConfig.privateKey = fs.readFileSync(
|
|
106
|
+
// path.join(process.env.HOME, '.ssh', 'id_rsa'),
|
|
107
|
+
// );
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
// pisell2.0正式环境使用亚马逊服务器
|