@teams-max/mwsp 2.0.4 → 2.0.5

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/utils/index.js CHANGED
@@ -2,12 +2,16 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2
2
  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; }
3
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
4
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
- 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); }
6
5
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
6
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
- 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; }
9
7
  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); } }
10
8
  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); }); }; }
9
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ 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); }
12
+ 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; }
13
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
14
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
15
  var fs = require('fs');
12
16
  var _require = require('path'),
13
17
  join = _require.join;
@@ -43,13 +47,98 @@ function printErrorAndExit() {
43
47
  }
44
48
  function pickDependencies(dependencies, isDev) {
45
49
  var pkgs = require(join(cwd, 'package.json'));
46
- return dependencies.filter(function (p) {
50
+ var dependenciesList = Object.entries(dependencies || {}).filter(function (_ref) {
51
+ var _ref2 = _slicedToArray(_ref, 1),
52
+ key = _ref2[0];
47
53
  if (isDev) {
48
- return !pkgs.devDependencies[p];
54
+ return !pkgs.devDependencies[key];
49
55
  } else {
50
- return !pkgs.dependencies[p];
56
+ return !pkgs.dependencies[key];
51
57
  }
52
58
  });
59
+ return dependenciesList.map(function (_ref3) {
60
+ var _ref4 = _slicedToArray(_ref3, 2),
61
+ key = _ref4[0],
62
+ value = _ref4[1];
63
+ return "".concat(key, "@").concat(value);
64
+ });
65
+ }
66
+ //安装Asgard的依赖
67
+ function addAsgDependencies(_x2) {
68
+ return _addAsgDependencies.apply(this, arguments);
69
+ }
70
+ function _addAsgDependencies() {
71
+ _addAsgDependencies = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(cfg) {
72
+ var infra, ASG_DIR, dependencies, devDependencies, asgDeps, asgDevDeps;
73
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
74
+ while (1) switch (_context.prev = _context.next) {
75
+ case 0:
76
+ infra = cfg.infra, ASG_DIR = cfg.ASG_DIR;
77
+ dependencies = {};
78
+ devDependencies = {};
79
+ _context.prev = 3;
80
+ asgDependencies = require(join(ASG_DIR, 'base', 'dependencies.js')) || {};
81
+ dependencies = asgDependencies.dependencies || {};
82
+ devDependencies = asgDependencies.devDependencies || {};
83
+ _context.next = 13;
84
+ break;
85
+ case 9:
86
+ _context.prev = 9;
87
+ _context.t0 = _context["catch"](3);
88
+ printErrorAndExit('The Asgard directory does not exist.', "Reason: ".concat(_context.t0.message));
89
+ return _context.abrupt("return");
90
+ case 13:
91
+ asgDeps = pickDependencies(dependencies);
92
+ asgDevDeps = pickDependencies(devDependencies, true);
93
+ if (!((infra === null || infra === void 0 ? void 0 : infra.arch) === 'PRO')) {
94
+ _context.next = 26;
95
+ break;
96
+ }
97
+ _context.t1 = !!asgDeps.length;
98
+ if (!_context.t1) {
99
+ _context.next = 20;
100
+ break;
101
+ }
102
+ _context.next = 20;
103
+ return exec('yarn', ['add'].concat(_toConsumableArray(asgDeps)));
104
+ case 20:
105
+ _context.t2 = !!asgDevDeps.length;
106
+ if (!_context.t2) {
107
+ _context.next = 24;
108
+ break;
109
+ }
110
+ _context.next = 24;
111
+ return exec('yarn', ['add'].concat(_toConsumableArray(asgDevDeps), ['-D']));
112
+ case 24:
113
+ _context.next = 35;
114
+ break;
115
+ case 26:
116
+ if (!((infra === null || infra === void 0 ? void 0 : infra.arch) === 'MAX')) {
117
+ _context.next = 35;
118
+ break;
119
+ }
120
+ _context.t3 = !!asgDeps.length;
121
+ if (!_context.t3) {
122
+ _context.next = 31;
123
+ break;
124
+ }
125
+ _context.next = 31;
126
+ return exec('pnpm', ['add'].concat(_toConsumableArray(asgDeps)));
127
+ case 31:
128
+ _context.t4 = !!asgDevDeps.length;
129
+ if (!_context.t4) {
130
+ _context.next = 35;
131
+ break;
132
+ }
133
+ _context.next = 35;
134
+ return exec('pnpm', ['add'].concat(_toConsumableArray(asgDevDeps), ['-D']));
135
+ case 35:
136
+ case "end":
137
+ return _context.stop();
138
+ }
139
+ }, _callee, null, [[3, 9]]);
140
+ }));
141
+ return _addAsgDependencies.apply(this, arguments);
53
142
  }
