@cloudbase/lowcode-builder 0.1.5-mp-beta → 0.1.5-mpbeta.2

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/README.md ADDED
@@ -0,0 +1,59 @@
1
+ ## 本包说明
2
+ - @cloudbase/lowcode-builder是微搭用于将DSL构建为小程序和web的构建包。
3
+ - 例子在__tests__/build.ts下
4
+ - 主要是在node环境下运行。由于微信IDE的背景,提供了web构建出小程序版本的功能。两种方式如何使用见以下示例
5
+
6
+ ## node端使用
7
+ 使用示例:
8
+ ```javascript
9
+ import { buildWedaApp } from '@cloudbase/lowcode-builder';
10
+ import { simpleData as data, options } from './data';
11
+ import path from 'path';
12
+ import fs from 'fs-extra';
13
+
14
+ const outPath = path.resolve(__dirname, '.temp');
15
+ fs.emptyDirSync(outPath);
16
+ buildWedaApp({
17
+ ...data,
18
+ ...options,
19
+ buildTypeList: ['web' as any],
20
+ output: { path: outPath },
21
+ }).then((dir) => {
22
+ console.log(dir);
23
+ });
24
+ ```
25
+
26
+ ## web端使用
27
+ 使用示例:
28
+ ```javascript
29
+ export async function builderToZip(builderData: any, selectedPageId: string, outputPath: string) {
30
+ return import('@cloudbase/lowcode-builder/lib/builder.web').then(async (result) => {
31
+ try {
32
+ console.log('rose builderToZip import result ', result);
33
+ const { buildWedaApp, getFiles, fileToZip, strToBuf } = result;
34
+
35
+ // 1、构建到指定路径,返回构建文件存放路径
36
+ const buildPath = await buildWedaApp(builderData);
37
+
38
+ // 2、从指定路径获取文件
39
+ const files = await getFiles(buildPath, {}, `${outputPath}/`);
40
+
41
+ // 3、修改app.json入口地址
42
+ const finalFiles = setEntryPage(files, selectedPageId, strToBuf);
43
+
44
+ // 4、得到zip包,返回主进程,传给微信hybrid
45
+ const zipFiles = await fileToZip(finalFiles, 'arraybuffer'); // blob or arraybuffer
46
+
47
+ return {
48
+ zipFiles,
49
+ strFiles: '', // TODO暂时保留,用于返回zip包内容
50
+ };
51
+ } catch (err) {
52
+ error('builder.worker.js->builderToZip->catch:', err);
53
+ throw err;
54
+ }
55
+ });
56
+ }
57
+ ```
58
+
59
+
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -3,6 +3,13 @@ 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
5
  export declare function installMaterials(projDir: string, usedComps: IUsedComps, weapps: IWeAppData[], ctx: IBuildContext): Promise<void>;
6
+ /**
7
+ * 过滤组件库文件
8
+ * @param src 源文件
9
+ * @param dest 目标文件
10
+ * @returns boolean
11
+ */
12
+ export declare function filterMaterial(src: any, dest: any): boolean;
6
13
  export declare function extractUsedCompsRecursively(comps: IUsedComps, checkedComps: ICompositedComponent[], compositedLibs: IMaterialItem[], outputComps?: IUsedComps): IUsedComps;
