@pisell/common 0.0.33 → 0.0.34

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.
@@ -0,0 +1,187 @@
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 path from 'path';
11
+ import { getServerConfig } from "../utils/index.js";
12
+ var filterFiles = ['index.html', 'umi.server.js', 'umi.server.d.ts'];
13
+ var s3Client = null;
14
+ var bucketName = '';
15
+ var init = /*#__PURE__*/function () {
16
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
17
+ var serverConfig, awsConfig;
18
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
19
+ while (1) switch (_context.prev = _context.next) {
20
+ case 0:
21
+ _context.prev = 0;
22
+ _context.next = 3;
23
+ return getServerConfig();
24
+ case 3:
25
+ serverConfig = _context.sent;
26
+ awsConfig = serverConfig.aws;
27
+ if (!awsConfig) {
28
+ _context.next = 12;
29
+ break;
30
+ }
31
+ bucketName = awsConfig.bucketName;
32
+ s3Client = new S3Client({
33
+ region: awsConfig.region,
34
+ credentials: {
35
+ accessKeyId: awsConfig.accessKeyId,
36
+ secretAccessKey: awsConfig.secretAccessKey
37
+ }
38
+ });
39
+ console.log('aws 初始化成功');
40
+ return _context.abrupt("return", serverConfig.aws);
41
+ case 12:
42
+ console.log('未获取到aws权限');
43
+ return _context.abrupt("return", false);
44
+ case 14:
45
+ _context.next = 20;
46
+ break;
47
+ case 16:
48
+ _context.prev = 16;
49
+ _context.t0 = _context["catch"](0);
50
+ console.log(_context.t0);
51
+ return _context.abrupt("return", false);
52
+ case 20:
53
+ case "end":
54
+ return _context.stop();
55
+ }
56
+ }, _callee, null, [[0, 16]]);
57
+ }));
58
+ return function init() {
59
+ return _ref.apply(this, arguments);
60
+ };
61
+ }();
62
+
63
+ // 上传文件到S3指定目录
64
+ var uploadFile = /*#__PURE__*/function () {
65
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(directory, fileKey, filePath) {
66
+ var fileStream, uploadParams, command, response;
67
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
68
+ while (1) switch (_context2.prev = _context2.next) {
69
+ case 0:
70
+ fileStream = fs.createReadStream(filePath);
71
+ uploadParams = {
72
+ Bucket: bucketName,
73
+ Key: "static/".concat(directory, "/").concat(fileKey),
74
+ // 指定目录路径
75
+ Body: fileStream
76
+ };
77
+ command = new PutObjectCommand(uploadParams);
78
+ _context2.prev = 3;
79
+ _context2.next = 6;
80
+ return s3Client.send(command);
81
+ case 6:
82
+ response = _context2.sent;
83
+ console.log("\u4E0A\u4F20\u6210\u529F: ".concat(fileKey));
84
+ return _context2.abrupt("return", {
85
+ fileName: fileKey,
86
+ location: response.Location
87
+ });
88
+ case 11:
89
+ _context2.prev = 11;
90
+ _context2.t0 = _context2["catch"](3);
91
+ console.error("\u4E0A\u4F20\u5931\u8D25: ".concat(fileKey), _context2.t0);
92
+ return _context2.abrupt("return", {
93
+ fileName: fileKey,
94
+ error: _context2.t0
95
+ });
96
+ case 15:
97
+ case "end":
98
+ return _context2.stop();
99
+ }
100
+ }, _callee2, null, [[3, 11]]);
101
+ }));
102
+ return function uploadFile(_x, _x2, _x3) {
103
+ return _ref2.apply(this, arguments);
104
+ };
105
+ }();
106
+
107
+ // 递归上传文件夹内容
108
+ export var uploadFolderContents = /*#__PURE__*/function () {
109
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(directory) {
110
+ var folderPath,
111
+ files,
112
+ uploadPromises,
113
+ _iterator,
114
+ _step,
115
+ file,
116
+ filePath,
117
+ fileStats,
118
+ fileKey,
119
+ uploadPromise,
120
+ subDirectory,
121
+ subFolderPromise,
122
+ _args3 = arguments;
123
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
124
+ while (1) switch (_context3.prev = _context3.next) {
125
+ case 0:
126
+ folderPath = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : path.resolve(__dirname, 'dist');
127
+ files = fs.readdirSync(folderPath);
128
+ uploadPromises = [];
129
+ _iterator = _createForOfIteratorHelper(files);
130
+ try {
131
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
132
+ file = _step.value;
133
+ filePath = path.join(folderPath, file);
134
+ fileStats = fs.statSync(filePath);
135
+ if (fileStats.isFile()) {
136
+ fileKey = path.relative(folderPath, filePath);
137
+ if (!filterFiles.includes(fileKey)) {
138
+ uploadPromise = uploadFile(directory, fileKey, filePath);
139
+ uploadPromises.push(uploadPromise);
140
+ }
141
+ } else if (fileStats.isDirectory()) {
142
+ subDirectory = path.join(directory, file);
143
+ subFolderPromise = uploadFolderContents(subDirectory, filePath);
144
+ uploadPromises.push(subFolderPromise);
145
+ }
146
+ }
147
+ } catch (err) {
148
+ _iterator.e(err);
149
+ } finally {
150
+ _iterator.f();
151
+ }
152
+ return _context3.abrupt("return", Promise.all(uploadPromises).then(function (res) {
153
+ console.log('全部上传完成', res.length);
154
+ return res;
155
+ }));
156
+ case 6:
157
+ case "end":
158
+ return _context3.stop();
159
+ }
160
+ }, _callee3);
161
+ }));
162
+ return function uploadFolderContents(_x4) {
163
+ return _ref3.apply(this, arguments);
164
+ };
165
+ }();
166
+ export var uploadStaticToOSS = /*#__PURE__*/function () {
167
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(directory) {
168
+ var folderPath,
169
+ _args4 = arguments;
170
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
171
+ while (1) switch (_context4.prev = _context4.next) {
172
+ case 0:
173
+ folderPath = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : path.resolve(__dirname, 'dist');
174
+ _context4.next = 3;
175
+ return init();
176
+ case 3:
177
+ return _context4.abrupt("return", uploadFolderContents(directory, folderPath));
178
+ case 4:
179
+ case "end":
180
+ return _context4.stop();
181
+ }
182
+ }, _callee4);
183
+ }));
184
+ return function uploadStaticToOSS(_x5) {
185
+ return _ref4.apply(this, arguments);
186
+ };
187
+ }();
@@ -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";
@@ -150,28 +151,35 @@ function _init() {
150
151
  return uploadCode.build();
151
152
  case 30:
152
153
  console.log('✅ 打包完成');
153
- console.log('开始压缩');
154
+ if (!(res.env === 'prod')) {
155
+ _context.next = 34;
156
+ break;
157
+ }
154
158
  _context.next = 34;
155
- return uploadCode.compress();
159
+ return uploadStaticToOSS(res.project.fileName);
156
160
  case 34:
161
+ console.log('开始压缩');
162
+ _context.next = 37;
163
+ return uploadCode.compress();
164
+ case 37:
157
165
  console.log('✅ 压缩完成');
158
166
  console.log('开始连接服务器');
159
- _context.next = 38;
167
+ _context.next = 41;
160
168
  return uploadCode.connectServer();
161
- case 38:
169
+ case 41:
162
170
  conn = _context.sent;
163
171
  console.log('✅ 连接服务器完成');
164
172
  console.log('开始上传');
165
- _context.next = 43;
173
+ _context.next = 46;
166
174
  return uploadCode.serverUpload();
167
- case 43:
175
+ case 46:
168
176
  console.log('✅ 上传完成');
169
177
  console.log('开始解压');
170
- _context.next = 47;
178
+ _context.next = 50;
171
179
  return uploadCode.serverUnpack();
172
- case 47:
180
+ case 50:
173
181
  if (!res.is_release) {
174
- _context.next = 52;
182
+ _context.next = 55;
175
183
  break;
176
184
  }
177
185
  releaseInstance = new Release({
@@ -181,32 +189,32 @@ function _init() {
181
189
  conn: conn
182
190
  });
183
191
  console.log('开始发布');
184
- _context.next = 52;
192
+ _context.next = 55;
185
193
  return releaseInstance.release();
186
- case 52:
187
- _context.next = 54;
194
+ case 55:
195
+ _context.next = 57;
188
196
  return uploadCode.disconnectServer();
189
- case 54:
190
- _context.next = 56;
197
+ case 57:
198
+ _context.next = 59;
191
199
  return $(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["git pull --no-edit"])));
