@pisell/common 0.0.33 → 0.0.35
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/script/aws/index.js +217 -0
- package/es/script/uploadCode/index.js +47 -34
- package/lib/script/aws/index.js +121 -0
- package/lib/script/uploadCode/index.js +8 -0
- package/package.json +3 -1
|
@@ -0,0 +1,217 @@
|
|
|
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 s3Client = null;
|
|
15
|
+
var bucketName = '';
|
|
16
|
+
|
|
17
|
+
/*******
|
|
18
|
+
* @title: 初始化
|
|
19
|
+
* @description:
|
|
20
|
+
* @return {*}
|
|
21
|
+
* @Author: zhiwei.Wang
|
|
22
|
+
* @Date: 2023-11-24 14:05
|
|
23
|
+
*/
|
|
24
|
+
var init = /*#__PURE__*/function () {
|
|
25
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
26
|
+
var serverConfig, awsConfig;
|
|
27
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
28
|
+
while (1) switch (_context.prev = _context.next) {
|
|
29
|
+
case 0:
|
|
30
|
+
_context.prev = 0;
|
|
31
|
+
_context.next = 3;
|
|
32
|
+
return getServerConfig();
|
|
33
|
+
case 3:
|
|
34
|
+
serverConfig = _context.sent;
|
|
35
|
+
// aws配置
|
|
36
|
+
awsConfig = serverConfig.aws;
|
|
37
|
+
if (!awsConfig) {
|
|
38
|
+
_context.next = 12;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
bucketName = awsConfig.bucketName;
|
|
42
|
+
|
|
43
|
+
// 创建实例
|
|
44
|
+
s3Client = new S3Client({
|
|
45
|
+
region: awsConfig.region,
|
|
46
|
+
credentials: {
|
|
47
|
+
accessKeyId: awsConfig.accessKeyId,
|
|
48
|
+
secretAccessKey: awsConfig.secretAccessKey
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
console.log('aws 初始化成功');
|
|
52
|
+
return _context.abrupt("return", serverConfig.aws);
|
|
53
|
+
case 12:
|
|
54
|
+
console.log('未获取到aws权限');
|
|
55
|
+
return _context.abrupt("return", false);
|
|
56
|
+
case 14:
|
|
57
|
+
_context.next = 20;
|
|
58
|
+
break;
|
|
59
|
+
case 16:
|
|
60
|
+
_context.prev = 16;
|
|
61
|
+
_context.t0 = _context["catch"](0);
|
|
62
|
+
console.log(_context.t0);
|
|
63
|
+
return _context.abrupt("return", false);
|
|
64
|
+
case 20:
|
|
65
|
+
case "end":
|
|
66
|
+
return _context.stop();
|
|
67
|
+
}
|
|
68
|
+
}, _callee, null, [[0, 16]]);
|
|
69
|
+
}));
|
|
70
|
+
return function init() {
|
|
71
|
+
return _ref.apply(this, arguments);
|
|
72
|
+
};
|
|
73
|
+
}();
|
|
74
|
+
|
|
75
|
+
// 上传文件到S3指定目录
|
|
76
|
+
var uploadFile = /*#__PURE__*/function () {
|
|
77
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(directory, fileKey, filePath) {
|
|
78
|
+
var fileStream, contentType, uploadParams, command, response;
|
|
79
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
80
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
81
|
+
case 0:
|
|
82
|
+
fileStream = fs.createReadStream(filePath); // 根据文件扩展名获取MIME类型
|
|
83
|
+
contentType = mime.lookup(filePath);
|
|
84
|
+
uploadParams = {
|
|
85
|
+
Bucket: bucketName,
|
|
86
|
+
Key: "static/".concat(directory, "/").concat(fileKey),
|
|
87
|
+
// 指定目录路径
|
|
88
|
+
Body: fileStream,
|
|
89
|
+
contentType: contentType,
|
|
90
|
+
ACL: 'public-read' // 设置ACL权限为公共读取
|
|
91
|
+
};
|
|
92
|
+
command = new PutObjectCommand(uploadParams);
|
|
93
|
+
_context2.prev = 4;
|
|
94
|
+
_context2.next = 7;
|
|
95
|
+
return s3Client.send(command);
|
|
96
|
+
case 7:
|
|
97
|
+
response = _context2.sent;
|
|
98
|
+
console.log("\u4E0A\u4F20\u6210\u529F: ".concat(fileKey));
|
|
99
|
+
return _context2.abrupt("return", {
|
|
100
|
+
fileName: fileKey,
|
|
101
|
+
location: response.Location
|
|
102
|
+
});
|
|
103
|
+
case 12:
|
|
104
|
+
_context2.prev = 12;
|
|
105
|
+
_context2.t0 = _context2["catch"](4);
|
|
106
|
+
console.error("\u4E0A\u4F20\u5931\u8D25: ".concat(fileKey), _context2.t0);
|
|
107
|
+
return _context2.abrupt("return", {
|
|
108
|
+
fileName: fileKey,
|
|
109
|
+
error: _context2.t0
|
|
110
|
+
});
|
|
111
|
+
case 16:
|
|
112
|
+
case "end":
|
|
113
|
+
return _context2.stop();
|
|
114
|
+
}
|
|
115
|
+
}, _callee2, null, [[4, 12]]);
|
|
116
|
+
}));
|
|
117
|
+
return function uploadFile(_x, _x2, _x3) {
|
|
118
|
+
return _ref2.apply(this, arguments);
|
|
119
|
+
};
|
|
120
|
+
}();
|
|
121
|
+
|
|
122
|
+
/*******
|
|
123
|
+
* @title: 递归上传文件夹内容
|
|
124
|
+
* @description:
|
|
125
|
+
* @return {*}
|
|
126
|
+
* @Author: zhiwei.Wang
|
|
127
|
+
* @Date: 2023-11-24 14:06
|
|
128
|
+
*/
|
|
129
|
+
export var uploadFolderContents = /*#__PURE__*/function () {
|
|
130
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(directory) {
|
|
131
|
+
var folderPath,
|
|
132
|
+
files,
|
|
133
|
+
uploadPromises,
|
|
134
|
+
_iterator,
|
|
135
|
+
_step,
|
|
136
|
+
file,
|
|
137
|
+
filePath,
|
|
138
|
+
fileStats,
|
|
139
|
+
fileKey,
|
|
140
|
+
uploadPromise,
|
|
141
|
+
subDirectory,
|
|
142
|
+
subFolderPromise,
|
|
143
|
+
_args3 = arguments;
|
|
144
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
145
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
146
|
+
case 0:
|
|
147
|
+
folderPath = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : path.resolve(__dirname, 'dist');
|
|
148
|
+
files = fs.readdirSync(folderPath); // promise all 储存
|
|
149
|
+
uploadPromises = [];
|
|
150
|
+
_iterator = _createForOfIteratorHelper(files);
|
|
151
|
+
try {
|
|
152
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
153
|
+
file = _step.value;
|
|
154
|
+
filePath = path.join(folderPath, file);
|
|
155
|
+
fileStats = fs.statSync(filePath); // 文件上传, 文件夹递归循环
|
|
156
|
+
if (fileStats.isFile()) {
|
|
157
|
+
fileKey = path.relative(folderPath, filePath); // 过滤不需要上传的文件
|
|
158
|
+
if (!filterFiles.includes(fileKey)) {
|
|
159
|
+
uploadPromise = uploadFile(directory, fileKey, filePath);
|
|
160
|
+
uploadPromises.push(uploadPromise);
|
|
161
|
+
}
|
|
162
|
+
// 文件夹
|
|
163
|
+
} else if (fileStats.isDirectory()) {
|
|
164
|
+
subDirectory = path.join(directory, file);
|
|
165
|
+
subFolderPromise = uploadFolderContents(subDirectory, filePath);
|
|
166
|
+
uploadPromises.push(subFolderPromise);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
} catch (err) {
|
|
170
|
+
_iterator.e(err);
|
|
171
|
+
} finally {
|
|
172
|
+
_iterator.f();
|
|
173
|
+
}
|
|
174
|
+
return _context3.abrupt("return", Promise.all(uploadPromises).then(function (res) {
|
|
175
|
+
console.log('全部上传完成', res.length);
|
|
176
|
+
return res;
|
|
177
|
+
}));
|
|
178
|
+
case 6:
|
|
179
|
+
case "end":
|
|
180
|
+
return _context3.stop();
|
|
181
|
+
}
|
|
182
|
+
}, _callee3);
|
|
183
|
+
}));
|
|
184
|
+
return function uploadFolderContents(_x4) {
|
|
185
|
+
return _ref3.apply(this, arguments);
|
|
186
|
+
};
|
|
187
|
+
}();
|
|
188
|
+
|
|
189
|
+
/*******
|
|
190
|
+
* @title: 上传资源到oss
|
|
191
|
+
* @description:
|
|
192
|
+
* @return {*}
|
|
193
|
+
* @Author: zhiwei.Wang
|
|
194
|
+
* @Date: 2023-11-24 14:04
|
|
195
|
+
*/
|
|
196
|
+
export var uploadStaticToOSS = /*#__PURE__*/function () {
|
|
197
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(directory) {
|
|
198
|
+
var folderPath,
|
|
199
|
+
_args4 = arguments;
|
|
200
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
201
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
202
|
+
case 0:
|
|
203
|
+
folderPath = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : path.resolve(__dirname, 'dist');
|
|
204
|
+
_context4.next = 3;
|
|
205
|
+
return init();
|
|
206
|
+
case 3:
|
|
207
|
+
return _context4.abrupt("return", uploadFolderContents(directory, folderPath));
|
|
208
|
+
case 4:
|
|
209
|
+
case "end":
|
|
210
|
+
return _context4.stop();
|
|
211
|
+
}
|
|
212
|
+
}, _callee4);
|
|
213
|
+
}));
|
|
214
|
+
return function uploadStaticToOSS(_x5) {
|
|
215
|
+
return _ref4.apply(this, arguments);
|
|
216
|
+
};
|
|
217
|
+
}();
|
|
@@ -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";
|
|
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";
|
|
@@ -80,7 +81,7 @@ function init() {
|
|
|
80
81
|
*/
|
|
81
82
|
function _init() {
|
|
82
83
|
_init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
83
|
-
var res, uploadCode, version, currentUserName, result, conn, releaseInstance;
|
|
84
|
+
var res, uploadCode, version, currentUserName, result, _fileName, conn, releaseInstance;
|
|
84
85
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
85
86
|
while (1) switch (_context.prev = _context.next) {
|
|
86
87
|
case 0:
|
|
@@ -150,28 +151,40 @@ function _init() {
|
|
|
150
151
|
return uploadCode.build();
|
|
151
152
|
case 30:
|
|
152
153
|
console.log('✅ 打包完成');
|
|
154
|
+
if (!(res.env === 'pre' || res.env === 'prod')) {
|
|
155
|
+
_context.next = 36;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
_fileName = res.project.fileName;
|
|
159
|
+
if (res.env === 'pre') {
|
|
160
|
+
_fileName = 'pre_' + _fileName;
|
|
161
|
+
}
|
|
162
|
+
// 上传oss
|
|
163
|
+
_context.next = 36;
|
|
164
|
+
return uploadStaticToOSS(_fileName);
|
|
165
|
+
case 36:
|
|
153
166
|
console.log('开始压缩');
|
|
154
|
-
_context.next =
|
|
167
|
+
_context.next = 39;
|
|
155
168
|
return uploadCode.compress();
|
|
156
|
-
case
|
|
169
|
+
case 39:
|
|
157
170
|
console.log('✅ 压缩完成');
|
|
158
171
|
console.log('开始连接服务器');
|
|
159
|
-
_context.next =
|
|
172
|
+
_context.next = 43;
|
|
160
173
|
return uploadCode.connectServer();
|
|
161
|
-
case
|
|
174
|
+
case 43:
|
|
162
175
|
conn = _context.sent;
|
|
163
176
|
console.log('✅ 连接服务器完成');
|
|
164
177
|
console.log('开始上传');
|
|
165
|
-
_context.next =
|
|
178
|
+
_context.next = 48;
|
|
166
179
|
return uploadCode.serverUpload();
|
|
167
|
-
case
|
|
180
|
+
case 48:
|
|
168
181
|
console.log('✅ 上传完成');
|
|
169
182
|
console.log('开始解压');
|
|
170
|
-
_context.next =
|
|
183
|
+
_context.next = 52;
|
|
171
184
|
return uploadCode.serverUnpack();
|
|
172
|
-
case
|
|
185
|
+
case 52:
|
|
173
186
|
if (!res.is_release) {
|
|
174
|
-
_context.next =
|
|
187
|
+
_context.next = 57;
|
|
175
188
|
break;
|
|
176
189
|
}
|
|
177
190
|
releaseInstance = new Release({
|
|
@@ -181,32 +194,32 @@ function _init() {
|
|
|
181
194
|
conn: conn
|
|
182
195
|
});
|
|
183
196
|
console.log('开始发布');
|
|
184
|
-
_context.next =
|
|
197
|
+
_context.next = 57;
|
|
185
198
|
return releaseInstance.release();
|
|
186
|
-
case
|
|
187
|
-
_context.next =
|
|
199
|
+
case 57:
|
|
200
|
+
_context.next = 59;
|
|
188
201
|
return uploadCode.disconnectServer();
|
|
189
|
-
case
|
|
190
|
-
_context.next =
|
|
202
|
+
case 59:
|
|
203
|
+
_context.next = 61;
|
|
191
204
|
return $(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["git pull --no-edit"])));
|
|
192
|
-
case
|
|
193
|
-
_context.next =
|
|
205
|
+
case 61:
|
|
206
|
+
_context.next = 63;
|
|
194
207
|
return $(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["git push --follow-tags"])));
|
|
195
|
-
case
|
|
208
|
+
case 63:
|
|
196
209
|
console.log('✅ 成功后推送到git');
|
|
197
|
-
_context.next =
|
|
210
|
+
_context.next = 75;
|
|
198
211
|
break;
|
|
199
|
-
case
|
|
200
|
-
_context.prev =
|
|
212
|
+
case 66:
|
|
213
|
+
_context.prev = 66;
|
|
201
214
|
_context.t0 = _context["catch"](26);
|
|
202
215
|
console.log(_context.t0, '执行出错 请排查重试');
|
|
203
|
-
_context.next =
|
|
216
|
+
_context.next = 71;
|
|
204
217
|
return $(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["git reset HEAD~1"])));
|
|
205
|
-
case
|
|
206
|
-
_context.next =
|
|
218
|
+
case 71:
|
|
219
|
+
_context.next = 73;
|
|
207
220
|
return $(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["git tag -d v", ""])), uploadCode.currentVersion);
|
|
208
|
-
case
|
|
209
|
-
_context.next =
|
|
221
|
+
case 73:
|
|
222
|
+
_context.next = 75;
|
|
210
223
|
return sendWebhook({
|
|
211
224
|
title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u5931\u8D25"),
|
|
212
225
|
content: [{
|
|
@@ -220,18 +233,18 @@ function _init() {
|
|
|
220
233
|
value: version || ''
|
|
221
234
|
}]
|
|
222
235
|
});
|
|
223
|
-
case
|
|
236
|
+
case 75:
|
|
224
237
|
if (!(res.project.fileName === 'my_pisel_shop')) {
|
|
225
|
-
_context.next =
|
|
238
|
+
_context.next = 78;
|
|
226
239
|
break;
|
|
227
240
|
}
|
|
228
|
-
_context.next =
|
|
241
|
+
_context.next = 78;
|
|
229
242
|
return updateVersion({
|
|
230
243
|
version: version,
|
|
231
244
|
changelog: res.changelog
|
|
232
245
|
}, res.env);
|
|
233
|
-
case
|
|
234
|
-
_context.next =
|
|
246
|
+
case 78:
|
|
247
|
+
_context.next = 80;
|
|
235
248
|
return sendWebhook({
|
|
236
249
|
title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u6210\u529F"),
|
|
237
250
|
content: [{
|
|
@@ -245,13 +258,13 @@ function _init() {
|
|
|
245
258
|
value: version || ''
|
|
246
259
|
}]
|
|
247
260
|
});
|
|
248
|
-
case
|
|
261
|
+
case 80:
|
|
249
262
|
uploadCode.deleteLocalZip();
|
|
250
|
-
case
|
|
263
|
+
case 81:
|
|
251
264
|
case "end":
|
|
252
265
|
return _context.stop();
|
|
253
266
|
}
|
|
254
|
-
}, _callee, null, [[26,
|
|
267
|
+
}, _callee, null, [[26, 66]]);
|
|
255
268
|
}));
|
|
256
269
|
return _init.apply(this, arguments);
|
|
257
270
|
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/script/aws/index.js
|
|
30
|
+
var aws_exports = {};
|
|
31
|
+
__export(aws_exports, {
|
|
32
|
+
uploadFolderContents: () => uploadFolderContents,
|
|
33
|
+
uploadStaticToOSS: () => uploadStaticToOSS
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(aws_exports);
|
|
36
|
+
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
37
|
+
var import_fs = __toESM(require("fs"));
|
|
38
|
+
var import_mime_types = __toESM(require("mime-types"));
|
|
39
|
+
var import_path = __toESM(require("path"));
|
|
40
|
+
var import_utils = require("../utils/index.js");
|
|
41
|
+
var filterFiles = ["index.html", "umi.server.js", "umi.server.d.ts"];
|
|
42
|
+
var s3Client = null;
|
|
43
|
+
var bucketName = "";
|
|
44
|
+
var init = async () => {
|
|
45
|
+
try {
|
|
46
|
+
const serverConfig = await (0, import_utils.getServerConfig)();
|
|
47
|
+
let awsConfig = serverConfig.aws;
|
|
48
|
+
if (awsConfig) {
|
|
49
|
+
bucketName = awsConfig.bucketName;
|
|
50
|
+
s3Client = new import_client_s3.S3Client({
|
|
51
|
+
region: awsConfig.region,
|
|
52
|
+
credentials: {
|
|
53
|
+
accessKeyId: awsConfig.accessKeyId,
|
|
54
|
+
secretAccessKey: awsConfig.secretAccessKey
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
console.log("aws 初始化成功");
|
|
58
|
+
return serverConfig.aws;
|
|
59
|
+
} else {
|
|
60
|
+
console.log("未获取到aws权限");
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.log(err);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var uploadFile = async (directory, fileKey, filePath) => {
|
|
69
|
+
const fileStream = import_fs.default.createReadStream(filePath);
|
|
70
|
+
const contentType = import_mime_types.default.lookup(filePath);
|
|
71
|
+
const uploadParams = {
|
|
72
|
+
Bucket: bucketName,
|
|
73
|
+
Key: `static/${directory}/${fileKey}`,
|
|
74
|
+
// 指定目录路径
|
|
75
|
+
Body: fileStream,
|
|
76
|
+
contentType,
|
|
77
|
+
ACL: "public-read"
|
|
78
|
+
// 设置ACL权限为公共读取
|
|
79
|
+
};
|
|
80
|
+
const command = new import_client_s3.PutObjectCommand(uploadParams);
|
|
81
|
+
try {
|
|
82
|
+
const response = await s3Client.send(command);
|
|
83
|
+
console.log(`上传成功: ${fileKey}`);
|
|
84
|
+
return { fileName: fileKey, location: response.Location };
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error(`上传失败: ${fileKey}`, err);
|
|
87
|
+
return { fileName: fileKey, error: err };
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var uploadFolderContents = async (directory, folderPath = import_path.default.resolve(__dirname, "dist")) => {
|
|
91
|
+
const files = import_fs.default.readdirSync(folderPath);
|
|
92
|
+
const uploadPromises = [];
|
|
93
|
+
for (const file of files) {
|
|
94
|
+
const filePath = import_path.default.join(folderPath, file);
|
|
95
|
+
const fileStats = import_fs.default.statSync(filePath);
|
|
96
|
+
if (fileStats.isFile()) {
|
|
97
|
+
const fileKey = import_path.default.relative(folderPath, filePath);
|
|
98
|
+
if (!filterFiles.includes(fileKey)) {
|
|
99
|
+
const uploadPromise = uploadFile(directory, fileKey, filePath);
|
|
100
|
+
uploadPromises.push(uploadPromise);
|
|
101
|
+
}
|
|
102
|
+
} else if (fileStats.isDirectory()) {
|
|
103
|
+
const subDirectory = import_path.default.join(directory, file);
|
|
104
|
+
const subFolderPromise = uploadFolderContents(subDirectory, filePath);
|
|
105
|
+
uploadPromises.push(subFolderPromise);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return Promise.all(uploadPromises).then((res) => {
|
|
109
|
+
console.log("全部上传完成", res.length);
|
|
110
|
+
return res;
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
var uploadStaticToOSS = async (directory, folderPath = import_path.default.resolve(__dirname, "dist")) => {
|
|
114
|
+
await init();
|
|
115
|
+
return uploadFolderContents(directory, folderPath);
|
|
116
|
+
};
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
uploadFolderContents,
|
|
120
|
+
uploadStaticToOSS
|
|
121
|
+
});
|
|
@@ -35,6 +35,7 @@ __export(uploadCode_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(uploadCode_exports);
|
|
36
36
|
var import_inquirer = __toESM(require("inquirer"));
|
|
37
37
|
var import_globals = require("zx/globals");
|
|
38
|
+
var import_aws = require("../aws");
|
|
38
39
|
var import_release = __toESM(require("../release/release.js"));
|
|
39
40
|
var import_utils = require("../utils/index.js");
|
|
40
41
|
var import_uploadCode = __toESM(require("./uploadCode.js"));
|
|
@@ -131,6 +132,13 @@ async function init() {
|
|
|
131
132
|
console.log("开始打包");
|
|
132
133
|
await uploadCode.build();
|
|
133
134
|
console.log("✅ 打包完成");
|
|
135
|
+
if (res.env === "pre" || res.env === "prod") {
|
|
136
|
+
let _fileName = res.project.fileName;
|
|
137
|
+
if (res.env === "pre") {
|
|
138
|
+
_fileName = "pre_" + _fileName;
|
|
139
|
+
}
|
|
140
|
+
await (0, import_aws.uploadStaticToOSS)(_fileName);
|
|
141
|
+
}
|
|
134
142
|
console.log("开始压缩");
|
|
135
143
|
await uploadCode.compress();
|
|
136
144
|
console.log("✅ 压缩完成");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pisell/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"description": "A collection of reusable UI components for web development",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": [
|
|
@@ -58,11 +58,13 @@
|
|
|
58
58
|
]
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
+
"@aws-sdk/client-s3": "^3.456.0",
|
|
61
62
|
"antd5": "npm:antd@^5.5.0",
|
|
62
63
|
"archiver": "^5.3.1",
|
|
63
64
|
"array-move": "^3.0.1",
|
|
64
65
|
"dotenv": "^16.0.3",
|
|
65
66
|
"inquirer": "^9.2.6",
|
|
67
|
+
"mime-types": "^2.1.35",
|
|
66
68
|
"npm-check": "^6.0.1",
|
|
67
69
|
"react-beautiful-dnd": "^13.1.0",
|
|
68
70
|
"react-color": "^2.19.3",
|