@teams-max/mwsp 2.0.7 → 2.0.8

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
@@ -4,6 +4,11 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
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
5
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
6
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ 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; }
8
+ 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; }
9
+ 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; }
10
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
12
  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); } }
8
13
  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
14
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
@@ -63,80 +68,173 @@ function pickDependencies(dependencies, isDev) {
63
68
  return "".concat(key, "@").concat(value);
64
69
  });
65
70
  }
66
- //安装Asgard的依赖
67
- function addAsgDependencies(_x2) {
71
+
72
+ //获取需要集成包的依赖
73
+ function addIntegrateDeps(_x2) {
74
+ return _addIntegrateDeps.apply(this, arguments);
75
+ } //安装Asgard的依赖
76
+ function _addIntegrateDeps() {
77
+ _addIntegrateDeps = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(cfg) {
78
+ var infra, ASG_DIR, pkgs, integration, dependencies, devDependencies, asgDependencies, asgDeps, asgDevDeps;
79
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
80
+ while (1) switch (_context.prev = _context.next) {
81
+ case 0:
82
+ infra = cfg.infra, ASG_DIR = cfg.ASG_DIR;
83
+ pkgs = require(join(cwd, 'package.json'));
84
+ integration = pkgs.integration || [];
85
+ if (integration.length) {
86
+ _context.next = 6;
87
+ break;
88
+ }
89
+ logStep("No integration packages are required.");
90
+ return _context.abrupt("return");
91
+ case 6:
92
+ ;
93
+ dependencies = {};
94
+ devDependencies = {};
95
+ _context.prev = 9;
96
+ asgDependencies = require(join(ASG_DIR, 'base', 'integrationDeps.js')) || {};
97
+ dependencies = integration.reduce(function (acc, item) {
98
+ var _asgDependencies$item;
99
+ return _objectSpread(_objectSpread({}, acc), ((_asgDependencies$item = asgDependencies[item]) === null || _asgDependencies$item === void 0 ? void 0 : _asgDependencies$item.dependencies) || {});
100
+ }, {});
101
+ devDependencies = integration.reduce(function (acc, item) {
102
+ var _asgDependencies$item2;
103
+ return _objectSpread(_objectSpread({}, acc), ((_asgDependencies$item2 = asgDependencies[item]) === null || _asgDependencies$item2 === void 0 ? void 0 : _asgDependencies$item2.devDependencies) || {});
104
+ }, {});
105
+ _context.next = 19;
106
+ break;
107
+ case 15:
108
+ _context.prev = 15;
109
+ _context.t0 = _context["catch"](9);
110
+ printErrorAndExit('The Asgard directory does not exist.', "Reason: ".concat(_context.t0.message));
111
+ return _context.abrupt("return");
112
+ case 19:
113
+ asgDeps = pickDependencies(dependencies);
114
+ asgDevDeps = pickDependencies(devDependencies, true);
115
+ if (!((infra == null ? void 0 : infra.arch) === "PRO")) {
116
+ _context.next = 32;
117
+ break;
118
+ }
119
+ _context.t1 = !!asgDeps.length;
120
+ if (!_context.t1) {
121
+ _context.next = 26;
122
+ break;
123
+ }
124
+ _context.next = 26;
125
+ return exec("yarn", ["add"].concat(_toConsumableArray(asgDeps)));
126
+ case 26:
127
+ _context.t2 = !!asgDevDeps.length;
128
+ if (!_context.t2) {
129
+ _context.next = 30;
130
+ break;
131
+ }
132
+ _context.next = 30;
133
+ return exec("yarn", ["add"].concat(_toConsumableArray(asgDevDeps), ["-D"]));
134
+ case 30:
135
+ _context.next = 41;
136
+ break;
137
+ case 32:
138
+ if (!((infra == null ? void 0 : infra.arch) === "MAX")) {
139
+ _context.next = 41;
140
+ break;
141
+ }
142
+ _context.t3 = !!asgDeps.length;
143
+ if (!_context.t3) {
144
+ _context.next = 37;
145
+ break;
146
+ }
147
+ _context.next = 37;
148
+ return exec("pnpm", ["add"].concat(_toConsumableArray(asgDeps)));
149
+ case 37:
150
+ _context.t4 = !!asgDevDeps.length;
151
+ if (!_context.t4) {
152
+ _context.next = 41;
153
+ break;
154
+ }
155
+ _context.next = 41;
156
+ return exec("pnpm", ["add"].concat(_toConsumableArray(asgDevDeps), ["-D"]));
157
+ case 41:
158
+ case "end":
159
+ return _context.stop();
160
+ }
161
+ }, _callee, null, [[9, 15]]);
162
+ }));
163
+ return _addIntegrateDeps.apply(this, arguments);
164
+ }
165
+ function addAsgDependencies(_x3) {
68
166
  return _addAsgDependencies.apply(this, arguments);
69
167
  }