192
- case 56:
193
- _context.next = 58;
200
+ case 59:
201
+ _context.next = 61;
194
202
  return $(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["git push --follow-tags"])));
195
- case 58:
203
+ case 61:
196
204
  console.log('✅ 成功后推送到git');
197
- _context.next = 70;
205
+ _context.next = 73;
198
206
  break;
199
- case 61:
200
- _context.prev = 61;
207
+ case 64:
208
+ _context.prev = 64;
201
209
  _context.t0 = _context["catch"](26);
202
210
  console.log(_context.t0, '执行出错 请排查重试');
203
- _context.next = 66;
211
+ _context.next = 69;
204
212
  return $(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["git reset HEAD~1"])));
205
- case 66:
206
- _context.next = 68;
213
+ case 69:
214
+ _context.next = 71;
207
215
  return $(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["git tag -d v", ""])), uploadCode.currentVersion);
208
- case 68:
209
- _context.next = 70;
216
+ case 71:
217
+ _context.next = 73;
210
218
  return sendWebhook({
211
219
  title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u5931\u8D25"),
212
220
  content: [{
@@ -220,18 +228,18 @@ function _init() {
220
228
  value: version || ''
221
229
  }]
222
230
  });
223
- case 70:
231
+ case 73:
224
232
  if (!(res.project.fileName === 'my_pisel_shop')) {
225
- _context.next = 73;
233
+ _context.next = 76;
226
234
  break;
227
235
  }
228
- _context.next = 73;
236
+ _context.next = 76;
229
237
  return updateVersion({
230
238
  version: version,
231
239
  changelog: res.changelog
232
240
  }, res.env);
233
- case 73:
234
- _context.next = 75;
241
+ case 76:
242
+ _context.next = 78;
235
243
  return sendWebhook({
236
244
  title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u6210\u529F"),
237
245
  content: [{
@@ -245,13 +253,13 @@ function _init() {
245
253
  value: version || ''
246
254
  }]
247
255
  });
248
- case 75:
256
+ case 78:
249
257
  uploadCode.deleteLocalZip();
250
- case 76:
258
+ case 79:
251
259
  case "end":
252
260
  return _context.stop();
253
261
  }
254
- }, _callee, null, [[26, 61]]);
262
+ }, _callee, null, [[26, 64]]);
255
263
  }));
