@cloudbase/lowcode-builder 0.1.5-mpbeta.0 → 0.1.5-mpbeta.1
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 +59 -0
- package/lib/builder/mp/util.js +14 -1
- package/lib/builder/mp/wxml.js +4 -0
- package/lib/builder.web.js +94 -0
- package/package.json +9 -9
- package/template/mp/common/util.js +2 -2
- package/template/mp/common/weapp-component.js +3 -3
- package/template/mp/common/weapp-page.js +4 -3
- package/template/mp/common/widget.js +10 -10
- package/template/mp/component/index.js +6 -4
- package/template/mp/page/index.js +7 -4
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
|
+
|
package/lib/builder/mp/util.js
CHANGED
|
@@ -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
|
}
|
package/lib/builder/mp/wxml.js
CHANGED
|
@@ -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);
|