@cloudbase/lowcode-builder 1.8.58 → 1.8.60

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.
@@ -154,7 +154,8 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
154
154
  : 'rpx'),
155
155
  enablePageRoot,
156
156
  enableLoading: (_e = cals === null || cals === void 0 ? void 0 : cals.extra) === null || _e === void 0 ? void 0 : _e.enableLoading,
157
- enableAsyncMaterials: (_f = cals === null || cals === void 0 ? void 0 : cals.extra) === null || _f === void 0 ? void 0 : _f.enableAsyncMaterials,
157
+ enableAsyncMaterials: (_f = cals.extra) === null || _f === void 0 ? void 0 : _f.enableAsyncMaterials,
158
+ // enableAsyncMaterials: true,
158
159
  };
159
160
  const result = await (0, index_1.generateWxMp)({
160
161
  weapps: apps,
@@ -39,7 +39,7 @@ const common_1 = require("../types/common");
39
39
  const compile_1 = require("./compile");
40
40
  const util_1 = require("../util");
41
41
  const types_1 = require("../../types");
42
- const mp_1 = require("../mp");
42
+ const cals_1 = require("@cloudbase/cals");
43
43
  const common_2 = require("../../utils/common");
44
44
  const config_1 = require("../config");
45
45
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -51,7 +51,7 @@ if (!process.env.IS_WEB_WORKER) {
51
51
  BabelTransform = transform.BabelTransform;
52
52
  }
53
53
  async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, buildTypeList = [common_1.BuildType.WEB], subAppCalsList, mode, devTool, runtime = types_1.RUNTIME.NONE, deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW }, ignoreInstall = false, cdnEndpoints, }) {
54
- var _a, _b, _c;
54
+ var _a, _b, _c, _d;
55
55
  const { projDir: buildDir, domain, materialLibs: dependencies, appId: appKey, isPrivateMode, enableExpiredTag, } = buildContext;
56
56
  if (!deployOptions.mode) {
57
57
  deployOptions.mode = types_1.DEPLOY_MODE.PREVIEW;
@@ -68,23 +68,21 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, bu
68
68
  _cals.extra.historyType = types_1.HISTORY_TYPE.HASH;
69
69
  }
70
70
  const cals = processCals(_cals);
71
- const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
72
- const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(item, dependencies))) || [];
73
- const { allAppUsedComps } = (0, mp_1.handleUsedComponents)({
74
- buildContext: { ...buildContext, mainAppData: mainAppSerializeData },
75
- weapps: [mainAppSerializeData, ...subAppSerializeDataList],
71
+ const used = (0, cals_1.getUsedComps)([cals], dependencies, {
72
+ withAction: true,
73
+ streamline: false,
76
74
  });
77
75
  // 处理应用数据
78
- const mainAppData = (0, weapps_core_1.deserialize)(mainAppSerializeData);
76
+ const mainAppData = (0, weapps_core_1.deserialize)((0, common_2.processCals2WeappsData)(cals, dependencies));
79
77
  if (!mainAppData.extra) {
80
78
  mainAppData.extra = { domain };
81
79
  }
82
80
  if (!((_a = mainAppData.extra) === null || _a === void 0 ? void 0 : _a.domain)) {
83
81
  mainAppData.extra.domain = domain;
84
82
  }
85
- const subAppDataList = subAppSerializeDataList.map((sub) => (0, weapps_core_1.deserialize)(sub));
83
+ const subAppDataList = ((_b = subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map) === null || _b === void 0 ? void 0 : _b.call(subAppCalsList, (sub) => (0, weapps_core_1.deserialize)((0, common_2.processCals2WeappsData)(sub, dependencies)))) || [];
86
84
  // 前置操作
87
- const { publicPath, basename, assets = '', _indexPage } = ((_b = mainAppData.appConfig) === null || _b === void 0 ? void 0 : _b.window) || {};
85
+ const { publicPath, basename, assets = '', _indexPage } = ((_c = mainAppData.appConfig) === null || _c === void 0 ? void 0 : _c.window) || {};
88
86
  // 获取 插入的cdn 资源
89
87
  const jsAssets = await (0, generate_1.handleAssets)({
90
88
  appBuildDir: buildDir,
@@ -97,8 +95,9 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, bu
97
95
  console.time(runHandleMaterialTag);
98
96
  // 精简只使用用到的组件库,并获取补齐json格式
99
97
  const processedDependencies = await (0, material_1.runHandleMaterial)(h5BuildDir, dependencies.filter((lib) => {
98
+ var _a, _b;
100
99
  // 注意需要包涵官方的(gsd),部分平台方法需要由其补充
101
- return lib.name === config_1.OFFICIAL_LIB_KEY || !!allAppUsedComps[lib.name];
100
+ return lib.name === config_1.OFFICIAL_LIB_KEY || !!(((_a = used.component) === null || _a === void 0 ? void 0 : _a[lib.name]) || ((_b = used.action) === null || _b === void 0 ? void 0 : _b[lib.name]));
102
101
  }), materialsDir, runtime, ignoreInstall);
103
102
  console.timeEnd(runHandleMaterialTag);
104
103
  // // 获取 generate 需要的构建文件
@@ -187,7 +186,7 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, bu
187
186
  })
188
187
  .filter((item) => !!item);
189
188
  // 普通 web 模式,且非hash模式,根据页面生成多份入口
190
- if (!((_c = cals.extra) === null || _c === void 0 ? void 0 : _c.historyType) || cals.extra.historyType === types_1.HISTORY_TYPE.BROWSER) {
189
+ if (!((_d = cals.extra) === null || _d === void 0 ? void 0 : _d.historyType) || cals.extra.historyType === types_1.HISTORY_TYPE.BROWSER) {
191
190
  preHeatUrls.push(path_1.default.posix.join(basename || ''));
192
191
  await Promise.all((cals.items || []).map((page) => {
193
192
  preHeatUrls.push(path_1.default.posix.join(basename || '', page.id));
@@ -1,7 +1,7 @@
1
1
  import { IWeAppData, IPlugin } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  import { ICDN_ENDPOINTS_COFIG } from '../config';
3
3
  import { IBuildContext } from './BuildContext';
4
- import { BuildType, IAppUsedComp, IUsedComps } from '../types/common';
4
+ import { BuildType } from '../types/common';
5
5
  import { IPlatformApp } from '@cloudbase/cals';
6
6
  import { IBuildWedaApp } from '../core';
7
7
  export declare function generateWxMp({ buildContext, weapps, calses, plugins, deployOptions, options, buildTypeList, ignoreInstall, cdnEndpoints, }: {
@@ -27,14 +27,3 @@ export declare function generateConfig(data: {
27
27
  endpointType?: IBuildContext['endpointType'] | '';
28
28
  }, root: string): Promise<void>;
29
29
  export declare function writeLowCodeFiles(ctx: IBuildContext, appData: IWeAppData, outDir: string): Promise<void>;
30
- /**
31
- * TODO: 与 cals 里的实现进行整合
32
- * 关键点在于 appUsedComps 分组, 与 generic componen 的实现
33
- */
34
- export declare function handleUsedComponents({ buildContext, weapps }: {
35
- buildContext: IBuildContext;
36
- weapps: IWeAppData[];
37
- }): {
38
- appUsedComps: IAppUsedComp[];
39
- allAppUsedComps: IUsedComps;
40
- };
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.handleUsedComponents = exports.writeLowCodeFiles = exports.generateConfig = exports.generateWxMp = void 0;
29
+ exports.writeLowCodeFiles = exports.generateConfig = exports.generateWxMp = void 0;
30
30
  const chalk_1 = __importDefault(require("chalk"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const util_1 = require("util");
@@ -52,24 +52,25 @@ const junk = __importStar(require("../util/junk"));
52
52
  const net_1 = require("../util/net");
53
53
  const cals_1 = require("@cloudbase/cals");
54
54
  const core_1 = require("../core");
55
+ const theme_1 = require("../../utils/theme");
55
56
  const templateDir = `${config_1.appTemplateDir}/mp/`;
56
57
  const em = chalk_1.default.blue.bold;
57
58
  const error = chalk_1.default.redBright;
58
- function patchBuildContext(ctx, calses, weapps) {
59
+ function patchBuildContext(ctx, calses) {
59
60
  var _a, _b, _c;
60
61
  const { mainAppData } = ctx;
61
62
  if ((_b = (_a = calses === null || calses === void 0 ? void 0 : calses[0]) === null || _a === void 0 ? void 0 : _a.templates) === null || _b === void 0 ? void 0 : _b.length) {
62
63
  ctx.materialLibs = [...ctx.materialLibs, (0, cals_1.processTemplatesToDependiencies)((_c = calses === null || calses === void 0 ? void 0 : calses[0]) === null || _c === void 0 ? void 0 : _c.templates)];
63
64
  }
64
- const { allAppUsedComps } = handleUsedComponents({ buildContext: ctx, weapps });
65
+ const used = (0, cals_1.getUsedComps)(calses, ctx.materialLibs, { streamline: false, withAction: true });
65
66
  /**
66
67
  * 修改 buildContext 进行 miniprogramPlugins 精简
67
68
  */
68
- ctx.miniprogramPlugins = (mainAppData.miniprogramPlugins || []).filter((plugin) => allAppUsedComps[plugin.name]);
69
- return { allAppUsedComps };
69
+ ctx.miniprogramPlugins = (mainAppData.miniprogramPlugins || []).filter((plugin) => used.component[plugin.name] || used.action[plugin.name]);
70
+ return { used: used };
70
71
  }
71
72
  async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptions, options, buildTypeList, ignoreInstall = false, cdnEndpoints = {}, }) {
72
- var _a, _b;
73
+ var _a, _b, _c, _d;
73
74
  const operationLabel = em('Wexin MiniProgram Generated');
74
75
  console.time(operationLabel);
75
76
  console.log(`Generating ${em('Wexin MiniProgram')} to ${buildContext.projDir}`);
@@ -77,10 +78,10 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
77
78
  * 此函数具有副作用,用于补充修正小程序特殊的buildContext
78
79
  * 注意一定在入口进行处理,应当尽可能提前,后续逻辑不应该更新buildContext
79
80
  */
80
- const { allAppUsedComps } = patchBuildContext(buildContext, calses, weapps);
81
+ const { used } = patchBuildContext(buildContext, calses);
81
82
  const { uin = '', appId, projDir, materialLibs: materials, isProduction, mainAppData, domain, isPrivateMode = false, endpointType = '', isBrowserMpBuilder = false, } = buildContext;
82
83
  // 安装依赖库,生成 materials 目录
83
- await (0, materials_1.installMaterials)(buildContext, projDir, allAppUsedComps, weapps);
84
+ await (0, materials_1.installMaterials)(buildContext, projDir, used, weapps);
84
85
  const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
85
86
  const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(buildContext, weapps, { mpAppId: options.mpAppId });
86
87
  const hasLowcodePkg = weapps.find((item) => !item.mpPkgUrl);
@@ -93,7 +94,7 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
93
94
  await (0, generateFiles_1.default)(projectFileData, templateDir, projDir);
94
95
  }
95
96
  // #2 生成主包
96
- await generatePkg({ ...buildContext, rootPath: mainAppData.rootPath }, mainAppData, path_1.default.join(projDir, '/'), pageConfigs[0]);
97
+ await generatePkg({ ...buildContext, rootPath: mainAppData.rootPath }, { cals: calses[0], weapp: mainAppData }, path_1.default.join(projDir, '/'), pageConfigs[0]);
97
98
  const projectConfigJsonPath = path_1.default.join(projDir, mainAppData.rootPath || '', 'project.config.json');
98
99
  let projectConfigJson = await fs.readJSON(projectConfigJsonPath);
99
100
  const miniprogramRoot = path_1.default.join(projDir, projectConfigJson.miniprogramRoot || '/');
@@ -114,6 +115,12 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
114
115
  endpointType,
115
116
  }, miniprogramRoot);
116
117
  const expirationStartTimesnap = buildContext.enableExpiredTag ? Date.now() : 0;
118
+ const cssVarList = Object.entries((0, theme_1.mergeCssVarConfig)((_b = (_a = calses[0]) === null || _a === void 0 ? void 0 : _a.theme) === null || _b === void 0 ? void 0 : _b.cssVarConfig, 'MP'))
119
+ .map(([key, _value]) => {
120
+ const value = _value || '';
121
+ return `${key}: ${value}${/;$/.test(value) ? '' : ';'}`;
122
+ })
123
+ .filter((str) => !!str) || [];
117
124
  appFileData = {
118
125
  ...appFileData,
119
126
  'common/style.js': {},
@@ -124,6 +131,7 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
124
131
  'common/widget.js': {},
125
132
  'common/weapp-page.js': {
126
133
  expirationStartTimesnap,
134
+ pageStyle: cssVarList.join(''),
127
135
  },
128
136
  'common/weapp-component.js': {},
129
137
  'common/merge-renderer.js': {
@@ -226,9 +234,9 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
226
234
  appID: appId,
227
235
  resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
228
236
  isProd: (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.UPLOAD,
229
- clientID: ((_a = mainAppData.extra) === null || _a === void 0 ? void 0 : _a.enableLoginStatusShare)
237
+ clientID: ((_c = mainAppData.extra) === null || _c === void 0 ? void 0 : _c.enableLoginStatusShare)
230
238
  ? mainAppData.envId
231
- : (_b = mainAppData.extra) === null || _b === void 0 ? void 0 : _b.clientId,
239
+ : (_d = mainAppData.extra) === null || _d === void 0 ? void 0 : _d.clientId,
232
240
  cdnEndpoints,
233
241
  builderVersion: core_1.version || '',
234
242
  officialLibVersion: (officialLib === null || officialLib === void 0 ? void 0 : officialLib.version) || '',
@@ -265,7 +273,7 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
265
273
  ...buildContext,
266
274
  rootPath: app.rootPath,
267
275
  };
268
- await generatePkg(subpackageBuildCtx, app, subpackageRootPath, pageConfigs[index]);
276
+ await generatePkg(subpackageBuildCtx, { cals: calses[index], weapp: app }, subpackageRootPath, pageConfigs[index]);
269
277
  await generateFramework(subpackageBuildCtx, app, subpackageRootPath, { deployOptions });
270
278
  // 生成package.json
271
279
  let packageJsonPath = path_1.default.join(subpackageRootPath, 'package.json');
@@ -298,8 +306,10 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
298
306
  await handleMpPlugins();
299
307
  console.timeEnd(operationLabel);
300
308
  // web端的builder不需要清除
301
- !isBrowserMpBuilder && cleanProj(weapps, miniprogramRoot);
302
- !isBrowserMpBuilder && cleanMaterils(path_1.default.join(miniprogramRoot, config_1.materialsDirName), allAppUsedComps);
309
+ if (!isBrowserMpBuilder) {
310
+ cleanProj(weapps, miniprogramRoot);
311
+ cleanMaterils(path_1.default.join(miniprogramRoot, config_1.materialsDirName), used);
312
+ }
303
313
  return { miniprogramRoot };
304
314
  // SDK 插件
305
315
  async function handleMpPlugins() {
@@ -359,7 +369,8 @@ async function generateConfig(data, root) {
359
369
  }, templateDir, root);
360
370
  }
361
371
  exports.generateConfig = generateConfig;
362
- async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
372
+ async function generatePkg(ctx, { cals, weapp }, appRoot, pageConfigs) {
373
+ var _a;
363
374
  const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!ctx.isProduction);
364
375
  console.log(`Generating ${em(weapp.rootPath ? 'subApp' : 'app')} to ${appRoot}`);
365
376
  const { processCssUnit = 'rpx' } = ctx;
@@ -376,6 +387,10 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
376
387
  // #2 generate page files
377
388
  console.log(`Generating ${em('page')} files`);
378
389
  (0, generateFiles_1.cleanDir)(path_1.default.join(appRoot, 'pages'), []);
390
+ const CALS_PAGE_MAP = (_a = cals.items) === null || _a === void 0 ? void 0 : _a.reduce((map, page) => {
391
+ map[page.id] = page;
392
+ return map;
393
+ }, {});
379
394
  await Promise.all(weapp.pageInstanceList.map(async (page, index) => {
380
395
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
381
396
  // # Generating page
@@ -383,15 +398,12 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
383
398
  const usingComponents = {};
384
399
  const componentGenerics = {};
385
400
  const componentInstances = (0, util_2.processRepeaterSchema)(ctx, page.componentInstances);
386
- const { allAppUsedComps = [] } = handleUsedComponents({
387
- buildContext: ctx,
388
- weapps: [
389
- {
390
- ...weapp,
391
- pageInstanceList: [page],
392
- },
393
- ],
394
- });
401
+ const allAppUsedComps = (0, cals_1.getUsedComps)([
402
+ {
403
+ ...cals,
404
+ items: CALS_PAGE_MAP[page.id] ? [CALS_PAGE_MAP[page.id]] : [],
405
+ },
406
+ ], ctx.materialLibs);
395
407
  const wxml = (0, wxml_1.generateWxml)({ ...ctx, rootPath, pageUUID: rootPath ? `${rootPath}/${page.id}` : page.id }, componentInstances, `Page ${rootPath ? path_1.default.join('packages', rootPath, 'pages') : ''}/${page.id}`, wxmlDataPrefix, usingComponents, componentGenerics);
396
408
  const importor = (0, util_3.generateLowcodeImportor)(page.lowCodes);
397
409
  const pageFileName = (0, lodash_1.get)(pageConfigs, `${page.id}.pageFileName`, 'index');
@@ -595,42 +607,6 @@ function getAppendableJson(json = {}) {
595
607
  return '';
596
608
  }
597
609
  // 处理使用到的组件
598
- /**
599
- * TODO: 与 cals 里的实现进行整合
600
- * 关键点在于 appUsedComps 分组, 与 generic componen 的实现
601
- */
602
- function handleUsedComponents({ buildContext, weapps }) {
603
- const { materialLibs: materials } = buildContext;
604
- const appUsedComps = weapps.map((app) => {
605
- var _a;
606
- const usedComps = {};
607
- (_a = app.pageInstanceList) === null || _a === void 0 ? void 0 : _a.forEach((p) => (0, wxml_1.getUsedComponents)(p.componentInstances, usedComps));
608
- return {
609
- rootPath: app.rootPath || '',
610
- usedComps,
611
- };
612
- });
613
- // merge all app/subapp used
614
- let allAppUsedComps = appUsedComps.reduce((comps, item) => {
615
- Object.keys(item.usedComps).forEach((libName) => {
616
- comps[libName] = new Set([...Array.from(item.usedComps[libName]), ...Array.from(comps[libName] || [])]);
617
- });
618
- return comps;
619
- }, {});
620
- const compositedLibs = materials.filter((lib) => lib.isComposite);
621
- allAppUsedComps = (0, materials_1.extractUsedCompsRecursively)(allAppUsedComps, [], compositedLibs);
622
- if (buildContext.isMixMode) {
623
- appUsedComps.forEach((item) => {
624
- const appCompositedLibs = materials.filter((lib) => lib.isComposite);
625
- item.usedComps = (0, materials_1.extractUsedCompsRecursively)(item.usedComps, [], appCompositedLibs);
626
- });
627
- }
628
- return {
629
- appUsedComps,
630
- allAppUsedComps,
631
- };
632
- }
633
- exports.handleUsedComponents = handleUsedComponents;
634
610
  async function cleanProj(weapps, miniprogramRoot) {
635
611
  weapps.map((pkg) => cleanPkg(pkg, miniprogramRoot));
636
612
  }
@@ -670,11 +646,12 @@ async function cleanPkg(pkg, miniprogramRoot) {
670
646
  /**
671
647
  * Delete unsed materials
672
648
  */
673
- function cleanMaterils(materialsDir, usedComps) {
649
+ function cleanMaterils(materialsDir, used) {
674
650
  if (fs.existsSync(materialsDir)) {
675
651
  fs.readdirSync(materialsDir)
676
652
  .filter(junk.not)
677
653
  .map((libName) => {
654
+ var _a;
678
655
  const libDir = path_1.default.join(materialsDir, libName);
679
656
  if (fs.existsSync(path_1.default.join(libDir, 'meta.json'))) {
680
657
  try {
@@ -684,11 +661,11 @@ function cleanMaterils(materialsDir, usedComps) {
684
661
  // Skip none-composited materials
685
662
  return;
686
663
  }
687
- if (!usedComps[libName]) {
664
+ if (!used.component[libName] && !used.action[libName]) {
688
665
  (0, generateFiles_1.removeFile)(libDir);
689
666
  return;
690
667
  }
691
- (0, generateFiles_1.cleanDir)(libDir, [...Array.from(usedComps[libName]), 'libCommonRes']);
668
+ (0, generateFiles_1.cleanDir)(libDir, [...Array.from((_a = used.component) === null || _a === void 0 ? void 0 : _a[libName]), 'libCommonRes']);
692
669
  });
693
670
  }
694
671
  }
@@ -1,8 +1,11 @@
1
- import { IMaterialItem, ICompositedComponent, IWeAppComponentInstance, IWeAppData } from '@cloudbase/lowcode-generator/lib/weapps-core';
1
+ import { IWeAppComponentInstance, IWeAppData } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  import { IBuildContext } from './BuildContext';
3
3
  import NameMangler from '@cloudbase/lowcode-generator/lib/generator/util/name-mangler';
4
4
  import { IUsedComps } from '../types/common';
5
- export declare function installMaterials(ctx: IBuildContext, projDir: string, usedComps: IUsedComps, weapps: IWeAppData[]): Promise<void>;
5
+ export declare function installMaterials(ctx: IBuildContext, projDir: string, usedMeta: {
6
+ component: IUsedComps;
7
+ action: IUsedComps;
8
+ }, weapps: IWeAppData[]): Promise<void>;
6
9
  /**
7
10
  * 过滤组件库文件
8
11
  * @param src 源文件
@@ -10,7 +13,6 @@ export declare function installMaterials(ctx: IBuildContext, projDir: string, us
10
13
  * @returns boolean
11
14
  */
12
15
  export declare function filterMaterial(src: any, dest: any): boolean;
13
- export declare function extractUsedCompsRecursively(comps: IUsedComps, checkedComps: ICompositedComponent[], compositedLibs: IMaterialItem[], outputComps?: IUsedComps): IUsedComps;
14
16
  export declare function getWxmlTag(ctx: IBuildContext, cmp: Required<IWeAppComponentInstance>['xComponent'], nameMangler?: NameMangler): {
15
17
  tagName: string;
16
18
  path?: undefined;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getWxmlTag = exports.extractUsedCompsRecursively = exports.filterMaterial = exports.installMaterials = void 0;
29
+ exports.getWxmlTag = exports.filterMaterial = exports.installMaterials = void 0;
30
30
  const path = __importStar(require("path"));
31
31
  const util_1 = require("util");
32
32
  const fs = __importStar(require("fs-extra"));
@@ -43,13 +43,14 @@ const name_mangler_1 = __importDefault(require("@cloudbase/lowcode-generator/lib
43
43
  const junk = __importStar(require("../util/junk"));
44
44
  const cals_1 = require("@cloudbase/cals");
45
45
  const templateDir = `${config_1.appTemplateDir}/mp/`;
46
- async function installMaterials(ctx, projDir, usedComps, weapps) {
47
- let { materialLibs, isBrowserMpBuilder } = ctx;
46
+ async function installMaterials(ctx, projDir, usedMeta, weapps) {
47
+ let { materialLibs: _materialLibs, isBrowserMpBuilder } = ctx;
48
48
  const weappsList = ctx.isMixMode ? weapps : weapps.filter((item) => !item.rootPath);
49
+ let materialLibs = _materialLibs.filter((lib) => usedMeta.component[lib.name] || usedMeta.action[lib.name]);
49
50
  // #1 Download uploaded libs
50
51
  const localPkg = (0, util_2.getCurrentPackageJson)();
51
52
  await Promise.all(materialLibs
52
- .filter((lib) => !lib.isComposite && usedComps[lib.name])
53
+ .filter((lib) => !lib.isComposite)
53
54
  .map(async (lib) => {
54
55
  const { name, version, mpPkgUrl } = lib;
55
56
  let materialsSrcDir = '';
@@ -140,10 +141,9 @@ async function installMaterials(ctx, projDir, usedComps, weapps) {
140
141
  }));
141
142
  }));
142
143
  // clean unused comps
143
- materialLibs = ctx.materialLibs.filter((lib) => usedComps[lib.name]);
144
144
  ctx.materialLibs = materialLibs;
145
- materialLibs.map((lib) => {
146
- lib.components = lib.components.filter((comp) => usedComps[lib.name].has(comp.name));
145
+ materialLibs.forEach((lib) => {
146
+ lib.components = lib.components.filter((comp) => { var _a, _b; return (_b = (_a = usedMeta.component[lib.name]) === null || _a === void 0 ? void 0 : _a.has) === null || _b === void 0 ? void 0 : _b.call(_a, comp.name); });
147
147
  });
148
148
  // populate cmp.materialName
149
149
  materialLibs.map((lib) => {
@@ -173,7 +173,7 @@ async function installMaterials(ctx, projDir, usedComps, weapps) {
173
173
  });
174
174
  });
175
175
  // Collection infomation from components to lib meta
176
- const compositedLibs = materialLibs.filter((lib) => lib.isComposite && usedComps[lib.name]);
176
+ const compositedLibs = materialLibs.filter((lib) => lib.isComposite);
177
177
  // #2 Generate composited libs
178
178
  await Promise.all(compositedLibs.map(async (lib) => {
179
179
  console.log(`Generate composited library ${lib.name}`);
@@ -204,40 +204,6 @@ function filterMaterial(src, dest) {
204
204
  return !junk.is(srcPath[srcPath.length - 1]);
205
205
  }
206
206
  exports.filterMaterial = filterMaterial;
207
- // 递归查询复合组件所使用的组件
208
- function extractUsedCompsRecursively(comps, checkedComps, compositedLibs, outputComps) {
209
- let usedComps = (outputComps || comps);
210
- const libsUsedByApp = Object.keys(comps);
211
- libsUsedByApp.forEach((libName) => {
212
- const cmpNames = comps[libName];
213
- const lib = compositedLibs.find((lib) => lib.name == libName);
214
- if (!lib || !lib.isComposite)
215
- return;
216
- cmpNames.forEach((cmpName) => {
217
- const cmp = lib.components.find((c) => c.name === cmpName);
218
- if (!cmp) {
219
- console.warn('Component not found', `${libName}:${cmpName}`);
220
- return;
221
- }
222
- if (checkedComps.indexOf(cmp) > -1)
223
- return;
224
- checkedComps.push(cmp);
225
- const cmpsUsedByThisComp = (0, wxml_1.getUsedComponents)(cmp.componentInstances);
226
- const libs = Object.keys(cmpsUsedByThisComp);
227
- libs.forEach((libName) => {
228
- if (!usedComps[libName]) {
229
- usedComps[libName] = cmpsUsedByThisComp[libName];
230
- }
231
- else {
232
- cmpsUsedByThisComp[libName].forEach((n) => usedComps[libName].add(n));
233
- }
234
- });
235
- extractUsedCompsRecursively(cmpsUsedByThisComp, checkedComps, compositedLibs, usedComps);
236
- });
237
- });
238
- return usedComps;
239
- }
240
- exports.extractUsedCompsRecursively = extractUsedCompsRecursively;
241
207
  async function downloadMaterial(zipUrl, dstFolder, isBrowser = false, noCache = false) {
242
208
  if (!noCache && fs.existsSync(path.join(dstFolder, 'meta.json')))
243
209
  return;
@@ -1,5 +1,4 @@
1
- import { IWeAppData, IPlugin, IMaterialItem } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
- import { IAppUsedComp } from '../types/common';
1
+ import { IWeAppData, IPlugin } from '@cloudbase/lowcode-generator/lib/weapps-core';
3
2
  import { IBuildContext } from '../mp/BuildContext';
4
3
  export declare function handleMixMode({ buildContext, apps, miniprogramRoot, plugins, ignoreInstall, }: {
5
4
  buildContext: IBuildContext;
@@ -8,4 +7,3 @@ export declare function handleMixMode({ buildContext, apps, miniprogramRoot, plu
8
7
  plugins: IPlugin[];
9
8
  ignoreInstall: boolean;
10
9
  }): Promise<void>;
11
- export declare function handleMixMaterials(projDir: string, apps: IWeAppData[], appUsedComps: IAppUsedComp[], compositedLibs: IMaterialItem[]): Promise<void[]>;
@@ -26,12 +26,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.handleMixMaterials = exports.handleMixMode = void 0;
29
+ exports.handleMixMode = void 0;
30
30
  const path_1 = __importDefault(require("path"));
31
31
  const fs_extra_1 = __importStar(require("fs-extra"));
32
32
  const mp_1 = require("../util/mp");
33
33
  const plugin_1 = require("./plugin");
34
- const lodash_1 = require("lodash");
35
34
  const chalk_1 = __importDefault(require("chalk"));
36
35
  const generateFiles_1 = require("../util/generateFiles");
37
36
  const webpack_1 = require("../service/webpack");
@@ -179,39 +178,3 @@ async function handleMixMode({ buildContext, apps = [], miniprogramRoot, plugins
179
178
  }
180
179
  }
181
180
  exports.handleMixMode = handleMixMode;
182
- // 子模式则清理未使用的组件库
183
- async function handleMixMaterials(projDir, apps, appUsedComps, compositedLibs) {
184
- return Promise.all(apps.map(async (app) => {
185
- var _a;
186
- const rootPath = app.rootPath || '';
187
- const materialsDirPath = path_1.default.join(projDir, rootPath, 'materials');
188
- const usedComps = ((_a = appUsedComps.find((item) => item.rootPath === rootPath)) === null || _a === void 0 ? void 0 : _a.usedComps) || {};
189
- const materialsLib = await readDirs(materialsDirPath);
190
- // 清理未使用的组件库
191
- const cleanLibs = (0, lodash_1.difference)(materialsLib, Object.keys(usedComps));
192
- await removeDirs(cleanLibs.map((libName) => path_1.default.join(materialsDirPath, libName)));
193
- // 清理未使用的组件
194
- await Promise.all(Object.keys(usedComps).map(async (libName) => {
195
- // 只去处理复合组件
196
- if (!compositedLibs.find((item) => item.name === libName)) {
197
- return;
198
- }
199
- const libComponents = usedComps[libName];
200
- const materialsLibComps = await readDirs(path_1.default.join(materialsDirPath, libName));
201
- const cleanComps = (0, lodash_1.difference)(materialsLibComps, Array.from(libComponents));
202
- await removeDirs(cleanComps.map((compName) => path_1.default.join(materialsDirPath, libName, compName)));
203
- }));
204
- }));
205
- }
206
- exports.handleMixMaterials = handleMixMaterials;
207
- async function removeDirs(dirs) {
208
- return Promise.all(dirs.map((dir) => {
209
- console.log('【MIX MODE 清理】', dir);
210
- return fs_extra_1.default.remove(dir);
211
- }));
212
- }
213
- // 只返回文件夹
214
- async function readDirs(dirPath) {
215
- const isDirectory = (source) => (0, fs_extra_1.lstatSync)(source).isDirectory();
216
- return ((await fs_extra_1.default.readdir(dirPath)) || []).filter((name) => isDirectory(path_1.default.join(dirPath, name)));
217
- }
@@ -23,6 +23,13 @@ export declare function createTemplateQuery(ctx: IBuildContext, query?: {
23
23
  [key: string]: IQueryData;
24
24
  }): {};
25
25
  export declare function createTemplateEventFlows(ctx: IBuildContext, eventFlows?: any[]): any[];
26
+ export declare function generateArgsDynamicValueFromData(args?: {
27
+ [prop: string]: IDynamicValue;
28
+ }, data?: {
29
+ [prop: string]: IDynamicValue;
30
+ }): {
31
+ [prop: string]: IDynamicValue;
32
+ } | undefined;
26
33
  export declare function createDataBinds(ctx: IBuildContext, widgets: {
27
34
  [key: string]: IWeAppComponentInstance;
28
35
  }): {};