@cloudbase/lowcode-builder 1.8.94 → 1.8.96

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.
Files changed (38) hide show
  1. package/lib/builder/core/index.d.ts +9 -0
  2. package/lib/builder/core/index.js +118 -7
  3. package/lib/builder/h5/generate.d.ts +1 -1
  4. package/lib/builder/h5/index.d.ts +2 -2
  5. package/lib/builder/h5/index.js +24 -6
  6. package/lib/builder/h5/webpack.d.ts +2 -2
  7. package/lib/builder/mp/BuildContext.d.ts +18 -14
  8. package/lib/builder/mp/index.d.ts +11 -1
  9. package/lib/builder/mp/index.js +98 -85
  10. package/lib/builder/mp/lowcode.d.ts +5 -3
  11. package/lib/builder/mp/lowcode.js +14 -5
  12. package/lib/builder/mp/materials.d.ts +10 -5
  13. package/lib/builder/mp/materials.js +139 -135
  14. package/lib/builder/mp/util.d.ts +15 -12
  15. package/lib/builder/mp/util.js +50 -22
  16. package/lib/builder/mp/wxml.d.ts +5 -3
  17. package/lib/builder/mp/wxml.js +29 -27
  18. package/lib/builder/service/webpack.js +0 -1
  19. package/lib/builder/util/common.d.ts +1 -2
  20. package/lib/builder/util/common.js +1 -45
  21. package/lib/builder/util/generateFiles.d.ts +1 -1
  22. package/lib/builder/util/generateFiles.js +5 -1
  23. package/lib/builder.web.js +8 -55
  24. package/package.json +2 -2
  25. package/template/html/index.html.ejs +7 -3
  26. package/template/mp/app/weapps-api.js +1 -1
  27. package/template/mp/app.js +4 -2
  28. package/template/mp/common/cloud-sdk.js +28 -0
  29. package/template/mp/common/data-patch.js +18 -3
  30. package/template/mp/common/util.js +6 -2
  31. package/template/mp/common/watch.js +1 -1
  32. package/template/mp/common/weapp-component.js +5 -5
  33. package/template/mp/common/weapp-page.js +4 -3
  34. package/template/mp/common/widget.js +51 -38
  35. package/template/mp/component/index.js +7 -6
  36. package/template/mp/datasources/index.js.tpl +2 -30
  37. package/template/mp/package.json +3 -3
  38. package/template/webpack/web.prod.js +1 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateScopedStyleText = exports.findComponentInfo = exports.processRepeaterSchema = exports.setDataBind = exports.createDataBinds = exports.generateArgsDynamicValueFromData = exports.createTemplateEventFlows = exports.createTemplateQuery = exports.generateDataContainerListeners = exports.generateSyncListeners = exports.createEventHandlers = exports.createWidgetProps = exports.generatedDynamicData = void 0;
3
+ exports.isRepeaterWidget = exports.generateScopedStyleText = exports.findComponentInfo = exports.processRepeaterSchema = exports.setDataBind = exports.createDataBinds = exports.generateArgsDynamicValueFromData = exports.createTemplateEventFlows = exports.createTemplateQuery = exports.generateDataContainerListeners = exports.generateSyncListeners = exports.createEventHandlers = exports.createWidgetProps = exports.generatedDynamicData = void 0;
4
4
  const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
5
5
  const lowcode_generator_1 = require("@cloudbase/lowcode-generator");
6
6
  const weapp_1 = require("@cloudbase/lowcode-generator/lib/generator/util/weapp");
@@ -128,14 +128,8 @@ function createWidgetProps(ctx, widgets) {
128
128
  materialLibs: ctx.materialLibs,
129
129
  miniprogramPlugins: ctx.miniprogramPlugins,
130
130
  });