54
143
  function getCfg() {
55
144
  var pkgs = require(join(cwd, 'package.json'));
@@ -107,121 +196,77 @@ function fetchRemoteRepository() {
107
196
  return _fetchRemoteRepository.apply(this, arguments);
108
197
  }
109
198
  function _fetchRemoteRepository() {
110
- _fetchRemoteRepository = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
111
- var cfg, infra, directory, ASG_BRANCH, JENKINS_BUILD, remoteUrl, doesExist, proDevDeps, proDeps, maxDevDeps, maxDeps, _yield$inquirer$promp, syncUp, infraBranchsOutput, infraBranchArray, filteredBranches, defaultBrancheIdx, questions;
112
- return _regeneratorRuntime().wrap(function _callee$(_context) {
113
- while (1) switch (_context.prev = _context.next) {
199
+ _fetchRemoteRepository = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
200
+ var cfg, infra, directory, ASG_BRANCH, JENKINS_BUILD, remoteUrl, doesExist, _yield$inquirer$promp, syncUp, infraBranchsOutput, infraBranchArray, filteredBranches, defaultBrancheIdx, questions;
201
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
202
+ while (1) switch (_context2.prev = _context2.next) {
114
203
  case 0:
115
204
  cfg = getCfg();
116
205
  infra = cfg.infra, directory = cfg.ASG_DIR, ASG_BRANCH = cfg.ASG_BRANCH, JENKINS_BUILD = cfg.JENKINS_BUILD;
117
206
  remoteUrl = infra.url;
118
207
  doesExist = checkDirectoryExistsSync(directory);
119
208
  if (doesExist) {
120
- _context.next = 36;
209
+ _context2.next = 14;
121
210
  break;
122
211
  }
123
212
  logStep('Cloning the repository from GitHub...');
124
213
  execa.sync('git', ['clone', '-b', 'feature-asg', remoteUrl, directory]);
125
214
  logStep('Cloning completed.');
126
215
  logStep('Installing dependencies...');
127
- if (!((infra === null || infra === void 0 ? void 0 : infra.arch) === 'PRO')) {
128
- _context.next = 22;
129
- break;
130
- }
131
- proDevDeps = pickDependencies(['snb-mock-middleware', 'lodash-webpack-plugin'], true);
132
- _context.t0 = !!proDevDeps.length;
133
- if (!_context.t0) {
134
- _context.next = 15;
135
- break;
136
- }
137
- _context.next = 15;
138
- return exec('yarn', ['add'].concat(_toConsumableArray(proDevDeps), ['-D']));
139
- case 15:
140
- proDeps = pickDependencies(['@teams-max/skynet', 'history']);
141
- _context.t1 = !!proDeps.length;
142
- if (!_context.t1) {
143
- _context.next = 20;
144
- break;
145
- }
146
- _context.next = 20;
147
- return exec('yarn', ['add'].concat(_toConsumableArray(proDeps)));
148
- case 20:
149
- _context.next = 33;
150
- break;
151
- case 22:
152
- if (!((infra === null || infra === void 0 ? void 0 : infra.arch) === 'MAX')) {
153
- _context.next = 33;
154
- break;
155
- }
156
- maxDevDeps = pickDependencies(['axios'], true);
157
- _context.t2 = !!maxDevDeps.length;
158
- if (!_context.t2) {
159
- _context.next = 28;
160
- break;
161
- }
162
- _context.next = 28;
163
- return exec('pnpm', ['add'].concat(_toConsumableArray(maxDevDeps), ['-D']));
164
- case 28:
165
- maxDeps = pickDependencies(['@teams-max/skynet', 'classnames', 'qs', 'uuid', 'react-draggable', 'lodash', 'moment', 'dayjs']);
166
- _context.t3 = !!maxDeps.length;
167
- if (!_context.t3) {
168
- _context.next = 33;
169
- break;
170
- }
171
- _context.next = 33;
172
- return exec('pnpm', ['add'].concat(_toConsumableArray(maxDeps)));
173
- case 33:
216
+ _context2.next = 11;
217
+ return addAsgDependencies(cfg);
218
+ case 11:
174
219
  logStep('Installation completed.');
175
- _context.next = 48;
220
+ _context2.next = 26;
176
221
  break;
177
- case 36:
222
+ case 14:
178
223
  if (!(JENKINS_BUILD && !ASG_BRANCH)) {
179
- _context.next = 41;
224
+ _context2.next = 19;
180
225
  break;
181
226
  }
182
227
  logStep('Jenkins build detected. Skipping sync up.');
183
- return _context.abrupt("return");
184
- case 41:
228
+ return _context2.abrupt("return");
229
+ case 19:
185
230
  if (JENKINS_BUILD) {
186
- _context.next = 48;
231
+ _context2.next = 26;
187
232
  break;
188
233
  }
189
- _context.next = 44;
234
+ _context2.next = 22;
190
235
  return inquirer.prompt([{
191
236
  type: 'confirm',
192
237
  name: 'syncUp',
193
238
  message: '同步远端仓库',
194
239
  default: 'Y'
195
240
  }]);
196
- case 44:
197
- _yield$inquirer$promp = _context.sent;
241
+ case 22:
242
+ _yield$inquirer$promp = _context2.sent;
198
243
  syncUp = _yield$inquirer$promp.syncUp;
199
244
  if (syncUp) {
200
- _context.next = 48;
245
+ _context2.next = 26;
201
246
  break;
202
247
  }
203
- return _context.abrupt("return");
204
- case 48:
248
+ return _context2.abrupt("return");
249
+ case 26:
205
250
  if (!(!doesExist && JENKINS_BUILD && !ASG_BRANCH)) {
206
- _context.next = 51;
251
+ _context2.next = 29;
207
252
  break;
208
253
  }
209
254
  printErrorAndExit('Jenkins build detected. The branch parameter is missing!');
210
- return _context.abrupt("return");
211
- case 51:
255
+ return _context2.abrupt("return");
256
+ case 29:
212
257
  logStep('Synchronizing with the remote repository...');
213
258
  process.chdir(directory);
214
- _context.prev = 53;
259
+ _context2.prev = 31;
215
260
  execa.sync('git', ['fetch', 'origin', '--prune']);
216
261
  if (!(JENKINS_BUILD && ASG_BRANCH)) {
217
- _context.next = 60;
262
+ _context2.next = 38;
218
263
  break;
219
264
  }
220
265
  execa.sync('git', ['checkout', ASG_BRANCH]);
221
266
  logStep("Anto switched to branch:", ASG_BRANCH);
222
- _context.next = 70;
267
+ _context2.next = 48;
223
268
  break;
224
- case 60:
269
+ case 38:
225
270
  // 获取远程分支列表
226
271
  infraBranchsOutput = execa.sync('git', ['branch', '-r']).stdout; // 处理分支列表
227
272
  infraBranchArray = infraBranchsOutput.trim().split('\n');
@@ -241,7 +286,7 @@ function _fetchRemoteRepository() {
241
286
  }
242
287
 
243
288
  // 提示用户选择分支
244
- _context.next = 68;
289
+ _context2.next = 46;
245
290
  return inquirer.prompt([{
246
291
  type: 'list',
247
292
  name: 'branch',
@@ -254,8 +299,8 @@ function _fetchRemoteRepository() {
254
299
  return true;
255
300
  }
256
301
  }]);
257
- case 68:
258
- questions = _context.sent;
302
+ case 46:
303
+ questions = _context2.sent;
259
304
  // 切换分支,增加错误处理
260
305
  try {
261
306
  execa.sync('git', ['checkout', '-q', questions.branch]);
@@ -263,21 +308,21 @@ function _fetchRemoteRepository() {
263
308
  } catch (error) {
264
309
  printErrorAndExit("Failed to switch to branch '".concat(questions.branch, "'. Reason: ").concat(error.message));
265
310
  }
266
- case 70:
267
- _context.next = 75;
311
+ case 48:
312
+ _context2.next = 53;
268
313
  break;
269
- case 72:
270
- _context.prev = 72;
271
- _context.t4 = _context["catch"](53);
314
+ case 50:
315
+ _context2.prev = 50;
316
+ _context2.t0 = _context2["catch"](31);
272
317
  // 获取分支列表时的错误处理
273
- printErrorAndExit("An error occurred while fetching remote branches: ".concat(_context.t4.message));
274
- case 75:
318
+ printErrorAndExit("An error occurred while fetching remote branches: ".concat(_context2.t0.message));
319
+ case 53:
275
320
  process.chdir(cwd);
276
- case 76:
321
+ case 54:
277
322
  case "end":
278
- return _context.stop();
323
+ return _context2.stop();
279
324
  }
280
- }, _callee, null, [[53, 72]]);
325
+ }, _callee2, null, [[31, 50]]);
281
326
  }));
