@lingxiteam/ebe-utils 0.0.16 → 0.0.18

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/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export declare const treeForEach: (tree: any, callback: (item: any, root: boolea
8
8
  children: string;
9
9
  }) => void;
10
10
  export declare const getPageDsls: (resultObjects: any[]) => any[];
11
+ export declare function findAllItem<T = any>(target: T[], callback: (item: T, index: number, list: T[]) => boolean, itemHash: any): void;
11
12
  export declare function findItem<T = any>(target: T[], callback: (item: T, index: number, list: T[]) => boolean): T | null;
12
13
  export declare const cleanTree: (tree: any, fields: any) => any;
13
14
  export declare const clearLXPagesDSL: (pages: any[]) => any[];
@@ -76,6 +77,7 @@ export declare const fetchData: ({ appId, services, platform, baseUrl, onProgres
76
77
  appInfo: Record<string, any>;
77
78
  pagePathEnglishMapping: any;
78
79
  incrementalConstruction: IncrementalConstruction | undefined;
80
+ pageTypeMap: any;
79
81
  };
80
82
  cleanedTree: any;
81
83
  }>;
package/es/index.js CHANGED
@@ -156,28 +156,25 @@ export var getPageDsls = function getPageDsls(resultObjects) {
156
156
  }
157
157
  }).filter(Boolean);
158
158
  };