131
- if (!widegetComp) {
132
- if (xComponent.moduleName === config_1.REPEATER.MODULE_NAME &&
133
- (xComponent.name === config_1.REPEATER.REPEATER_NAME || xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME)) {
134
- // skip
135
- }
136
- else {
137
- return;
138
- }
131
+ if (!widegetComp && !checkRepeaterComponent(xComponent)) {
132
+ return;
139
133
  }
140
134
  widgetProps[id] = extractWidgetProps(xProps, widegetComp, ctx.processCssUnit);
141
135
  widgetProps[id]._parentId = parentId;
@@ -157,8 +151,7 @@ function createEventHandlers(ctx, widgets, componentApi, page) {
157
151
  return;
158
152
  }
159
153
  let compProto;
160
- if (xComponent.moduleName === config_1.REPEATER.MODULE_NAME &&
161
- (xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME || xComponent.name === config_1.REPEATER.REPEATER_NAME)) {
154
+ if (checkRepeaterComponent(xComponent)) {
162
155
  // 内部虚组件,不校验compProto
163
156
  }
164
157
  else {
@@ -357,8 +350,7 @@ function createDataBinds(ctx, widgets) {
357
350
  // skip slot component
358
351
  return;
359
352
  }
360
- if (xComponent.moduleName === config_1.REPEATER.MODULE_NAME &&
361
- (xComponent.name === config_1.REPEATER.REPEATER_NAME || xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME)) {
353
+ if (checkRepeaterComponent(xComponent)) {
362
354
  // skip exist
363
355
  }
364
356
  else if (!findComponentInfo(xComponent, { materialLibs: ctx.materialLibs, miniprogramPlugins: ctx.miniprogramPlugins })) {
@@ -439,16 +431,36 @@ function processRepeaterSchema(ctx, componentInstanceMap) {
439
431
  // skip slot component
440
432
  return;
441
433
  }
442
- if (`${xComponent.moduleName}:${xComponent.name}` === `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_NAME}`) {
434
+ const componentInfo = findComponentInfo(xComponent, {
435
+ materialLibs: ctx.materialLibs,
436
+ miniprogramPlugins: ctx.miniprogramPlugins,
437
+ });
438
+ const simpleWidget = {
439
+ widgetType: `${xComponent.moduleName}:${xComponent.name}`,
440
+ getConfig: () => {
441
+ return (componentInfo === null || componentInfo === void 0 ? void 0 : componentInfo.compConfig) || {};
442
+ },
443
+ };
444
+ if (isRepeaterWidget(simpleWidget, config_1.REPEATER.REPEATER_NAME)) {
443
445
  const children = Object.values(properties);
444
446
  // 子项已经为 item 的不在处理
445
447
  if (children.length === 1) {
446
448
  const child = children[0];
447
449
  const { xComponent: childXComponent } = child;
448
- if (childXComponent &&
449
- `${childXComponent.moduleName}:${childXComponent.name}` ===
450
- `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_ITEM_NAME}`) {
451
- return;
450
+ if (childXComponent) {
451
+ const componentInfo = findComponentInfo(childXComponent, {
452
+ materialLibs: ctx.materialLibs,
453
+ miniprogramPlugins: ctx.miniprogramPlugins,
454
+ });
455
+ const simpleWidget = {
456
+ widgetType: `${xComponent.moduleName}:${xComponent.name}`,
457
+ getConfig: () => {
458
+ return (componentInfo === null || componentInfo === void 0 ? void 0 : componentInfo.compConfig) || {};
459
+ },
460
+ };
461
+ if (isRepeaterWidget(simpleWidget, config_1.REPEATER.REPEATER_ITEM_NAME)) {
462
+ return;
463
+ }
452
464
  }
453
465
  }
454
466
  // 给 Repeater 组件加一层虚拟项组件,在虚拟项组件上挂 for 循环
@@ -483,10 +495,10 @@ function processRepeaterSchema(ctx, componentInstanceMap) {
483
495
  },
484
496
  };
485
497
  }
486
- else if (`${xComponent.moduleName}:${xComponent.name}` === `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_ITEM_NAME}`) {
498
+ else if (isRepeaterWidget(simpleWidget, config_1.REPEATER.REPEATER_ITEM_NAME)) {
487
499
  return;
488
500
  }
489
- else if (xComponent && !findComponentInfo(xComponent, ctx)) {
501
+ else if (xComponent && !componentInfo) {
490
502
  component.properties = {};
491
503
  }
492
504
  return;
@@ -522,7 +534,7 @@ function findComponentInfo(xComponent, { materialLibs, miniprogramPlugins }) {
522
534
  return compProto;
523
535
  }
524
536
  exports.findComponentInfo = findComponentInfo;
525
- function generateScopedStyleText(widgets) {
537
+ function generateScopedStyleText(widgets, weightPrefix = '#wd-page-root') {
526
538
  const cssTextList = [];
527
539
  function traverse(target) {
528
540
  var _a;
@@ -535,7 +547,7 @@ function generateScopedStyleText(widgets) {
535
547
  // 移除换行及其前后的空白符
536
548
  .replace(/\s*\n\s*/g, '')
537
549
  // 添加 `#wd-page-root` 前缀以增加样式权重
538
- .replace(/(:scope.*?{)/g, '\n#wd-page-root $1')
550
+ .replace(/(:scope.*?{)/g, `\n${weightPrefix} $1`)
539
551
  // 替换 `:scope`
540
552
  .replace(/:scope/g, `.wd-comp-id-${id}`)
541
553
  // `: ` => `:`
@@ -555,3 +567,19 @@ function generateScopedStyleText(widgets) {
555
567
  return cssTextList.join('\n');
556
568
  }
557
569
  exports.generateScopedStyleText = generateScopedStyleText;
570
+ function isRepeaterWidget(w, repeaterComponentName /* 'Repeater' | 'RepeaterItem' */) {
571
+ var _a;
572
+ const { componentType } = ((_a = w === null || w === void 0 ? void 0 : w.getConfig) === null || _a === void 0 ? void 0 : _a.call(w)) || {};
573
+ if (componentType === repeaterComponentName || (w === null || w === void 0 ? void 0 : w.widgetType) === `${config_1.REPEATER.MODULE_NAME}:${repeaterComponentName}`) {
574
+ return true;
575
+ }
576
+ }
577
+ exports.isRepeaterWidget = isRepeaterWidget;
578
+ function checkRepeaterComponent(xComponent) {
579
+ if (xComponent.moduleName === config_1.REPEATER.MODULE_NAME &&
580
+ (xComponent.name === config_1.REPEATER.REPEATER_NAME || xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME)) {
581
+ return true;
582
+ // skip
583
+ }
584
+ return false;
585
+ }
@@ -1,10 +1,12 @@
1
1
  import { IWeAppComponentInstance, IEventModifiers } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
- import { IBuildContext } from './BuildContext';
2
+ import { IBuildContext, IMpCommonBuildContext } from './BuildContext';
3
3
  export declare const WD_EMPTY_PLACEHOLDER = "wd-ph";
4
4
  export declare const WD_RUNTIME_TAG: string[];
5
- export declare function generateWxml(ctx: IBuildContext & {
5
+ export declare function generateWxml(ctx: (IBuildContext & {
6
6
  pageUUID?: string;
7
- }, widgets: {
7
+ }) | (IMpCommonBuildContext & {
8
+ pageUUID?: undefined;
9
+ }), widgets: {
8
10
  [key: string]: IWeAppComponentInstance;
9
11
  }, docTag: string, wxmlDataPrefix: any, usingComponents: any, componentGenerics: any, nodeTransform?: (cmp: IWeAppComponentInstance, node: any) => void): string;
10
12
  export declare function getMpEventHandlerName(widgetId: string, evtName: string, modifier?: IEventModifiers): string;
@@ -194,35 +194,37 @@ function generateWxml(ctx, widgets, docTag, wxmlDataPrefix, usingComponents, com
194
194
  }
195
195
  const componentKey = `${xComponent.moduleName}:${xComponent.name}`;
196
196
  const helpMsg = `Please check component(${id}) in component tree of ${docTag}.`;
197
- let tagName, path, componentProto;
198
- switch (componentKey) {
199
- case `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_NAME}`: {
200
- const children = createXml(properties, parent, parentForNodes);
201
- for (let item of children) {
202
- item._order = xIndex || 0;
203
- }
204
- elements.push(...children);
205
- continue;
206
- break;
207
- }
208
- case `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_ITEM_NAME}`: {
209
- tagName = 'block';
210
- path = '';
211
- break;
197
+ let tagName, path;
198
+ const componentProto = (0, util_1.findComponentInfo)(xComponent, {
199
+ materialLibs: ctx.materialLibs,
200
+ miniprogramPlugins: ctx.miniprogramPlugins,
201
+ });
202
+ const simpleWidget = {
203
+ widgetType: componentKey,
204
+ getConfig: () => {
205
+ return (componentProto === null || componentProto === void 0 ? void 0 : componentProto.compConfig) || {};
206
+ },
207
+ };
208
+ if ((0, util_1.isRepeaterWidget)(simpleWidget, config_1.REPEATER.REPEATER_NAME)) {
209
+ const children = createXml(properties, parent, parentForNodes);
210
+ for (let item of children) {
211
+ item._order = xIndex || 0;
212
212
  }
213
- default: {
214
- componentProto = (0, util_1.findComponentInfo)(xComponent, {
215
- materialLibs: ctx.materialLibs,
216
- miniprogramPlugins: ctx.miniprogramPlugins,
217
- });
218
- if (!componentProto) {
219
- console.error(error(`Component(${xComponent.name}) not found in lib(${xComponent.moduleName}). ${helpMsg}`));
220
- continue;
221
- }
222
- const meta = (0, materials_1.getWxmlTag)(ctx, xComponent, nameMangler);
223
- tagName = meta.tagName;
224
- path = meta.path;
213
+ elements.push(...children);
214
+ continue;
215
+ }
216
+ else if ((0, util_1.isRepeaterWidget)(simpleWidget, config_1.REPEATER.REPEATER_ITEM_NAME)) {
217
+ tagName = 'block';
218
+ path = '';
219
+ }
220
+ else {
221
+ if (!componentProto) {
222
+ console.error(error(`Component(${xComponent.name}) not found in lib(${xComponent.moduleName}). ${helpMsg}`));
223
+ continue;
225
224
  }
225
+ const meta = (0, materials_1.getWxmlTag)(ctx, xComponent, nameMangler);
226
+ tagName = meta.tagName;
227
+ path = meta.path;
226
228
  }
227
229
  if (genericComp === null || genericComp === void 0 ? void 0 : genericComp.propName) {
228
230
  tagName = getGenericCompTagName(genericComp.propName);
@@ -259,7 +259,6 @@ async function downloadDependencies(targetDir, srcZipUrl) {
259
259
  }
260
260
  }
261
261
  exports.downloadDependencies = downloadDependencies;
262
- // TODO use yarn if installed
263
262
  async function installDependencies(targetDir, options = {}) {
264
263
  var _a;
265
264
  let yarnExists = false;
@@ -1,6 +1,6 @@
1
1
  import { IComponentInputProps, IComponentsInfoMap, IPackageJson } from '../types/common';
2
2
  import { IMaterialItem, IWeAppComponentInstance, IWeAppCode } from '@cloudbase/lowcode-generator/lib/weapps-core';
3
- export { getMetaInfoBySourceKey, isArray, isPlainObject, deepDeal, simpleDeepClone, deepDealSchema, getFileNameByUrl, } from '@cloudbase/lowcode-generator/lib/generator/util/common';
3
+ export { getMetaInfoBySourceKey, isArray, isPlainObject, deepDeal, simpleDeepClone, getFileNameByUrl, } from '@cloudbase/lowcode-generator/lib/generator/util/common';
4
4
  declare type PromiseResult<T> = Promise<[null, T] | [Error, null]>;
5
5
  export declare function promiseWrapper<T>(p: Promise<T>): PromiseResult<T>;
6
6
  export declare function getCurrentPackageJson(): {
@@ -14,7 +14,6 @@ export declare function JsonToStringWithVariableName(copyJson: any, options?: {
14
14
  export declare function requireUncached(module: any): any;
15
15
  export declare function removeRequireUncached(path?: string): void;
16
16
  export declare function getInputProps(componentsMetaMap: IComponentsInfoMap): IComponentInputProps;
17
- export declare function getComponentsInfo(appBuildDir: string, dependencies: IMaterialItem[]): Promise<IComponentsInfoMap>;
18
17
  export declare function getYyptConfigInfo(extraData: any): Promise<{
19
18
  yyptAppKey: any;
20
19
  reportUrl: any;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.normalizeWedaRoot = exports.normalizePackageName = exports.generateLowcodeImportor = exports.getCompileDirs = exports.deepDealComponentSchemaJson = exports.canUseVite = exports.isOfficialComponentLib = exports.readComponentLibMata = exports.writeLibCommonRes2file = exports.getYyptConfigInfo = exports.getComponentsInfo = exports.getInputProps = exports.removeRequireUncached = exports.requireUncached = exports.JsonToStringWithVariableName = exports.getSelfPackageJson = exports.getCurrentPackageJson = exports.promiseWrapper = exports.getFileNameByUrl = exports.deepDealSchema = exports.simpleDeepClone = exports.deepDeal = exports.isPlainObject = exports.isArray = exports.getMetaInfoBySourceKey = void 0;
6
+ exports.normalizeWedaRoot = exports.normalizePackageName = exports.generateLowcodeImportor = exports.getCompileDirs = exports.deepDealComponentSchemaJson = exports.canUseVite = exports.isOfficialComponentLib = exports.readComponentLibMata = exports.writeLibCommonRes2file = exports.getYyptConfigInfo = exports.getInputProps = exports.removeRequireUncached = exports.requireUncached = exports.JsonToStringWithVariableName = exports.getSelfPackageJson = exports.getCurrentPackageJson = exports.promiseWrapper = exports.getFileNameByUrl = exports.simpleDeepClone = exports.deepDeal = exports.isPlainObject = exports.isArray = exports.getMetaInfoBySourceKey = void 0;
7
7
  // import * as R from 'ramda'
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -19,7 +19,6 @@ Object.defineProperty(exports, "isArray", { enumerable: true, get: function () {
19
19
  Object.defineProperty(exports, "isPlainObject", { enumerable: true, get: function () { return common_1.isPlainObject; } });
20
20
  Object.defineProperty(exports, "deepDeal", { enumerable: true, get: function () { return common_1.deepDeal; } });
21
21
  Object.defineProperty(exports, "simpleDeepClone", { enumerable: true, get: function () { return common_1.simpleDeepClone; } });
22
- Object.defineProperty(exports, "deepDealSchema", { enumerable: true, get: function () { return common_1.deepDealSchema; } });
23
22
  Object.defineProperty(exports, "getFileNameByUrl", { enumerable: true, get: function () { return common_1.getFileNameByUrl; } });
24
23
  const homeDir = os_1.default.homedir();
25
24
  const commandConfigPath = path_1.default.join(homeDir, '.warc');
@@ -100,49 +99,6 @@ function getInputProps(componentsMetaMap) {
100
99
  return outputObj;
101
100
  }
102
101
  exports.getInputProps = getInputProps;
103
- async function getComponentsInfo(appBuildDir, dependencies) {
104
- const outputObj = {};
105
- await Promise.all(dependencies.map(async ({ name: materialName, version, components = [], isComposite }) => {
106
- if (isComposite) {
107
- components.forEach((component) => {
108
- let { lowCodes, componentInstances, ...compItem } = component;
109
- const sourceKey = `${materialName}:${compItem.name}`;
110
- outputObj[sourceKey] = {
111
- isComposite,
112
- ...compItem,
113
- };
114
- });
115
- }
116
- else {
117
- const materialComponentsPath = path_1.default.resolve(appBuildDir, `src/libraries/${materialName}@${version}/components`);
118
- const componentLibPath = path_1.default.resolve(appBuildDir, `src/libraries/${materialName}@${version}`);
119
- const meta = readComponentLibMata(componentLibPath);
120
- if (meta) {
121
- const { components: componentsMap } = meta;
122
- for (let name in componentsMap) {
123
- const sourceKey = `${materialName}:${name}`;
124
- let metaJson = componentsMap[name];
125
- outputObj[sourceKey] = { isComposite, ...metaJson };
126
- }
127
- }
128
- else {
129
- // 老格式,需要从子目录下读取
130
- const components = await fs_extra_1.default.readdir(materialComponentsPath);
131
- await Promise.all(components.map(async (name) => {
132
- const sourceKey = `${materialName}:${name}`;
133
- const componentMetaPath = `${materialComponentsPath}/${name}/meta.json`;
134
- let metaJson = {
135
- name,
136
- meta: await fs_extra_1.default.readJson(componentMetaPath),
137
- };
138
- outputObj[sourceKey] = { isComposite, ...metaJson };
139
- }));
140
- }
141
- }
142
- }));
143
- return outputObj;
144
- }
145
- exports.getComponentsInfo = getComponentsInfo;
146
102
  async function getYyptConfigInfo(extraData) {
147
103
  let configJson;
148
104
  try {
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { OutputType } from 'jszip';
3
3
  export declare const generatedFileContents: {};
4
- export default function generateFiles(appFileData: any, srcDir: string, dstDir: string): Promise<void>;
4
+ export default function generateFiles(appFileData: any, srcDir: string, dstDir: string, filter?: (src: any) => boolean): Promise<void>;
5
5
  export declare function writeFile(outFile: string, content: string): Promise<boolean>;
6
6
  export declare function removeFile(file: string): void;
7
7
  /**
@@ -35,7 +35,7 @@ const glob_1 = __importDefault(require("glob"));
35
35
  const jszip_1 = __importDefault(require("jszip"));
36
36
  const buffer_1 = require("buffer");
37
37
  exports.generatedFileContents = {}; // generated files for incrmental build
38
- async function generateFiles(appFileData, srcDir, dstDir) {
38
+ async function generateFiles(appFileData, srcDir, dstDir, filter = (src) => true) {
39
39
  const filesGenerated = [];
40
40
  // Generating file by template and data
41
41
  for (const file in appFileData) {
@@ -43,6 +43,10 @@ async function generateFiles(appFileData, srcDir, dstDir) {
43
43
  const srcFileName = fileNameList[0];
44
44
  const outFileName = fileNameList[1] || fileNameList[0];
45
45
  const srcePath = path_1.default.join(srcDir, srcFileName);
46
+ const use = filter ? filter(srcePath) : true;
47
+ if (!use) {
48
+ continue;
49
+ }
46
50
  if (fs_extra_1.default.lstatSync(srcePath).isDirectory()) {
47
51
  (0, exports.copyRecursiveSync)(srcePath, path_1.default.join(dstDir, outFileName));
48
52
  }