7
14
  /**
8
15
  * {
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
23
  return result;
20
24
  };
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getWxmlTag = exports.extractUsedCompsRecursively = exports.installMaterials = void 0;
26
+ exports.getWxmlTag = exports.extractUsedCompsRecursively = exports.filterMaterial = exports.installMaterials = void 0;
23
27
  const path = __importStar(require("path"));
24
28
  const util_1 = require("util");
25
29
  const fs = __importStar(require("fs-extra"));
@@ -88,7 +92,6 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
88
92
  const metaJosnPath = path.join(materialsSrcDir, 'meta.json');
89
93
  if (fs.existsSync(metaJosnPath)) {
90
94
  !isBrowserMpBuilder ? await fs.copy(metaJosnPath, path.join(targetDir, 'meta.json')) : (0, generateFiles_1.copyRecursiveSync)(metaJosnPath, path.join(targetDir, 'meta.json'));
91
- ;
92
95
  }
93
96
  // #3 copy 组件库代码文件到项目目录
94
97
  !isBrowserMpBuilder ? await fs.copy(materialsSrcDirPath, targetDir, {
@@ -96,7 +99,9 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
96
99
  const path = src.split('/');
97
100
  return !junk.is(path[path.length - 1]);
98
101
  },
99
- }) : (0, generateFiles_1.copyRecursiveSync)(materialsSrcDirPath, targetDir);
102
+ }) : (0, generateFiles_1.copyRecursiveSync)(materialsSrcDirPath, targetDir, {
103
+ filter: filterMaterial,
104
+ });
100
105
  }
101
106
  else {
102
107
  console.log(`Copying material ${materialId} from ${materialsSrcDir} to ${targetDir}`);
@@ -106,7 +111,9 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
106
111
  const path = src.split('/');
107
112
  return !junk.is(path[path.length - 1]);
108
113
  },
109
- }) : (0, generateFiles_1.copyRecursiveSync)(materialsSrcDir, targetDir);
114
+ }) : (0, generateFiles_1.copyRecursiveSync)(materialsSrcDir, targetDir, {
115
+ filter: filterMaterial,
116
+ });
110
117
  }
111
118
  }
112
119
  const libMeta = (0, util_4.readComponentLibMata)(targetDir);
@@ -170,6 +177,17 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
170
177
  }));
171
178
  }
172
179
  exports.installMaterials = installMaterials;
180
+ /**
181
+ * 过滤组件库文件
182
+ * @param src 源文件
183
+ * @param dest 目标文件
184
+ * @returns boolean
185
+ */
186
+ function filterMaterial(src, dest) {
187
+ const srcPath = src.split('/');
188
+ return !junk.is(srcPath[srcPath.length - 1]);
189
+ }
190
+ exports.filterMaterial = filterMaterial;
173
191
  // 递归查询复合组件所使用的组件
