@pisell/common 1.0.19 → 1.0.21
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/es/script/utils/index.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
2
|
var _templateObject, _templateObject2, _templateObject3;
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
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); }
|
|
3
8
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
4
9
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
5
10
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
6
11
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
7
12
|
import * as dotenv from 'dotenv';
|
|
13
|
+
import npmCheck from 'npm-check';
|
|
8
14
|
import path from 'path';
|
|
9
15
|
import ssh2 from 'ssh2';
|
|
10
16
|
|
|
@@ -202,7 +208,8 @@ var serverUnpack = function serverUnpack(conn, _ref5) {
|
|
|
202
208
|
*/
|
|
203
209
|
var releaseProject = function releaseProject(conn, _ref6) {
|
|
204
210
|
var path = _ref6.path,
|
|
205
|
-
fileName = _ref6.fileName
|
|
211
|
+
fileName = _ref6.fileName,
|
|
212
|
+
isSSR = _ref6.isSSR;
|
|
206
213
|
return new Promise(function (resolve, reject) {
|
|
207
214
|
conn.shell(function (err, stream) {
|
|
208
215
|
if (err) {
|
|
@@ -210,7 +217,7 @@ var releaseProject = function releaseProject(conn, _ref6) {
|
|
|
210
217
|
reject(err);
|
|
211
218
|
return;
|
|
212
219
|
}
|
|
213
|
-
stream.end("\n cd ".concat(path, "\n cp -R -f pre-master next-master\n rm -rf pre-master\n \\cp -R -f ").concat(fileName, "/* next-master\n cp -R -f ").concat(fileName, " pre-master\n rm -rf master\n cp -R next-master master\n rm -rf next-master\n exit\n ") // 打开到path
|
|
220
|
+
stream.end("\n cd ".concat(path, "\n cp -R -f pre-master next-master\n rm -rf pre-master\n \\cp -R -f ").concat(fileName, "/* next-master\n cp -R -f ").concat(fileName, " pre-master\n rm -rf master\n cp -R next-master master\n rm -rf next-master\n ").concat(isSSR ? 'pm2 restart server.js' : '', "\n exit\n ") // 打开到path
|
|
214
221
|
// 复制pre-master到next-master
|
|
215
222
|
// 删除pre-master
|
|
216
223
|
// 复制1.0.0到next-master
|
|
@@ -255,6 +262,9 @@ var versionSort = function versionSort(versionList) {
|
|
|
255
262
|
var getCurrentProjectName = function getCurrentProjectName() {
|
|
256
263
|
return loadJSON(path.join(process.cwd(), './package.json')).name;
|
|
257
264
|
};
|
|
265
|
+
var getCurrentProjectPkg = function getCurrentProjectPkg() {
|
|
266
|
+
return loadJSON(path.join(process.cwd(), './package.json'));
|
|
267
|
+
};
|
|
258
268
|
var loadJSON = function loadJSON(path) {
|
|
259
269
|
return JSON.parse(fs.readFileSync(path));
|
|
260
270
|
};
|
|
@@ -291,6 +301,16 @@ var createFeishuMessageContent = function createFeishuMessageContent(contentArr)
|
|
|
291
301
|
}];
|
|
292
302
|
}));
|
|
293
303
|
};
|
|
304
|
+
|
|
305
|
+
// 获取除了此pkg的包
|
|
306
|
+
var getNonExcludedPackages = function getNonExcludedPackages(excludedPackages) {
|
|
307
|
+
var packageData = getCurrentProjectPkg();
|
|
308
|
+
var dependencies = _objectSpread(_objectSpread({}, packageData.dependencies), packageData.devDependencies);
|
|
309
|
+
var nonExcludedPackages = Object.keys(dependencies).filter(function (packageName) {
|
|
310
|
+
return !excludedPackages.includes(packageName);
|
|
311
|
+
});
|
|
312
|
+
return nonExcludedPackages;
|
|
313
|
+
};
|
|
294
314
|
var sendWebhook = /*#__PURE__*/function () {
|
|
295
315
|
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref8) {
|
|
296
316
|
var _dotenv$config, _dotenv$config$parsed, _dotenv$config2, _dotenv$config2$parse;
|
|
@@ -333,4 +353,39 @@ var sendWebhook = /*#__PURE__*/function () {
|
|
|
333
353
|
return _ref9.apply(this, arguments);
|
|
334
354
|
};
|
|
335
355
|
}();
|
|
336
|
-
|
|
356
|
+
var checkPkgVersion = /*#__PURE__*/function () {
|
|
357
|
+
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(checkPackages) {
|
|
358
|
+
var currentState, pkgs, wrongPkg, errorMessage, isWrongVersion;
|
|
359
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
360
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
361
|
+
case 0:
|
|
362
|
+
_context6.next = 2;
|
|
363
|
+
return npmCheck({
|
|
364
|
+
skipUnused: true,
|
|
365
|
+
ignore: getNonExcludedPackages(checkPackages)
|
|
366
|
+
});
|
|
367
|
+
case 2:
|
|
368
|
+
currentState = _context6.sent;
|
|
369
|
+
pkgs = currentState.get('packages');
|
|
370
|
+
wrongPkg = pkgs.filter(function (item) {
|
|
371
|
+
return checkPackages.includes(item.moduleName) && item.mismatch;
|
|
372
|
+
});
|
|
373
|
+
errorMessage = wrongPkg.reduce(function (p, c) {
|
|
374
|
+
return "".concat(p, "\n ").concat(c.moduleName, "\u672C\u5730\u7248\u672C").concat(c.installed, "\u9700\u5347\u7EA7\u81F3").concat(c.packageJson, "\n ");
|
|
375
|
+
}, '');
|
|
376
|
+
isWrongVersion = wrongPkg.length;
|
|
377
|
+
return _context6.abrupt("return", {
|
|
378
|
+
success: !isWrongVersion,
|
|
379
|
+
message: errorMessage
|
|
380
|
+
});
|
|
381
|
+
case 8:
|
|
382
|
+
case "end":
|
|
383
|
+
return _context6.stop();
|
|
384
|
+
}
|
|
385
|
+
}, _callee6);
|
|
386
|
+
}));
|
|
387
|
+
return function checkPkgVersion(_x3) {
|
|
388
|
+
return _ref10.apply(this, arguments);
|
|
389
|
+
};
|
|
390
|
+
}();
|
|
391
|
+
export { isWorkingTreeClean, getServerConfig, connectServer, serverUpload, serverUnpack, versionSort, releaseProject, getGitCurrentBranch, getCurrentProjectName, loadJSON, getCurrentUserName, sendWebhook, checkPkgVersion };
|
package/lib/index.d.ts
CHANGED
|
@@ -0,0 +1,125 @@
|
|
|
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 __dirname = process.cwd();
|
|
43
|
+
var s3Client = null;
|
|
44
|
+
var bucketName = "";
|
|
45
|
+
var init = async () => {
|
|
46
|
+
try {
|
|
47
|
+
const serverConfig = await (0, import_utils.getServerConfig)("admin");
|
|
48
|
+
let awsConfig = serverConfig.aws;
|
|
49
|
+
if (awsConfig) {
|
|
50
|
+
bucketName = awsConfig.bucketName;
|
|
51
|
+
s3Client = new import_client_s3.S3Client({
|
|
52
|
+
region: awsConfig.region,
|
|
53
|
+
credentials: {
|
|
54
|
+
accessKeyId: awsConfig.accessKeyId,
|
|
55
|
+
secretAccessKey: awsConfig.secretAccessKey
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
console.log("aws 初始化成功");
|
|
59
|
+
return serverConfig.aws;
|
|
60
|
+
} else {
|
|
61
|
+
console.log("未获取到aws权限");
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.log(err);
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var uploadFile = async (directory, fileKey, filePath) => {
|
|
70
|
+
const fileStream = import_fs.default.createReadStream(filePath);
|
|
71
|
+
const contentType = import_mime_types.default.lookup(filePath);
|
|
72
|
+
const uploadParams = {
|
|
73
|
+
Bucket: bucketName,
|
|
74
|
+
Key: `${directory}/${fileKey}`,
|
|
75
|
+
// 指定目录路径
|
|
76
|
+
Body: fileStream,
|
|
77
|
+
ContentType: contentType,
|
|
78
|
+
ContentDisposition: "inline",
|
|
79
|
+
ACL: "public-read"
|
|
80
|
+
// 设置ACL权限为公共读取
|
|
81
|
+
};
|
|
82
|
+
const command = new import_client_s3.PutObjectCommand(uploadParams);
|
|
83
|
+
try {
|
|
84
|
+
const response = await s3Client.send(command);
|
|
85
|
+
console.log(`上传成功: ${fileKey}`);
|
|
86
|
+
return { fileName: fileKey, location: response.Location };
|
|
87
|
+
} catch (err) {
|
|
88
|
+
console.error(`上传失败: ${fileKey}`, err);
|
|
89
|
+
throw new Error(`上传失败: ${fileKey}, ${err.message}`);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var uploadFolderContents = async (directory, folderPath = import_path.default.resolve(__dirname, "dist")) => {
|
|
93
|
+
const files = import_fs.default.readdirSync(folderPath);
|
|
94
|
+
const uploadPromises = [];
|
|
95
|
+
for (const file of files) {
|
|
96
|
+
const filePath = import_path.default.join(folderPath, file);
|
|
97
|
+
const fileStats = import_fs.default.statSync(filePath);
|
|
98
|
+
if (fileStats.isFile()) {
|
|
99
|
+
const fileKey = import_path.default.relative(folderPath, filePath);
|
|
100
|
+
if (!filterFiles.includes(fileKey)) {
|
|
101
|
+
const uploadPromise = uploadFile(directory, fileKey, filePath);
|
|
102
|
+
uploadPromises.push(uploadPromise);
|
|
103
|
+
}
|
|
104
|
+
} else if (fileStats.isDirectory()) {
|
|
105
|
+
const subDirectory = import_path.default.join(directory, file);
|
|
106
|
+
const subFolderPromise = uploadFolderContents(subDirectory, filePath);
|
|
107
|
+
uploadPromises.push(subFolderPromise);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return Promise.all(uploadPromises).then((res) => {
|
|
111
|
+
console.log("全部上传完成", res.length);
|
|
112
|
+
return res;
|
|
113
|
+
}).catch((err) => {
|
|
114
|
+
throw new Error(`上传cdn失败: ${err.message}`);
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
var uploadStaticToOSS = async (directory, folderPath = import_path.default.resolve(__dirname, "dist")) => {
|
|
118
|
+
await init();
|
|
119
|
+
return uploadFolderContents(directory, folderPath);
|
|
120
|
+
};
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
uploadFolderContents,
|
|
124
|
+
uploadStaticToOSS
|
|
125
|
+
});
|
|
@@ -19,12 +19,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/script/constants/index.js
|
|
20
20
|
var constants_exports = {};
|
|
21
21
|
__export(constants_exports, {
|
|
22
|
+
checkPackages: () => checkPackages,
|
|
23
|
+
isSsrMap: () => isSsrMap,
|
|
22
24
|
outPathMap: () => outPathMap
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(constants_exports);
|
|
25
27
|
var outPathMap = {
|
|
26
28
|
my_pisel_shop: {
|
|
27
|
-
prod: "../data/release/project/
|
|
29
|
+
prod: "../data/release/project/my_pisel_shop",
|
|
28
30
|
release: "../data/release/project/my_pisel_shop",
|
|
29
31
|
pre: "../data/release/project/my_pisel_shop"
|
|
30
32
|
},
|
|
@@ -32,9 +34,33 @@ var outPathMap = {
|
|
|
32
34
|
prod: "../../data/project/pisell2",
|
|
33
35
|
release: "../data/release/project/pisell_v2",
|
|
34
36
|
pre: "../data/release/project/pisell_v2"
|
|
37
|
+
},
|
|
38
|
+
my_pisel_pc_v2: {
|
|
39
|
+
prod: "../data/release/project/my_pisel_pc_v2",
|
|
40
|
+
release: "../data/release/project/my_pisel_pc_v2",
|
|
41
|
+
pre: "../data/release/project/my_pisel_pc_v2"
|
|
42
|
+
},
|
|
43
|
+
my_pisel_h5_v2: {
|
|
44
|
+
prod: "../data/release/project/my_pisel_h5_v2",
|
|
45
|
+
release: "../data/release/project/my_pisel_h5_v2",
|
|
46
|
+
pre: "../data/release/project/my_pisel_h5_v2"
|
|
35
47
|
}
|
|
36
48
|
};
|
|
49
|
+
var isSsrMap = {
|
|
50
|
+
my_pisel_shop: false,
|
|
51
|
+
admin: false,
|
|
52
|
+
my_pisel_pc_v2: true,
|
|
53
|
+
my_pisel_h5_v2: true
|
|
54
|
+
};
|
|
55
|
+
var checkPackages = [
|
|
56
|
+
"@pisell/date-picker",
|
|
57
|
+
"@pisell/lowcode-renderer",
|
|
58
|
+
"@pisell/common",
|
|
59
|
+
"@pisell/utils"
|
|
60
|
+
];
|
|
37
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
62
|
0 && (module.exports = {
|
|
63
|
+
checkPackages,
|
|
64
|
+
isSsrMap,
|
|
39
65
|
outPathMap
|
|
40
66
|
});
|
|
@@ -32,6 +32,7 @@ var Release = class {
|
|
|
32
32
|
this.version = version;
|
|
33
33
|
this.conn = conn;
|
|
34
34
|
this.outPath = import_constants.outPathMap[this.projectName][this.env];
|
|
35
|
+
this.isSSR = import_constants.isSsrMap[this.projectName];
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
38
|
* @Title: 设置连接服务器配置
|
|
@@ -72,7 +73,8 @@ var Release = class {
|
|
|
72
73
|
async release() {
|
|
73
74
|
return await (0, import_utils.releaseProject)(this.conn, {
|
|
74
75
|
path: this.outPath,
|
|
75
|
-
fileName: `${this.version}
|
|
76
|
+
fileName: `${this.version}`,
|
|
77
|
+
isSSR: this.isSSR
|
|
76
78
|
});
|
|
77
79
|
}
|
|
78
80
|
/**
|
|
@@ -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/index.js");
|
|
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"));
|
|
@@ -82,6 +83,15 @@ var inquirerResult = () => {
|
|
|
82
83
|
{ value: false, name: "只上传" }
|
|
83
84
|
]
|
|
84
85
|
},
|
|
86
|
+
{
|
|
87
|
+
type: "list",
|
|
88
|
+
message: "是否执行build打包",
|
|
89
|
+
name: "whether_build",
|
|
90
|
+
choices: [
|
|
91
|
+
{ value: true, name: "执行打包" },
|
|
92
|
+
{ value: false, name: "不执行打包,使用项目根目录/dist文件夹" }
|
|
93
|
+
]
|
|
94
|
+
},
|
|
85
95
|
{
|
|
86
96
|
type: "confirm",
|
|
87
97
|
message: "确认信息无误",
|
|
@@ -128,9 +138,23 @@ async function init() {
|
|
|
128
138
|
});
|
|
129
139
|
console.log(result, "result");
|
|
130
140
|
try {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
141
|
+
if (res.whether_build) {
|
|
142
|
+
console.log("开始打包");
|
|
143
|
+
await uploadCode.build();
|
|
144
|
+
console.log("✅ 打包完成");
|
|
145
|
+
} else {
|
|
146
|
+
console.log("使用本地/dist");
|
|
147
|
+
}
|
|
148
|
+
if (res.env === "prod") {
|
|
149
|
+
let _fileName = res.project.fileName;
|
|
150
|
+
if (res.env === "pre") {
|
|
151
|
+
_fileName = "pre_" + _fileName;
|
|
152
|
+
}
|
|
153
|
+
if (_fileName === "admin") {
|
|
154
|
+
_fileName = "my_pisell_v2";
|
|
155
|
+
}
|
|
156
|
+
await (0, import_aws.uploadStaticToOSS)(_fileName);
|
|
157
|
+
}
|
|
134
158
|
console.log("开始压缩");
|
|
135
159
|
await uploadCode.compress();
|
|
136
160
|
console.log("✅ 压缩完成");
|
|
@@ -49,6 +49,7 @@ var UploadCode = class {
|
|
|
49
49
|
this.projectAbsolutePath = "";
|
|
50
50
|
this.conn = null;
|
|
51
51
|
this.serverConfig = null;
|
|
52
|
+
this.isSSR = import_constants.isSsrMap[this.projectName];
|
|
52
53
|
this.outPath = import_constants.outPathMap[this.projectName][this.env];
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
@@ -82,9 +83,7 @@ var UploadCode = class {
|
|
|
82
83
|
serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
|
|
83
84
|
}
|
|
84
85
|
if (this.env === "prod") {
|
|
85
|
-
serverConfig
|
|
86
|
-
import_path.default.join(process.env.HOME, ".ssh", "id_rsa")
|
|
87
|
-
);
|
|
86
|
+
serverConfig = this.setConfig(serverConfigMap["prod3"]);
|
|
88
87
|
}
|
|
89
88
|
if (this.env === "prod" && this.projectName === "admin") {
|
|
90
89
|
serverConfig = serverConfigMap.aws[this.env];
|
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/script/utils/index.js
|
|
30
30
|
var utils_exports = {};
|
|
31
31
|
__export(utils_exports, {
|
|
32
|
+
checkPkgVersion: () => checkPkgVersion,
|
|
32
33
|
connectServer: () => connectServer,
|
|
33
34
|
getCurrentProjectName: () => getCurrentProjectName,
|
|
34
35
|
getCurrentUserName: () => getCurrentUserName,
|
|
@@ -44,6 +45,7 @@ __export(utils_exports, {
|
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(utils_exports);
|
|
46
47
|
var dotenv = __toESM(require("dotenv"));
|
|
48
|
+
var import_npm_check = __toESM(require("npm-check"));
|
|
47
49
|
var import_path = __toESM(require("path"));
|
|
48
50
|
var import_ssh2 = __toESM(require("ssh2"));
|
|
49
51
|
var isWorkingTreeClean = async () => {
|
|
@@ -149,7 +151,7 @@ var serverUnpack = (conn, { path: path2, fileName, fullFileName, changelog }) =>
|
|
|
149
151
|
});
|
|
150
152
|
});
|
|
151
153
|
};
|
|
152
|
-
var releaseProject = (conn, { path: path2, fileName }) => {
|
|
154
|
+
var releaseProject = (conn, { path: path2, fileName, isSSR }) => {
|
|
153
155
|
return new Promise((resolve, reject) => {
|
|
154
156
|
conn.shell((err, stream) => {
|
|
155
157
|
if (err) {
|
|
@@ -167,6 +169,7 @@ var releaseProject = (conn, { path: path2, fileName }) => {
|
|
|
167
169
|
rm -rf master
|
|
168
170
|
cp -R next-master master
|
|
169
171
|
rm -rf next-master
|
|
172
|
+
${isSSR ? "pm2 restart server.js" : ""}
|
|
170
173
|
exit
|
|
171
174
|
`
|
|
172
175
|
// 打开到path
|
|
@@ -203,6 +206,9 @@ var versionSort = (versionList) => {
|
|
|
203
206
|
var getCurrentProjectName = () => {
|
|
204
207
|
return loadJSON(import_path.default.join(process.cwd(), "./package.json")).name;
|
|
205
208
|
};
|
|
209
|
+
var getCurrentProjectPkg = () => {
|
|
210
|
+
return loadJSON(import_path.default.join(process.cwd(), "./package.json"));
|
|
211
|
+
};
|
|
206
212
|
var loadJSON = (path2) => JSON.parse(fs.readFileSync(path2));
|
|
207
213
|
var getCurrentUserName = async () => {
|
|
208
214
|
const { stdout } = await $`git config user.name`;
|
|
@@ -218,6 +224,17 @@ var createFeishuMessageContent = (contentArr) => {
|
|
|
218
224
|
})
|
|
219
225
|
);
|
|
220
226
|
};
|
|
227
|
+
var getNonExcludedPackages = (excludedPackages) => {
|
|
228
|
+
const packageData = getCurrentProjectPkg();
|
|
229
|
+
const dependencies = {
|
|
230
|
+
...packageData.dependencies,
|
|
231
|
+
...packageData.devDependencies
|
|
232
|
+
};
|
|
233
|
+
const nonExcludedPackages = Object.keys(dependencies).filter(
|
|
234
|
+
(packageName) => !excludedPackages.includes(packageName)
|
|
235
|
+
);
|
|
236
|
+
return nonExcludedPackages;
|
|
237
|
+
};
|
|
221
238
|
var sendWebhook = async ({ title, content }) => {
|
|
222
239
|
var _a, _b, _c, _d;
|
|
223
240
|
const contentStr = createFeishuMessageContent(content);
|
|
@@ -235,8 +252,29 @@ var sendWebhook = async ({ title, content }) => {
|
|
|
235
252
|
});
|
|
236
253
|
return await response.json();
|
|
237
254
|
};
|
|
255
|
+
var checkPkgVersion = async (checkPackages) => {
|
|
256
|
+
const currentState = await (0, import_npm_check.default)({
|
|
257
|
+
skipUnused: true,
|
|
258
|
+
ignore: getNonExcludedPackages(checkPackages)
|
|
259
|
+
});
|
|
260
|
+
const pkgs = currentState.get("packages");
|
|
261
|
+
const wrongPkg = pkgs.filter((item) => {
|
|
262
|
+
return checkPackages.includes(item.moduleName) && item.mismatch;
|
|
263
|
+
});
|
|
264
|
+
const errorMessage = wrongPkg.reduce((p, c) => {
|
|
265
|
+
return `${p}
|
|
266
|
+
${c.moduleName}本地版本${c.installed}需升级至${c.packageJson}
|
|
267
|
+
`;
|
|
268
|
+
}, "");
|
|
269
|
+
const isWrongVersion = wrongPkg.length;
|
|
270
|
+
return {
|
|
271
|
+
success: !isWrongVersion,
|
|
272
|
+
message: errorMessage
|
|
273
|
+
};
|
|
274
|
+
};
|
|
238
275
|
// Annotate the CommonJS export names for ESM import in node:
|
|
239
276
|
0 && (module.exports = {
|
|
277
|
+
checkPkgVersion,
|
|
240
278
|
connectServer,
|
|
241
279
|
getCurrentProjectName,
|
|
242
280
|
getCurrentUserName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pisell/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.less"
|
|
6
6
|
],
|
|
@@ -12,12 +12,15 @@
|
|
|
12
12
|
"pisell": "es/bin/pisell.js"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"@aws-sdk/client-s3": "^3.456.0",
|
|
15
16
|
"zx": "^7.2.2",
|
|
16
17
|
"inquirer": "^6.2.6",
|
|
18
|
+
"mime-types": "^2.1.35",
|
|
19
|
+
"npm-check": "^6.0.1",
|
|
17
20
|
"archiver": "^5.3.1",
|
|
18
21
|
"dotenv": "^16.0.3",
|
|
19
22
|
"ssh2": "^1.13.0",
|
|
20
|
-
"@pisell/utils": "1.0.
|
|
23
|
+
"@pisell/utils": "1.0.22"
|
|
21
24
|
},
|
|
22
25
|
"devDependencies": {
|
|
23
26
|
"father": "^4.1.6"
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import mime from 'mime-types';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { getServerConfig } from '../utils/index.js';
|
|
6
|
+
const filterFiles = ['index.html', 'umi.server.js', 'umi.server.d.ts'];
|
|
7
|
+
const __dirname = process.cwd();
|
|
8
|
+
let s3Client = null;
|
|
9
|
+
let bucketName = '';
|
|
10
|
+
|
|
11
|
+
/*******
|
|
12
|
+
* @title: 初始化
|
|
13
|
+
* @description:
|
|
14
|
+
* @return {*}
|
|
15
|
+
* @Author: zhiwei.Wang
|
|
16
|
+
* @Date: 2023-11-24 14:05
|
|
17
|
+
*/
|
|
18
|
+
const init = async () => {
|
|
19
|
+
try {
|
|
20
|
+
// 读取本地config
|
|
21
|
+
const serverConfig = await getServerConfig('admin');
|
|
22
|
+
|
|
23
|
+
// aws配置
|
|
24
|
+
let awsConfig = serverConfig.aws;
|
|
25
|
+
|
|
26
|
+
if (awsConfig) {
|
|
27
|
+
bucketName = awsConfig.bucketName;
|
|
28
|
+
|
|
29
|
+
// 创建实例
|
|
30
|
+
s3Client = new S3Client({
|
|
31
|
+
region: awsConfig.region,
|
|
32
|
+
credentials: {
|
|
33
|
+
accessKeyId: awsConfig.accessKeyId,
|
|
34
|
+
secretAccessKey: awsConfig.secretAccessKey,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
console.log('aws 初始化成功');
|
|
38
|
+
|
|
39
|
+
return serverConfig.aws;
|
|
40
|
+
} else {
|
|
41
|
+
console.log('未获取到aws权限');
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.log(err);
|
|
47
|
+
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// 上传文件到S3指定目录
|
|
53
|
+
const uploadFile = async (directory, fileKey, filePath) => {
|
|
54
|
+
const fileStream = fs.createReadStream(filePath);
|
|
55
|
+
// 根据文件扩展名获取MIME类型
|
|
56
|
+
const contentType = mime.lookup(filePath);
|
|
57
|
+
const uploadParams = {
|
|
58
|
+
Bucket: bucketName,
|
|
59
|
+
Key: `${directory}/${fileKey}`, // 指定目录路径
|
|
60
|
+
Body: fileStream,
|
|
61
|
+
ContentType: contentType,
|
|
62
|
+
ContentDisposition: 'inline',
|
|
63
|
+
ACL: 'public-read', // 设置ACL权限为公共读取
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const command = new PutObjectCommand(uploadParams);
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const response = await s3Client.send(command);
|
|
70
|
+
console.log(`上传成功: ${fileKey}`);
|
|
71
|
+
return { fileName: fileKey, location: response.Location };
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.error(`上传失败: ${fileKey}`, err);
|
|
74
|
+
throw new Error(`上传失败: ${fileKey}, ${err.message}`);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/*******
|
|
79
|
+
* @title: 递归上传文件夹内容
|
|
80
|
+
* @description:
|
|
81
|
+
* @return {*}
|
|
82
|
+
* @Author: zhiwei.Wang
|
|
83
|
+
* @Date: 2023-11-24 14:06
|
|
84
|
+
*/
|
|
85
|
+
export const uploadFolderContents = async (
|
|
86
|
+
directory,
|
|
87
|
+
folderPath = path.resolve(__dirname, 'dist'),
|
|
88
|
+
) => {
|
|
89
|
+
const files = fs.readdirSync(folderPath);
|
|
90
|
+
|
|
91
|
+
// promise all 储存
|
|
92
|
+
const uploadPromises = [];
|
|
93
|
+
for (const file of files) {
|
|
94
|
+
const filePath = path.join(folderPath, file);
|
|
95
|
+
const fileStats = fs.statSync(filePath);
|
|
96
|
+
|
|
97
|
+
// 文件上传, 文件夹递归循环
|
|
98
|
+
if (fileStats.isFile()) {
|
|
99
|
+
const fileKey = path.relative(folderPath, filePath);
|
|
100
|
+
// 过滤不需要上传的文件
|
|
101
|
+
if (!filterFiles.includes(fileKey)) {
|
|
102
|
+
const uploadPromise = uploadFile(directory, fileKey, filePath);
|
|
103
|
+
uploadPromises.push(uploadPromise);
|
|
104
|
+
}
|
|
105
|
+
// 文件夹
|
|
106
|
+
} else if (fileStats.isDirectory()) {
|
|
107
|
+
const subDirectory = path.join(directory, file);
|
|
108
|
+
const subFolderPromise = uploadFolderContents(subDirectory, filePath);
|
|
109
|
+
uploadPromises.push(subFolderPromise);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return Promise.all(uploadPromises)
|
|
114
|
+
.then((res) => {
|
|
115
|
+
console.log('全部上传完成', res.length);
|
|
116
|
+
return res;
|
|
117
|
+
})
|
|
118
|
+
.catch((err) => {
|
|
119
|
+
throw new Error(`上传cdn失败: ${err.message}`);
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/*******
|
|
124
|
+
* @title: 上传资源到oss
|
|
125
|
+
* @description:
|
|
126
|
+
* @return {*}
|
|
127
|
+
* @Author: zhiwei.Wang
|
|
128
|
+
* @Date: 2023-11-24 14:04
|
|
129
|
+
*/
|
|
130
|
+
export const uploadStaticToOSS = async (
|
|
131
|
+
directory,
|
|
132
|
+
folderPath = path.resolve(__dirname, 'dist'),
|
|
133
|
+
) => {
|
|
134
|
+
// 初始化aws
|
|
135
|
+
await init();
|
|
136
|
+
|
|
137
|
+
return uploadFolderContents(directory, folderPath);
|
|
138
|
+
};
|