282
327
  return _fetchRemoteRepository.apply(this, arguments);
283
328
  }
@@ -24,13 +24,46 @@ function printErrorAndExit(...args) {
24
24
  }
25
25
  function pickDependencies(dependencies, isDev) {
26
26
  const pkgs = require(join(cwd, "package.json"));
27
- return dependencies.filter((p) => {
27
+ const dependenciesList = Object.entries(dependencies || {}).filter(([key]) => {
28
28
  if (isDev) {
29
- return !pkgs.devDependencies[p];
29
+ return !pkgs.devDependencies[key];
30
30
  } else {
31
- return !pkgs.dependencies[p];
31
+ return !pkgs.dependencies[key];
32
32
  }
33
33
  });
34
+ return dependenciesList.map(([key, value]) => `${key}@${value}`);
35
+ }
36
+ async function addAsgDependencies(cfg) {
37
+ const { infra, ASG_DIR } = cfg;
38
+ let dependencies = {};
39
+ let devDependencies = {};
40
+ try {
41
+ asgDependencies = require(join(
42
+ ASG_DIR,
43
+ "base",
44
+ "dependencies.js"
45
+ )) || {};
46
+ dependencies = asgDependencies.dependencies || {};
47
+ devDependencies = asgDependencies.devDependencies || {};
48
+ } catch (error) {
49
+ printErrorAndExit(
50
+ "The Asgard directory does not exist.",
51
+ `Reason: ${error.message}`
52
+ );
53
+ return;
54
+ }
55
+ const asgDeps = pickDependencies(dependencies);
56
+ const asgDevDeps = pickDependencies(
57
+ devDependencies,
58
+ true
59
+ );
60
+ if ((infra == null ? void 0 : infra.arch) === "PRO") {
61
+ !!asgDeps.length && await exec("yarn", ["add", ...asgDeps]);
62
+ !!asgDevDeps.length && await exec("yarn", ["add", ...asgDevDeps, "-D"]);
63
+ } else if ((infra == null ? void 0 : infra.arch) === "MAX") {
64
+ !!asgDeps.length && await exec("pnpm", ["add", ...asgDeps]);
65
+ !!asgDevDeps.length && await exec("pnpm", ["add", ...asgDevDeps, "-D"]);
66
+ }
34
67
  }
35
68
  function getCfg() {
36
69
  const pkgs = require(join(cwd, "package.json"));
@@ -88,29 +121,7 @@ async function fetchRemoteRepository() {
88
121
  execa.sync("git", ["clone", "-b", "feature-asg", remoteUrl, directory]);
89
122
  logStep("Cloning completed.");
90
123
  logStep("Installing dependencies...");
91
- if ((infra == null ? void 0 : infra.arch) === "PRO") {
92
- const proDevDeps = pickDependencies(
93
- ["snb-mock-middleware", "lodash-webpack-plugin"],
94
- true
95
- );
96
- !!proDevDeps.length && await exec("yarn", ["add", ...proDevDeps, "-D"]);
97
- const proDeps = pickDependencies(["@teams-max/skynet", "history"]);
98
- !!proDeps.length && await exec("yarn", ["add", ...proDeps]);
99
- } else if ((infra == null ? void 0 : infra.arch) === "MAX") {
100
- const maxDevDeps = pickDependencies(["axios"], true);
101
- !!maxDevDeps.length && await exec("pnpm", ["add", ...maxDevDeps, "-D"]);
102
- const maxDeps = pickDependencies([
103
- "@teams-max/skynet",
104
- "classnames",
105
- "qs",
106
- "uuid",
107
- "react-draggable",
108
- "lodash",
109
- "moment",
110
- "dayjs"
111
- ]);
112
- !!maxDeps.length && await exec("pnpm", ["add", ...maxDeps]);
113
- }
124
+ await addAsgDependencies(cfg);
114
125
  logStep("Installation completed.");
115
126
  } else if (JENKINS_BUILD && !ASG_BRANCH) {
116
127
  logStep("Jenkins build detected. Skipping sync up.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teams-max/mwsp",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "@teams-max/mwsp",
5
5
  "homepage": "https://gitlab.daikuan.qihoo.net/efficacy-fe/teams-max/-/tree/master/packages/mwsp",
6
6
  "repository": {