174
192
  function extractUsedCompsRecursively(comps, checkedComps, compositedLibs, outputComps) {
175
193
  let usedComps = (outputComps || comps);
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -102,8 +106,8 @@ function generateMpConfig(weapps, ctx) {
102
106
  appConfig.plugins = plugins;
103
107
  }
104
108
  miniprogramPlugins.forEach((plugin) => {
105
- var _a, _b;
106
- if (!((_b = (_a = appConfig) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b[plugin.name])) {
109
+ var _a;
110
+ if (!((_a = appConfig === null || appConfig === void 0 ? void 0 : appConfig.plugins) === null || _a === void 0 ? void 0 : _a[plugin.name])) {
107
111
  (0, lodash_1.set)(appConfig, `plugins.${plugin.name}`, {
108
112
  version: plugin.version,
109
113
  provider: plugin.pluginAppId,
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -111,7 +111,7 @@ exports.createWidgetProps = createWidgetProps;
111
111
  function createEventHanlders(widgets, componentApi, ctx) {
112
112
  const eventHanlders = {};
113
113
  (0, weapp_1.walkThroughWidgets)(widgets, (id, widget, parentId) => {
114
- var _a, _b;
114
+ var _a, _b, _c;
115
115
  const { xComponent } = widget;
116
116
  const xProps = widget.xProps || {};
117
117
  if (!xComponent) {
@@ -175,6 +175,19 @@ function createEventHanlders(widgets, componentApi, ctx) {
175
175
  type: l.type,
176
176
  });
177
177
  });
178
+ // 如果是数据容器,则生成一个onDataChange事件处理
179
+ if ((_c = compProto === null || compProto === void 0 ? void 0 : compProto.compConfig) === null || _c === void 0 ? void 0 : _c.isDataContainer) {
180
+ const customName = (0, wxml_1.getMpEventHanlderName)(id, 'onDataChange', {});
181
+ eventHanlders[customName] = [{
182
+ key: '',
183
+ handler: `({event})=>{
184
+ app.utils.set(context, '${id}.data', event?.detail?.data);
185
+ }`,
186
+ handlerModule: weapps_core_1.ActionType.Platform,
187
+ data: {},
188
+ boundData: {},
189
+ }];
190
+ }
178
191
  });
179
192
  return eventHanlders;
180
193
  }
@@ -205,6 +205,10 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
205
205
  });
206
206
  // 扩展组件配置
207
207
  const compConfig = componentProto.compConfig;
208
+ // 如果是数据容器,则增加一个onDataChange事件 bind:onDataChange="onid1$onDataChange"
209
+ if (compConfig === null || compConfig === void 0 ? void 0 : compConfig.isDataContainer) {
210
+ node.attributes['bind:onDataChange'] = getMpEventHanlderName(id, 'onDataChange');
211
+ }
208
212
  if (compConfig && compConfig.pluginConfig) {
209
213
  if (compConfig.pluginConfig.attributes) {
210
214
  Object.assign(node.attributes, compConfig.pluginConfig.attributes);
@@ -21,13 +21,15 @@ export declare function copy(src: string, dest: string): Promise<void>;
21
21
  * @param source 源文件
22
22
  * @param target 目标文件
23
23
  */
24
- export declare function copyFileSync(source: any, target: any): void;
24
+ export declare function copyFileSync(source: string, target: string): void;
25
25
  /**
26
26
  * 根据源文件目录,输出目录,递归复制文件
27
27
  * @param {string} src 源文件目录
28
28
  * @param {string} dest 输出目录
29
29
  */
30
- export declare const copyRecursiveSync: (src: any, dest: any) => void;
30
+ export declare const copyRecursiveSync: (src: string, dest: string, options?: {
31
+ filter: (src: string, dest: string) => boolean;
32
+ } | undefined) => void;
31
33
  /**
32
34
  * 返回指定目录的文件列表内容,返回map格式
33
35
  * @param dir 指定目录
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -143,17 +147,20 @@ exports.copyFileSync = copyFileSync;
143
147
  * @param {string} src 源文件目录
144
148
  * @param {string} dest 输出目录
145
149
  */
146
- const copyRecursiveSync = function (src, dest) {
147
- var exists = fs_extra_1.default.existsSync(src);
148
- var stats = exists && fs_extra_1.default.statSync(src);
149
- var isDirectory = exists && stats.isDirectory();
150
+ const copyRecursiveSync = function (src, dest, options) {
151
+ const exists = fs_extra_1.default.existsSync(src);
152
+ if (!exists || (options && options.filter && !options.filter(src, dest))) {
153
+ return;
154
+ }
155
+ const stats = fs_extra_1.default.statSync(src);
156
+ const isDirectory = stats.isDirectory();
150
157
  if (!fs_extra_1.default.existsSync(dest)) {
151
158
  mkDirByPathSync(path_1.default.parse(dest).dir);
152
159
  }
153
160
  if (isDirectory) {
154
161
  const files = fs_extra_1.default.readdirSync(src);
155
162
  files.forEach(function (childItemName) {
156
- (0, exports.copyRecursiveSync)(path_1.default.join(src, childItemName), path_1.default.join(dest, childItemName));
163
+ (0, exports.copyRecursiveSync)(path_1.default.join(src, childItemName), path_1.default.join(dest, childItemName), options);
157
164
  });
158
165
  }
159
166
  else {
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -20,7 +20,10 @@ const ignoreList = [
20
20
  '^Thumbs\\.db$',
21
21
  '^ehthumbs\\.db$',
22
22
  '^Desktop\\.ini$',
23
- '@eaDir$', // Synology Diskstation "hidden" folder where the server stores thumbnails
23
+ '@eaDir$',
24
+ '^.gitignore$',
25
+ '^readme.md$',
26
+ '^README.md$',
24
27
  ];
25
28
  const regex = new RegExp(ignoreList.join('|'));
26
29
  const is = (filename) => regex.test(filename);
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];