70
168
  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) {
169
+ _addAsgDependencies = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(cfg) {
170
+ var infra, ASG_DIR, dependencies, devDependencies, asgDependencies, asgDeps, asgDevDeps;
171
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
172
+ while (1) switch (_context2.prev = _context2.next) {
75
173
  case 0:
76
174
  infra = cfg.infra, ASG_DIR = cfg.ASG_DIR;
77
175
  dependencies = {};
78
176
  devDependencies = {};
79
- _context.prev = 3;
177
+ _context2.prev = 3;
80
178
  asgDependencies = require(join(ASG_DIR, 'base', 'dependencies.js')) || {};
81
179
  dependencies = asgDependencies.dependencies || {};
82
180
  devDependencies = asgDependencies.devDependencies || {};
83
- _context.next = 13;
181
+ _context2.next = 13;
84
182
  break;
85
183
  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");
184
+ _context2.prev = 9;
185
+ _context2.t0 = _context2["catch"](3);
186
+ printErrorAndExit('The Asgard directory does not exist.', "Reason: ".concat(_context2.t0.message));
187
+ return _context2.abrupt("return");
90
188
  case 13:
91
189
  asgDeps = pickDependencies(dependencies);
92
190
  asgDevDeps = pickDependencies(devDependencies, true);
93
191
  if (!((infra === null || infra === void 0 ? void 0 : infra.arch) === 'PRO')) {
94
- _context.next = 26;
192
+ _context2.next = 26;
95
193
  break;
96
194
  }
97
- _context.t1 = !!asgDeps.length;
98
- if (!_context.t1) {
99
- _context.next = 20;
195
+ _context2.t1 = !!asgDeps.length;
196
+ if (!_context2.t1) {
197
+ _context2.next = 20;
100
198
  break;
101
199
  }
102
- _context.next = 20;
200
+ _context2.next = 20;
103
201
  return exec('yarn', ['add'].concat(_toConsumableArray(asgDeps)));
104
202
  case 20:
105
- _context.t2 = !!asgDevDeps.length;
106
- if (!_context.t2) {
107
- _context.next = 24;
203
+ _context2.t2 = !!asgDevDeps.length;
204
+ if (!_context2.t2) {
205
+ _context2.next = 24;
108
206
  break;
109
207
  }
110
- _context.next = 24;
208
+ _context2.next = 24;
111
209
  return exec('yarn', ['add'].concat(_toConsumableArray(asgDevDeps), ['-D']));
112
210
  case 24:
113
- _context.next = 35;
211
+ _context2.next = 35;
114
212
  break;
115
213
  case 26:
116
214
  if (!((infra === null || infra === void 0 ? void 0 : infra.arch) === 'MAX')) {
117
- _context.next = 35;
215
+ _context2.next = 35;
118
216
  break;
119
217
  }
120
- _context.t3 = !!asgDeps.length;
121
- if (!_context.t3) {
122
- _context.next = 31;
218
+ _context2.t3 = !!asgDeps.length;
219
+ if (!_context2.t3) {
220
+ _context2.next = 31;
123
221
  break;
124
222
  }
125
- _context.next = 31;
223
+ _context2.next = 31;
126
224
  return exec('pnpm', ['add'].concat(_toConsumableArray(asgDeps)));
127
225
  case 31:
128
- _context.t4 = !!asgDevDeps.length;
129
- if (!_context.t4) {
130
- _context.next = 35;
226
+ _context2.t4 = !!asgDevDeps.length;
227
+ if (!_context2.t4) {
228
+ _context2.next = 35;
131
229
  break;
132
230
  }
133
- _context.next = 35;
231
+ _context2.next = 35;
134
232
  return exec('pnpm', ['add'].concat(_toConsumableArray(asgDevDeps), ['-D']));
135
233
  case 35:
136
234
  case "end":
137
- return _context.stop();
235
+ return _context2.stop();
138
236
  }
139
- }, _callee, null, [[3, 9]]);
237
+ }, _callee2, null, [[3, 9]]);
140
238
  }));
141
239
  return _addAsgDependencies.apply(this, arguments);
142
240
  }
@@ -196,42 +294,42 @@ function fetchRemoteRepository() {
196
294
  return _fetchRemoteRepository.apply(this, arguments);
197
295
  }