159
- // export function findAllItem<T = any>(
160
- // target: T[],
161
- // callback: (item: T, index: number, list: T[]) => boolean,
162
- // itemHash: any,
163
- // ) {
164
- // const list = target;
165
- // // Makes sures is always has an positive integer as length.
166
- // // eslint-disable-next-line
167
- // const length = list.length >>> 0;
168
- // // eslint-disable-next-line
169
- // const thisArg = arguments[1];
170
- // for (let i = 0; i < length; ) {
171
- // const element = list[i] as any;
172
- // if (callback.call(thisArg, element, i, list)) {
173
- // itemHash[element?.props?.busiCompId ?? ''] = 1;
174
- // }
175
- // i += 1;
176
- // if (element?.components) {
177
- // findAllItem(element?.components, callback, itemHash);
178
- // }
179
- // }
180
- // }
159
+ export function findAllItem(target, callback, itemHash) {
160
+ var list = target;
161
+ // Makes sures is always has an positive integer as length.
162
+ // eslint-disable-next-line
163
+ var length = list.length >>> 0;
164
+ // eslint-disable-next-line
165
+ var thisArg = arguments[1];
166
+ for (var i = 0; i < length;) {
167
+ var element = list[i];
168
+ if (callback.call(thisArg, element, i, list)) {
169
+ var _element$props$busiCo, _element$props;
170
+ itemHash[(_element$props$busiCo = element === null || element === void 0 || (_element$props = element.props) === null || _element$props === void 0 ? void 0 : _element$props.busiCompId) !== null && _element$props$busiCo !== void 0 ? _element$props$busiCo : ''] = 1;
171
+ }
172
+ i += 1;
173
+ if (element !== null && element !== void 0 && element.components) {
174
+ findAllItem(element === null || element === void 0 ? void 0 : element.components, callback, itemHash);
175
+ }
176
+ }
177
+ }
181
178
  export function findItem(target, callback) {
182
179
  var list = target;
183
180
  // Makes sures is always has an positive integer as length.
@@ -253,14 +250,14 @@ var getIsIncrementalConstruction = function getIsIncrementalConstruction(ic) {
253
250
  export var fetchData = /*#__PURE__*/function () {
254
251
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
255
252
  var _ref6, _attrSpecPage;
256
- var appId, services, platform, baseUrl, onProgress, needTranslatePagePathToEnglish, incrementalConstruction, isIncrementalConstruction, attrSpecPage, appPageList, globalDataInfo, busiData, themeCss, frontendHookList, globalDataMap, appInfo, temCompAssetList, compAssetList, _globalDataInfo, dataSourceList, pageIdMapping, lastPageId, data, pages, _yield$services$qryBu, itemLists, _incrementalConstruct, busiPages, getTranslateName, chinese, translateNames, key, _translateNames, pagePathEnglishMapping, pagePathEnglishSet, getName, pagesChinese, pagesTranslateNames, _key, _pages$_key$pageConta, _pagePathEnglishMappi, _pagesTranslateNames, safeTranslateName, pageDSLS, getPlatform, options, cleanedTree;
253
+ var appId, services, platform, baseUrl, onProgress, needTranslatePagePathToEnglish, incrementalConstruction, isIncrementalConstruction, attrSpecPage, incrementalConstructionPageList, globalDataInfo, busiData, themeCss, frontendHookList, pageTypeMap, globalDataMap, appInfo, appPageList, temCompAssetList, compAssetList, _globalDataInfo, dataSourceList, pageIdMapping, lastPageId, data, needFindDataPages, pages, _yield$services$qryBu, itemLists, _incrementalConstruct, itemHash, _itemLists, alllBusiComp, busiPages, getTranslateName, chinese, translateNames, key, _translateNames, pagePathEnglishMapping, pagePathEnglishSet, getName, pagesChinese, pagesTranslateNames, findPageKeyByPageId, _key2, _appPageList$_key2$pa, _pagePathEnglishMappi, _pagesTranslateNames, safeTranslateName, pageKey, pageDSLS, getPlatform, options, cleanedTree;
257
254
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
258
255
  while (1) switch (_context3.prev = _context3.next) {
259
256
  case 0:
260
257
  appId = _ref4.appId, services = _ref4.services, platform = _ref4.platform, baseUrl = _ref4.baseUrl, onProgress = _ref4.onProgress, needTranslatePagePathToEnglish = _ref4.needTranslatePagePathToEnglish, incrementalConstruction = _ref4.incrementalConstruction;
261
258
  isIncrementalConstruction = getIsIncrementalConstruction(incrementalConstruction);
262
259
  attrSpecPage = {};
263
- appPageList = (_ref6 = (incrementalConstruction === null || incrementalConstruction === void 0 ? void 0 : incrementalConstruction.pageIds) || []) === null || _ref6 === void 0 ? void 0 : _ref6.map(function (i) {
260
+ incrementalConstructionPageList = (_ref6 = (incrementalConstruction === null || incrementalConstruction === void 0 ? void 0 : incrementalConstruction.pageIds) || []) === null || _ref6 === void 0 ? void 0 : _ref6.map(function (i) {
264
261
  return {
265
262
  pageId: i
266
263
  };
@@ -269,54 +266,64 @@ export var fetchData = /*#__PURE__*/function () {
269
266
  busiData = [];
270
267
  themeCss = '';
271
268
  frontendHookList = [];
269
+ pageTypeMap = {};
272
270
  globalDataMap = {};
273
- _context3.next = 11;
271
+ _context3.next = 12;
274
272
  return services.findApplication({
275
273
  appId: appId
276
274
  });
277
- case 11:
275
+ case 12:
278
276
  appInfo = _context3.sent;
279
277
  onProgress({
280
278
  log: '获取应用信息',
281
279
  progress: 1
282
280
  });
283
281
  if (!(!isIncrementalConstruction || incrementalConstruction !== null && incrementalConstruction !== void 0 && incrementalConstruction.frontendHookChange)) {
284
- _context3.next = 17;
282
+ _context3.next = 18;
285
283
  break;
286
284
  }
287
- _context3.next = 16;
285
+ _context3.next = 17;
288
286
  return services.queryFrontendHookList({
289
287
  appId: appId
290
288
  });
291
- case 16:
292
- frontendHookList = _context3.sent;
293
289
  case 17:
294
- if (isIncrementalConstruction) {
295
- _context3.next = 35;
296
- break;
297
- }
298
- _context3.next = 20;
299
- return services.qryAttrSpecPage({
300
- appId: appId,
301
- pageNum: 1,
302
- pageSize: 999999
303
- });
304
- case 20:
305
- attrSpecPage = _context3.sent;
290
+ frontendHookList = _context3.sent;
291
+ case 18:
306
292
  onProgress({
307
293
  log: '获取当前应用的全部页面',
308
294
  progress: 2
309
295
  });
310
296
  // 根据 appId 获取当前应用的全部页面
311
- _context3.next = 24;
297
+ _context3.next = 21;
312
298
  return services.qryPageInstListByAppId({
313
299
  appId: appId,
314
300
  terminalType: platform
315
301
  });
316
- case 24:
302
+ case 21:
317
303
  appPageList = _context3.sent;
318
- _context3.prev = 25;
319
- _context3.next = 28;
304
+ appPageList.forEach(function (o) {
305
+ if (o.pageContainerType === 'Drawer') {
306
+ var _o$pageContainerType, _pageTypeMap$_o$pageC;
307
+ (_pageTypeMap$_o$pageC = pageTypeMap[_o$pageContainerType = o.pageContainerType]) !== null && _pageTypeMap$_o$pageC !== void 0 ? _pageTypeMap$_o$pageC : pageTypeMap[_o$pageContainerType] = {};
308
+ pageTypeMap[o.pageContainerType][o.pageId] = true;
309
+ }
310
+ // pageTypeMap[o.pageContainerType] ??= {};
311
+ // pageTypeMap[o.pageContainerType][o.pageId] = true;
312
+ });
313
+ if (isIncrementalConstruction) {
314
+ _context3.next = 37;
315
+ break;
316
+ }
317
+ _context3.next = 26;
318
+ return services.qryAttrSpecPage({
319
+ appId: appId,
320
+ pageNum: 1,
321
+ pageSize: 999999
322
+ });
323
+ case 26:
324
+ attrSpecPage = _context3.sent;
325
+ _context3.prev = 27;
326
+ _context3.next = 30;
320
327
  return Promise.race([new Promise(function (resolve, reject) {
321
328
  services.getThemeCss({
322
329
  appId: appId,
@@ -329,26 +336,26 @@ export var fetchData = /*#__PURE__*/function () {
329
336
  resolve('');
330
337
  }, 5000);
331
338
  })]);
332
- case 28:
339
+ case 30:
333
340
  themeCss = _context3.sent;
334
341
  console.log('====获取主题成功');
335
- _context3.next = 35;
342
+ _context3.next = 37;
336
343
  break;
337
- case 32:
338
- _context3.prev = 32;
339
- _context3.t0 = _context3["catch"](25);
344
+ case 34:
345
+ _context3.prev = 34;
346
+ _context3.t0 = _context3["catch"](27);
340
347
  console.error('====获取主题失败', _context3.t0);
341
- case 35:
348
+ case 37:
342
349
  // 根据 appId 获取当前应用的使用的自定义组件
343
350
  onProgress({
344
351
  log: '获取当前应用的使用的自定义组件',
345
352
  progress: 3
346
353
  });
347
- _context3.next = 38;
354
+ _context3.next = 40;
348
355
  return services.qryPageCompAssetList({
349
356
  appId: appId
350
357
  });
351
- case 38:
358
+ case 40:
352
359
  temCompAssetList = _context3.sent;
353
360
  // 兼容下割接数据,数组前面的自定义组件是新的
354
361
  compAssetList = temCompAssetList.reduce(function (acc, current) {
@@ -361,7 +368,7 @@ export var fetchData = /*#__PURE__*/function () {
361
368
  return acc;
362
369
  }, []);
363
370
  if (!(!isIncrementalConstruction || incrementalConstruction !== null && incrementalConstruction !== void 0 && incrementalConstruction.globalStoreChange)) {
364
- _context3.next = 47;
371
+ _context3.next = 49;
365
372
  break;
366
373
  }
367
374
  // 根据appId 获取全局数据源
@@ -369,12 +376,12 @@ export var fetchData = /*#__PURE__*/function () {
369
376
  log: '获取全局数据源',
370
377
  progress: 4
371
378
  });
372
- _context3.next = 44;
379
+ _context3.next = 46;
373
380
  return services.queryFrontendDatasourcePage({
374
381
  appId: appId,
375
382
  pageSize: 10000
376
383
  });
377
- case 44:
384
+ case 46:
378
385
  globalDataInfo = _context3.sent;
379
386
  dataSourceList = ((_globalDataInfo = globalDataInfo) === null || _globalDataInfo === void 0 ? void 0 : _globalDataInfo.list) || [];
380
387
  dataSourceList.forEach(function (item) {
@@ -387,7 +394,7 @@ export var fetchData = /*#__PURE__*/function () {
387
394
  } catch (err) {}
388
395
  return null;
389
396
  });
390
- case 47:
397
+ case 49:
391
398
  pageIdMapping = {};
392
399
  lastPageId = ''; // 根据 pageId 获得 dsl
393
400
  data = [];
@@ -395,8 +402,9 @@ export var fetchData = /*#__PURE__*/function () {
395
402
  log: '获取所有页面dsl',
396
403
  progress: 5
397
404
  });
398
- _context3.next = 53;
399
- return Promise.all(appPageList.map(function (i) {
405
+ needFindDataPages = isIncrementalConstruction ? incrementalConstructionPageList : appPageList;
406
+ _context3.next = 56;
407
+ return Promise.all(needFindDataPages.map(function (i) {
400
408
  lastPageId = i.pageId;
401
409
  pageIdMapping[i.pagePath] = i.pageId;
402
410
  return services.findPageInstByVersionId({
@@ -404,11 +412,11 @@ export var fetchData = /*#__PURE__*/function () {
404
412
  pageId: i.pageId
405
413
  });
406
414
  }));
407
- case 53:
415
+ case 56:
408
416
  data = _context3.sent;
409
417
  pages = getPageDsls(data);
410
418
  if (isIncrementalConstruction) {
411
- _context3.next = 66;
419
+ _context3.next = 69;
412
420
  break;
413
421
  }
414
422
  onProgress({
@@ -417,7 +425,7 @@ export var fetchData = /*#__PURE__*/function () {
417
425
  });
418
426
 
419
427
  // 业务组件从被使用才生成改为全部生成
420
- _context3.next = 59;
428
+ _context3.next = 62;
421
429
  return services.qryBusiCompPage({
422
430
  appIds: [appId],
423
431
  appId: appId,
@@ -426,10 +434,10 @@ export var fetchData = /*#__PURE__*/function () {
426
434
  pageSize: 999999,
427
435
  terminalType: platform
428
436
  });
429
- case 59:
437
+ case 62:
430
438
  _yield$services$qryBu = _context3.sent;
431
439
  itemLists = _yield$services$qryBu.list;
432
- _context3.next = 63;
440
+ _context3.next = 66;
433
441
  return Promise.all(itemLists.map(function (i) {
434
442
  return services.findBusiCompById({
435
443
  busiCompId: i.busiCompId,
@@ -437,22 +445,29 @@ export var fetchData = /*#__PURE__*/function () {
437
445
  pageId: lastPageId
438
446
  });
439
447
  }));
440
- case 63:
448
+ case 66:
441
449
  busiData = _context3.sent;
442
- _context3.next = 69;
450
+ _context3.next = 76;
443
451
  break;
444
- case 66:
445
- _context3.next = 68;
446
- return Promise.all(((_incrementalConstruct = incrementalConstruction === null || incrementalConstruction === void 0 ? void 0 : incrementalConstruction.busiCompIds) !== null && _incrementalConstruct !== void 0 ? _incrementalConstruct : []).map(function (i) {
452
+ case 69:
453
+ // busiCompId 过滤重复
454
+ itemHash = {}; // 找到所有页面使用到的 业务组件
455
+ findAllItem(pages, function (item) {
456
+ return item.compName === 'BOFramer';
457
+ }, itemHash);
458
+ _itemLists = Object.keys(itemHash); // 请求所有业务组件的 dsl
459
+ alllBusiComp = ((_incrementalConstruct = incrementalConstruction === null || incrementalConstruction === void 0 ? void 0 : incrementalConstruction.busiCompIds) !== null && _incrementalConstruct !== void 0 ? _incrementalConstruct : []).concat(_itemLists);
460
+ _context3.next = 75;
461
+ return Promise.all(alllBusiComp.map(function (i) {
447
462
  return services.findBusiCompById({
448
463
  busiCompId: i,
449
464
  appId: appId,
450
465
  pageId: lastPageId
451
466
  });
452
467
  }));
453
- case 68:
468
+ case 75:
454
469
  busiData = _context3.sent;
455
- case 69:
470
+ case 76:
456
471
  // 过滤为空
457
472
  busiPages = busiData.filter(Boolean).map(function (i, index) {
458
473
  var _i$busiCompVersion;
@@ -525,14 +540,14 @@ export var fetchData = /*#__PURE__*/function () {
525
540
  });
526
541
  translateNames = {};
527
542
  if (!(chinese.length > 0)) {
528
- _context3.next = 77;
543
+ _context3.next = 84;
529
544
  break;
530
545
  }
531
- _context3.next = 76;
546
+ _context3.next = 83;
532
547
  return getTranslateName(appId, chinese, 'UPPER_CAMEL');
533
- case 76:
548
+ case 83:
534
549
  translateNames = _context3.sent;
535
- case 77:
550
+ case 84:
536
551
  // 翻译业务组件的名字
537
552
  for (key = 0; key < busiPages.length; key++) {
538
553
  onProgress({
@@ -544,7 +559,7 @@ export var fetchData = /*#__PURE__*/function () {
544
559
  }
545
560
  pagePathEnglishMapping = {};
546
561
  if (!needTranslatePagePathToEnglish) {
547
- _context3.next = 89;
562
+ _context3.next = 97;
548
563
  break;
549
564
  }
550
565
  pagePathEnglishSet = {};
@@ -561,36 +576,45 @@ export var fetchData = /*#__PURE__*/function () {
561
576
  }
562
577
  return getName("".concat(compName), type, index + 1);
563
578
  };
564
- pagesChinese = pages === null || pages === void 0 ? void 0 : pages.map(function (item) {
579
+ pagesChinese = appPageList === null || appPageList === void 0 ? void 0 : appPageList.map(function (item) {
565
580
  return getSafeTypeName(item.pageName);
566
581
  });
567
582
  pagesTranslateNames = {};
568
583
  if (!(pagesChinese.length > 0)) {
569
- _context3.next = 88;
584
+ _context3.next = 95;
570
585
  break;
571
586
  }
572
- _context3.next = 87;
587
+ _context3.next = 94;
573
588
  return getTranslateName(appId, pagesChinese, 'UPPER_CAMEL');
574
- case 87:
589
+ case 94:
575
590
  pagesTranslateNames = _context3.sent;
576
- case 88:
577
- // 翻译页面的名字
578
- for (_key = 0; _key < pages.length; _key++) {
591
+ case 95:
592
+ findPageKeyByPageId = function findPageKeyByPageId(id, arrs) {
593
+ for (var _key = 0; _key < arrs.length; _key++) {
594
+ var _arrs$_key;
595
+ if (((_arrs$_key = arrs[_key]) === null || _arrs$_key === void 0 ? void 0 : _arrs$_key.pageId) == id) {
596
+ return _key;
597
+ }
598
+ }
599
+ return 0;
600
+ }; // 翻译页面的名字
601
+ for (_key2 = 0; _key2 < appPageList.length; _key2++) {
579
602
  onProgress({
580
603
  log: '翻译页面路径',
581
- progress: 7 + _key / pages.length
604
+ progress: 7 + _key2 / appPageList.length
582
605
  });
583
606
  // 如果页面路径翻译失败,就不处理路径
584
607
  // index 保留不处理
585
- if (pages[_key].pagePath !== '/index') {
586
- (_pagePathEnglishMappi = pagePathEnglishMapping[_pages$_key$pageConta = pages[_key].pageContainerType]) !== null && _pagePathEnglishMappi !== void 0 ? _pagePathEnglishMappi : pagePathEnglishMapping[_pages$_key$pageConta] = {};
587
- safeTranslateName = getName(((_pagesTranslateNames = pagesTranslateNames) === null || _pagesTranslateNames === void 0 ? void 0 : _pagesTranslateNames[getSafeTypeName(pages[_key].pageName)]) || pages[_key].pageName, pages[_key].pageContainerType);
588
- pagePathEnglishMapping[pages[_key].pageContainerType][pages[_key].pagePath] = safeTranslateName;
589
- pages[_key]._pagePath = pages[_key].pagePath;
590
- pages[_key].pagePath = safeTranslateName;
608
+ if (appPageList[_key2].pagePath !== '/index') {
609
+ (_pagePathEnglishMappi = pagePathEnglishMapping[_appPageList$_key2$pa = appPageList[_key2].pageContainerType]) !== null && _pagePathEnglishMappi !== void 0 ? _pagePathEnglishMappi : pagePathEnglishMapping[_appPageList$_key2$pa] = {};
610
+ safeTranslateName = getName(((_pagesTranslateNames = pagesTranslateNames) === null || _pagesTranslateNames === void 0 ? void 0 : _pagesTranslateNames[getSafeTypeName(appPageList[_key2].pageName)]) || appPageList[_key2].pageName, appPageList[_key2].pageContainerType);
611
+ pagePathEnglishMapping[appPageList[_key2].pageContainerType][appPageList[_key2].pagePath] = safeTranslateName;
612
+ pageKey = findPageKeyByPageId(appPageList[_key2].pageId, pages);
613
+ pages[pageKey]._pagePath = pages[pageKey].pagePath;
614
+ pages[pageKey].pagePath = safeTranslateName;
591
615
  }
592
616
  }
593
- case 89:
617
+ case 97:
594
618
  // 合并页面,生成器那边支持页面类型和业务组件类型
595
619
  pageDSLS = [].concat(_toConsumableArray(pages), _toConsumableArray(busiPages));
596
620
  getPlatform = function getPlatform(platFormtype) {
@@ -620,7 +644,8 @@ export var fetchData = /*#__PURE__*/function () {
620
644
  appInfo: clearAppInfo(appInfo),
621
645
  // 英文路径的对应关系
622
646
  pagePathEnglishMapping: pagePathEnglishMapping,
623
- incrementalConstruction: incrementalConstruction
647
+ incrementalConstruction: incrementalConstruction,
648
+ pageTypeMap: pageTypeMap
624
649
  };
625
650
  onProgress({
626
651
  log: '清理无用数据',
@@ -632,11 +657,11 @@ export var fetchData = /*#__PURE__*/function () {
632
657
  options: options,
633
658
  cleanedTree: cleanedTree
634
659
  });
635
- case 96:
660
+ case 104:
636
661
  case "end":
637
662
  return _context3.stop();
638
663
  }
639
- }, _callee3, null, [[25, 32]]);
664
+ }, _callee3, null, [[27, 34]]);
640
665
  }));
641
666
  return function fetchData(_x) {
642
667
  return _ref5.apply(this, arguments);
@@ -177,5 +177,3 @@ namespace securityType {
177
177
  desKey: string;
178
178
  };
179
179
  }
180
-
181
- export default securityType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxiteam/ebe-utils",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -17,7 +17,7 @@
17
17
  "@babel/parser": "^7.12.12",
18
18
  "@babel/traverse": "^7.12.12",
19
19
  "@babel/types": "^7.12.12",
20
- "@lingxiteam/ebe": "0.0.16",
20
+ "@lingxiteam/ebe": "0.0.18",
21
21
  "cac": "^6.7.14",
22
22
  "fs-extra": "9.x"
23
23
  },