256
264
  return _init.apply(this, arguments);
257
265
  }
@@ -0,0 +1,116 @@
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_path = __toESM(require("path"));
39
+ var import_utils = require("../utils/index.js");
40
+ var filterFiles = ["index.html", "umi.server.js", "umi.server.d.ts"];
41
+ var s3Client = null;
42
+ var bucketName = "";
43
+ var init = async () => {
44
+ try {
45
+ const serverConfig = await (0, import_utils.getServerConfig)();
46
+ let awsConfig = serverConfig.aws;
47
+ if (awsConfig) {
48
+ bucketName = awsConfig.bucketName;
49
+ s3Client = new import_client_s3.S3Client({
50
+ region: awsConfig.region,
51
+ credentials: {
52
+ accessKeyId: awsConfig.accessKeyId,
53
+ secretAccessKey: awsConfig.secretAccessKey
54
+ }
55
+ });
56
+ console.log("aws 初始化成功");
57
+ return serverConfig.aws;
58
+ } else {
59
+ console.log("未获取到aws权限");
60
+ return false;
61
+ }
62
+ } catch (err) {
63
+ console.log(err);
64
+ return false;
65
+ }
66
+ };
67
+ var uploadFile = async (directory, fileKey, filePath) => {
68
+ const fileStream = import_fs.default.createReadStream(filePath);
69
+ const uploadParams = {
70
+ Bucket: bucketName,
71
+ Key: `static/${directory}/${fileKey}`,
72
+ // 指定目录路径
73
+ Body: fileStream
74
+ };
75
+ const command = new import_client_s3.PutObjectCommand(uploadParams);
76
+ try {
77
+ const response = await s3Client.send(command);
78
+ console.log(`上传成功: ${fileKey}`);
79
+ return { fileName: fileKey, location: response.Location };
80
+ } catch (err) {
81
+ console.error(`上传失败: ${fileKey}`, err);
82
+ return { fileName: fileKey, error: err };
83
+ }
84
+ };
85
+ var uploadFolderContents = async (directory, folderPath = import_path.default.resolve(__dirname, "dist")) => {
86
+ const files = import_fs.default.readdirSync(folderPath);
87
+ const uploadPromises = [];
88
+ for (const file of files) {
89
+ const filePath = import_path.default.join(folderPath, file);
90
+ const fileStats = import_fs.default.statSync(filePath);
91
+ if (fileStats.isFile()) {
92
+ const fileKey = import_path.default.relative(folderPath, filePath);
93
+ if (!filterFiles.includes(fileKey)) {
94
+ const uploadPromise = uploadFile(directory, fileKey, filePath);
95
+ uploadPromises.push(uploadPromise);
96
+ }
97
+ } else if (fileStats.isDirectory()) {
98
+ const subDirectory = import_path.default.join(directory, file);
99
+ const subFolderPromise = uploadFolderContents(subDirectory, filePath);
100
+ uploadPromises.push(subFolderPromise);
101
+ }
102
+ }
103
+ return Promise.all(uploadPromises).then((res) => {
104
+ console.log("全部上传完成", res.length);
105
+ return res;
106
+ });
107
+ };
108
+ var uploadStaticToOSS = async (directory, folderPath = import_path.default.resolve(__dirname, "dist")) => {
109
+ await init();
110
+ return uploadFolderContents(directory, folderPath);
111
+ };
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ uploadFolderContents,
115
+ uploadStaticToOSS
116
+ });
@@ -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,9 @@ async function init() {
131
132
  console.log("开始打包");
132
133
  await uploadCode.build();
133
134
  console.log("✅ 打包完成");
135
+ if (res.env === "prod") {
136
+ await (0, import_aws.uploadStaticToOSS)(res.project.fileName);
137
+ }
134
138
  console.log("开始压缩");
135
139
  await uploadCode.compress();
136
140
  console.log("✅ 压缩完成");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/common",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "A collection of reusable UI components for web development",
5
5
  "license": "MIT",
6
6
  "sideEffects": [
@@ -58,6 +58,7 @@
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",