198
296
  function _fetchRemoteRepository() {
199
- _fetchRemoteRepository = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
297
+ _fetchRemoteRepository = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
200
298
  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) {
299
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
300
+ while (1) switch (_context3.prev = _context3.next) {
203
301
  case 0:
204
302
  cfg = getCfg();
205
303
  infra = cfg.infra, directory = cfg.ASG_DIR, ASG_BRANCH = cfg.ASG_BRANCH, JENKINS_BUILD = cfg.JENKINS_BUILD;
206
304
  remoteUrl = infra.url;
207
305
  doesExist = checkDirectoryExistsSync(directory);
208
306
  if (doesExist) {
209
- _context2.next = 14;
307
+ _context3.next = 14;
210
308
  break;
211
309
  }
212
310
  logStep('Cloning the repository from GitHub...');
213
311
  execa.sync('git', ['clone', '-b', 'feature-asg', remoteUrl, directory]);
214
312
  logStep('Cloning completed.');
215
313
  logStep('Installing dependencies...');
216
- _context2.next = 11;
314
+ _context3.next = 11;
217
315
  return addAsgDependencies(cfg);
218
316
  case 11:
219
317
  logStep('Installation completed.');
220
- _context2.next = 26;
318
+ _context3.next = 26;
221
319
  break;
222
320
  case 14:
223
321
  if (!(JENKINS_BUILD && !ASG_BRANCH)) {
224
- _context2.next = 19;
322
+ _context3.next = 19;
225
323
  break;
226
324
  }
227
325
  logStep('Jenkins build detected. Skipping sync up.');
228
- return _context2.abrupt("return");
326
+ return _context3.abrupt("return");
229
327
  case 19:
230
328
  if (JENKINS_BUILD) {
231
- _context2.next = 26;
329
+ _context3.next = 26;
232
330
  break;
233
331
  }
234
- _context2.next = 22;
332
+ _context3.next = 22;
235
333
  return inquirer.prompt([{
236
334
  type: 'confirm',
237
335
  name: 'syncUp',
@@ -239,32 +337,32 @@ function _fetchRemoteRepository() {
239
337
  default: 'Y'
240
338
  }]);
241
339
  case 22:
242
- _yield$inquirer$promp = _context2.sent;
340
+ _yield$inquirer$promp = _context3.sent;
243
341
  syncUp = _yield$inquirer$promp.syncUp;
244
342
  if (syncUp) {
245
- _context2.next = 26;
343
+ _context3.next = 26;
246
344
  break;
247
345
  }
248
- return _context2.abrupt("return");
346
+ return _context3.abrupt("return");
249
347
  case 26:
250
348
  if (!(!doesExist && JENKINS_BUILD && !ASG_BRANCH)) {
251
- _context2.next = 29;
349
+ _context3.next = 29;
252
350
  break;
253
351
  }
254
352
  printErrorAndExit('Jenkins build detected. The branch parameter is missing!');
255
- return _context2.abrupt("return");
353
+ return _context3.abrupt("return");
256
354
  case 29:
257
355
  logStep('Synchronizing with the remote repository...');
258
356
  process.chdir(directory);
259
- _context2.prev = 31;
357
+ _context3.prev = 31;
260
358
  execa.sync('git', ['fetch', 'origin', '--prune']);
261
359
  if (!(JENKINS_BUILD && ASG_BRANCH)) {
262
- _context2.next = 38;
360
+ _context3.next = 38;
263
361
  break;
264
362
  }
265
363
  execa.sync('git', ['checkout', ASG_BRANCH]);
266
364
  logStep("Anto switched to branch:", ASG_BRANCH);
267
- _context2.next = 48;
365
+ _context3.next = 59;
268
366
  break;
269
367
  case 38:
270
368
  // 获取远程分支列表
@@ -286,7 +384,7 @@ function _fetchRemoteRepository() {
286
384
  }
287
385
 
288
386
  // 提示用户选择分支
289
- _context2.next = 46;
387
+ _context3.next = 46;
290
388
  return inquirer.prompt([{
291
389
  type: 'list',
292
390
  name: 'branch',
@@ -300,29 +398,36 @@ function _fetchRemoteRepository() {
300
398
  }
301
399
  }]);
302
400
  case 46:
303
- questions = _context2.sent;
304
- // 切换分支,增加错误处理
305
- try {
306
- execa.sync('git', ['checkout', '-q', questions.branch]);
307
- logStep("Switched to branch:", questions.branch);
308
- } catch (error) {
309
- printErrorAndExit("Failed to switch to branch '".concat(questions.branch, "'. Reason: ").concat(error.message));
310
- }
311
- case 48:
312
- _context2.next = 53;
401
+ questions = _context3.sent;
402
+ _context3.prev = 47;
403
+ execa.sync('git', ['checkout', '-q', questions.branch]);
404
+ logStep("Switched to branch:", questions.branch);
405
+ logStep('Installing dependencies...');
406
+ _context3.next = 53;
407
+ return addIntegrateDeps(cfg);
408
+ case 53:
409
+ logStep('Installation completed.');
410
+ _context3.next = 59;
411
+ break;
412
+ case 56:
413
+ _context3.prev = 56;
414
+ _context3.t0 = _context3["catch"](47);
415
+ printErrorAndExit("Failed to switch to branch '".concat(questions.branch, "'. Reason: ").concat(_context3.t0.message));
416
+ case 59:
417
+ _context3.next = 64;
313
418
  break;
314
- case 50:
315
- _context2.prev = 50;
316
- _context2.t0 = _context2["catch"](31);
419
+ case 61:
420
+ _context3.prev = 61;
421
+ _context3.t1 = _context3["catch"](31);
317
422
  // 获取分支列表时的错误处理
318
- printErrorAndExit("An error occurred while fetching remote branches: ".concat(_context2.t0.message));
319
- case 53:
423
+ printErrorAndExit("An error occurred while fetching remote branches: ".concat(_context3.t1.message));
424
+ case 64:
320
425
  process.chdir(cwd);
321
- case 54:
426
+ case 65:
322
427
  case "end":
323
- return _context2.stop();
428
+ return _context3.stop();
324
429
  }
325
- }, _callee2, null, [[31, 50]]);
430
+ }, _callee3, null, [[31, 61], [47, 56]]);
326
431
  }));
327
432
  return _fetchRemoteRepository.apply(this, arguments);
328
433
  }
@@ -35,12 +35,56 @@ function pickDependencies(dependencies, isDev) {
35
35
  );
36
36
  return dependenciesList.map(([key, value]) => `${key}@${value}`);
37
37
  }
38
+ async function addIntegrateDeps(cfg) {
39
+ const { infra, ASG_DIR } = cfg;
40
+ const pkgs = require(join(cwd, "package.json"));
41
+ const integration = pkgs.integration || [];
42
+ if (!integration.length) {
43
+ logStep("No integration packages are required.");
44
+ return;
45
+ }
46
+ ;
47
+ let dependencies = {};
48
+ let devDependencies = {};
49
+ try {
50
+ const asgDependencies = require(join(ASG_DIR, "base", "integrationDeps.js")) || {};
51
+ dependencies = integration.reduce((acc, item) => {
52
+ var _a;
53
+ return {
54
+ ...acc,
55
+ ...((_a = asgDependencies[item]) == null ? void 0 : _a.dependencies) || {}
56
+ };
57
+ }, {});
58
+ devDependencies = integration.reduce((acc, item) => {
59
+ var _a;
60
+ return {
61
+ ...acc,
62
+ ...((_a = asgDependencies[item]) == null ? void 0 : _a.devDependencies) || {}
63
+ };
64
+ }, {});
65
+ } catch (error) {
66
+ printErrorAndExit(
67
+ "The Asgard directory does not exist.",
68
+ `Reason: ${error.message}`
69
+ );
70
+ return;
71
+ }
72
+ const asgDeps = pickDependencies(dependencies);
73
+ const asgDevDeps = pickDependencies(devDependencies, true);
74
+ if ((infra == null ? void 0 : infra.arch) === "PRO") {
75
+ !!asgDeps.length && await exec("yarn", ["add", ...asgDeps]);
76
+ !!asgDevDeps.length && await exec("yarn", ["add", ...asgDevDeps, "-D"]);
77
+ } else if ((infra == null ? void 0 : infra.arch) === "MAX") {
78
+ !!asgDeps.length && await exec("pnpm", ["add", ...asgDeps]);
79
+ !!asgDevDeps.length && await exec("pnpm", ["add", ...asgDevDeps, "-D"]);
80
+ }
81
+ }
38
82
  async function addAsgDependencies(cfg) {
39
83
  const { infra, ASG_DIR } = cfg;
40
84
  let dependencies = {};
41
85
  let devDependencies = {};
42
86
  try {
43
- asgDependencies = require(join(ASG_DIR, "base", "dependencies.js")) || {};
87
+ const asgDependencies = require(join(ASG_DIR, "base", "dependencies.js")) || {};
44
88
  dependencies = asgDependencies.dependencies || {};
45
89
  devDependencies = asgDependencies.devDependencies || {};
46
90
  } catch (error) {
@@ -179,6 +223,9 @@ async function fetchRemoteRepository() {
179
223
  try {
180
224
  execa.sync("git", ["checkout", "-q", questions.branch]);
181
225
  logStep(`Switched to branch:`, questions.branch);
226
+ logStep("Installing dependencies...");
227
+ await addIntegrateDeps(cfg);
228
+ logStep("Installation completed.");
182
229
  } catch (error) {
183
230
  printErrorAndExit(
184
231
  `Failed to switch to branch '${questions.branch}'. Reason: ${error.message}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teams-max/mwsp",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
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": {