@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.
- package/lib/builder/core/index.d.ts +9 -0
- package/lib/builder/core/index.js +118 -7
- package/lib/builder/h5/generate.d.ts +1 -1
- package/lib/builder/h5/index.d.ts +2 -2
- package/lib/builder/h5/index.js +24 -6
- package/lib/builder/h5/webpack.d.ts +2 -2
- package/lib/builder/mp/BuildContext.d.ts +18 -14
- package/lib/builder/mp/index.d.ts +11 -1
- package/lib/builder/mp/index.js +98 -85
- package/lib/builder/mp/lowcode.d.ts +5 -3
- package/lib/builder/mp/lowcode.js +14 -5
- package/lib/builder/mp/materials.d.ts +10 -5
- package/lib/builder/mp/materials.js +139 -135
- package/lib/builder/mp/util.d.ts +15 -12
- package/lib/builder/mp/util.js +50 -22
- package/lib/builder/mp/wxml.d.ts +5 -3
- package/lib/builder/mp/wxml.js +29 -27
- package/lib/builder/service/webpack.js +0 -1
- package/lib/builder/util/common.d.ts +1 -2
- package/lib/builder/util/common.js +1 -45
- package/lib/builder/util/generateFiles.d.ts +1 -1
- package/lib/builder/util/generateFiles.js +5 -1
- package/lib/builder.web.js +8 -55
- package/package.json +2 -2
- package/template/html/index.html.ejs +7 -3
- package/template/mp/app/weapps-api.js +1 -1
- package/template/mp/app.js +4 -2
- package/template/mp/common/cloud-sdk.js +28 -0
- package/template/mp/common/data-patch.js +18 -3
- package/template/mp/common/util.js +6 -2
- package/template/mp/common/watch.js +1 -1
- package/template/mp/common/weapp-component.js +5 -5
- package/template/mp/common/weapp-page.js +4 -3
- package/template/mp/common/widget.js +51 -38
- package/template/mp/component/index.js +7 -6
- package/template/mp/datasources/index.js.tpl +2 -30
- package/template/mp/package.json +3 -3
- package/template/webpack/web.prod.js +1 -1
|
@@ -9,9 +9,16 @@ const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
|
|
|
9
9
|
const style_1 = require("@cloudbase/lowcode-generator/lib/generator/util/style");
|
|
10
10
|
const generateFiles_1 = require("../util/generateFiles");
|
|
11
11
|
const cals_1 = require("@cloudbase/cals");
|
|
12
|
-
async function writeCode2file(ctx, mod, lowcodeRootDir, opts = {}, themeCode) {
|
|
12
|
+
async function writeCode2file(ctx, mod, lowcodeRootDir, opts = {}, themeCode, externalAPIImport) {
|
|
13
13
|
const { pageId = 'global', appDir, comp } = opts;
|
|
14
14
|
const file = path_1.default.join(lowcodeRootDir, (0, weapps_core_1.getCodeModuleFilePath)(pageId || 'global', mod, { style: '.wxss' }));
|
|
15
|
+
function importFromClientSDK(with$w) {
|
|
16
|
+
return [
|
|
17
|
+
`import { getWedaAPI } from '@cloudbase/weda-client';`,
|
|
18
|
+
'const app = new Proxy({}, { get: function(obj, prop){ return getWedaAPI()?.app?.[prop] }});',
|
|
19
|
+
'const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});',
|
|
20
|
+
].concat(with$w ? ['const $w = new Proxy({}, { get: function(obj, prop){ return getWedaAPI()?.$w?.[prop] }});'] : []);
|
|
21
|
+
}
|
|
15
22
|
let { code } = mod;
|
|
16
23
|
if (mod.type !== cals_1.ECodeType.STYLE && mod.type !== cals_1.ECodeType.THEME) {
|
|
17
24
|
if (appDir) {
|
|
@@ -19,9 +26,9 @@ async function writeCode2file(ctx, mod, lowcodeRootDir, opts = {}, themeCode) {
|
|
|
19
26
|
const baseDir = path_1.default.relative(path_1.default.dirname(file), appDir).replace(/\\/g, '/');
|
|
20
27
|
// 子包混合模式需要添加相对索引到根目录
|
|
21
28
|
const relativeRoot = (ctx === null || ctx === void 0 ? void 0 : ctx.isMixMode) && ctx.rootPath ? `${path_1.default.relative(`packages/${ctx.rootPath}`, '')}/` : '';
|
|
22
|
-
let weappsApiPrefix =
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
let weappsApiPrefix = externalAPIImport
|
|
30
|
+
? importFromClientSDK(pageId === 'global')
|
|
31
|
+
: [`import { app, $app${pageId !== 'global' ? '' : ', $w'} } from '${relativeRoot}${baseDir}/app/weapps-api';`]; // windows compatibility
|
|
25
32
|
if (pageId !== 'global') {
|
|
26
33
|
weappsApiPrefix.push(`import { $page, $w } from '${baseDir}/pages/${pageId}/api';`);
|
|
27
34
|
}
|
|
@@ -29,7 +36,9 @@ async function writeCode2file(ctx, mod, lowcodeRootDir, opts = {}, themeCode) {
|
|
|
29
36
|
}
|
|
30
37
|
else {
|
|
31
38
|
// Generate component lowcode
|
|
32
|
-
code =
|
|
39
|
+
code = `${externalAPIImport
|
|
40
|
+
? importFromClientSDK(true).join('\n')
|
|
41
|
+
: `import { app, $app, $w } from '${mod.type === 'handler-fn' ? '../' : ''}../../../../app/weapps-api';`}\n${code.replace(/\$comp/g, weapps_core_1.COMPONENT_API_PREFIX)}`;
|
|
33
42
|
}
|
|
34
43
|
}
|
|
35
44
|
else {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { IWeAppComponentInstance
|
|
2
|
-
import { IBuildContext } from './BuildContext';
|
|
1
|
+
import { IWeAppComponentInstance } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
|
+
import { IBuildContext, IMpCommonBuildContext } 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
|
|
5
|
+
export declare function normalizeCompositeDependienciesForBuild(lib: any): any;
|
|
6
|
+
declare type TInstallMaterialsType = 'lib' | 'inline';
|
|
7
|
+
export declare function installMaterials(ctx: IMpCommonBuildContext, outDir: string, usedMeta?: {
|
|
6
8
|
component: IUsedComps;
|
|
7
9
|
action: IUsedComps;
|
|
8
|
-
},
|
|
10
|
+
}, mode?: TInstallMaterialsType): Promise<void>;
|
|
9
11
|
/**
|
|
10
12
|
* 过滤组件库文件
|
|
11
13
|
* @param src 源文件
|
|
@@ -13,10 +15,13 @@ export declare function installMaterials(ctx: IBuildContext, outDir: string, use
|
|
|
13
15
|
* @returns boolean
|
|
14
16
|
*/
|
|
15
17
|
export declare function filterMaterial(src: any, dest: any): boolean;
|
|
16
|
-
export declare function getWxmlTag(ctx:
|
|
18
|
+
export declare function getWxmlTag(ctx: IMpCommonBuildContext & {
|
|
19
|
+
wedaRoot?: IBuildContext['wedaRoot'];
|
|
20
|
+
}, cmp: Required<IWeAppComponentInstance>['xComponent'], nameMangler?: NameMangler): {
|
|
17
21
|
tagName: string;
|
|
18
22
|
path?: undefined;
|
|
19
23
|
} | {
|
|
20
24
|
tagName: string;
|
|
21
25
|
path: any;
|
|
22
26
|
};
|
|
27
|
+
export {};
|
|
@@ -26,15 +26,14 @@ 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.filterMaterial = exports.installMaterials = void 0;
|
|
29
|
+
exports.getWxmlTag = exports.filterMaterial = exports.installMaterials = exports.normalizeCompositeDependienciesForBuild = void 0;
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
|
-
const util_1 = require("util");
|
|
32
31
|
const fs = __importStar(require("fs-extra"));
|
|
33
32
|
const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
|
|
34
33
|
const config_1 = require("../config");
|
|
35
34
|
const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
|
|
36
|
-
const
|
|
37
|
-
const
|
|
35
|
+
const util_1 = require("../util");
|
|
36
|
+
const util_2 = require("./util");
|
|
38
37
|
const wxml_1 = require("./wxml");
|
|
39
38
|
const generateFiles_1 = __importStar(require("../util/generateFiles"));
|
|
40
39
|
const lowcode_1 = require("./lowcode");
|
|
@@ -43,12 +42,63 @@ const name_mangler_1 = __importDefault(require("@cloudbase/lowcode-generator/lib
|
|
|
43
42
|
const junk = __importStar(require("../util/junk"));
|
|
44
43
|
const cals_1 = require("@cloudbase/cals");
|
|
45
44
|
const templateDir = `${config_1.appTemplateDir}/mp/`;
|
|
46
|
-
|
|
45
|
+
function normalizeCompositeDependienciesForBuild(lib) {
|
|
46
|
+
lib.dependencies = lib.dependencies || {};
|
|
47
|
+
lib.components.map((cmp) => {
|
|
48
|
+
// populate cmp.materialName
|
|
49
|
+
cmp.materialName = lib.name;
|
|
50
|
+
cmp.meta.syncProps = {};
|
|
51
|
+
const { dataForm = {} } = cmp;
|
|
52
|
+
for (const prop in dataForm) {
|
|
53
|
+
const { inputProp, syncProp } = dataForm[prop];
|
|
54
|
+
if (syncProp || inputProp) {
|
|
55
|
+
cmp.meta.syncProps[prop] = syncProp || inputProp;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (lib.isComposite) {
|
|
59
|
+
cmp.meta.platforms = {
|
|
60
|
+
mp: {
|
|
61
|
+
path: `${cmp.name}/index`,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
lib.dependencies = { ...lib.dependencies, ...cmp.npmDependencies };
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return lib;
|
|
68
|
+
}
|
|
69
|
+
exports.normalizeCompositeDependienciesForBuild = normalizeCompositeDependienciesForBuild;
|
|
70
|
+
async function generateCompLibs(ctx, outDir, mode) {
|
|
71
|
+
const { materialLibs } = ctx;
|
|
72
|
+
// Collection infomation from components to lib meta
|
|
73
|
+
const compositedLibs = materialLibs.filter((lib) => lib.isComposite);
|
|
74
|
+
const reg = new RegExp(`${cals_1.SPINOFF_SUFFIX}$`);
|
|
75
|
+
// #2 Generate composited libs
|
|
76
|
+
await Promise.all(compositedLibs.map(async (lib) => {
|
|
77
|
+
console.log(`Generate composited library ${lib.name}`);
|
|
78
|
+
await Promise.all(lib.components.map(async (cmp) => {
|
|
79
|
+
return generateCompositeComponent({
|
|
80
|
+
...ctx,
|
|
81
|
+
/**
|
|
82
|
+
* 此处强行覆盖为 rpx 是为了兼容老的复合组件
|
|
83
|
+
* $template, 和单独lib构建应受控,跟随应用的配置
|
|
84
|
+
*/
|
|
85
|
+
processCssUnit: lib.name === cals_1.OFFICIAL_COMPONENT_LIB_NAME || reg.test(lib.name) ? 'rpx' : ctx.processCssUnit,
|
|
86
|
+
// 只生成在主目录中,减少冗余
|
|
87
|
+
// rootPath: app.rootPath || '', // 主包是没有 rootPath 的
|
|
88
|
+
}, cmp, outDir, lib.rootPath !== undefined ? lib.rootPath : path.join(config_1.materialsDirName, lib.name), lib.compLibCommonResource, mode);
|
|
89
|
+
}));
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
async function installMaterials(ctx, outDir, usedMeta, mode) {
|
|
47
93
|
let { materialLibs: _materialLibs, isBrowserMpBuilder } = ctx;
|
|
48
|
-
|
|
49
|
-
|
|
94
|
+
let materialLibs = _materialLibs.filter((lib) => {
|
|
95
|
+
if (!usedMeta) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
return usedMeta.component[lib.name] || usedMeta.action[lib.name];
|
|
99
|
+
});
|
|
50
100
|
// #1 Download uploaded libs
|
|
51
|
-
const localPkg = (0,
|
|
101
|
+
const localPkg = (0, util_1.getCurrentPackageJson)();
|
|
52
102
|
await Promise.all(materialLibs
|
|
53
103
|
.filter((lib) => !lib.isComposite)
|
|
54
104
|
.map(async (lib) => {
|
|
@@ -66,7 +116,7 @@ async function installMaterials(ctx, outDir, usedMeta, weapps) {
|
|
|
66
116
|
await downloadMaterial(mpPkgUrl, materialsSrcDir, ctx.isBrowserMpBuilder, noCache);
|
|
67
117
|
}
|
|
68
118
|
function libUpdated(libDir, version) {
|
|
69
|
-
const meta = (0,
|
|
119
|
+
const meta = (0, util_1.readComponentLibMata)(libDir);
|
|
70
120
|
if (!meta) {
|
|
71
121
|
return true;
|
|
72
122
|
}
|
|
@@ -74,120 +124,68 @@ async function installMaterials(ctx, outDir, usedMeta, weapps) {
|
|
|
74
124
|
return true;
|
|
75
125
|
}
|
|
76
126
|
}
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
else {
|
|
86
|
-
usingMaterialMap[targetDir] = true;
|
|
87
|
-
}
|
|
88
|
-
if (libUpdated(targetDir, version)) {
|
|
89
|
-
const materialsSrcDirPath = path.join(materialsSrcDir, 'src');
|
|
90
|
-
if (fs.existsSync(materialsSrcDirPath)) {
|
|
91
|
-
console.log(`Copying material ${materialId} from ${isBrowserMpBuilder ? materialsSrcDirPath : materialsSrcDir}/src to ${targetDir}`);
|
|
92
|
-
// #2 从根目录 copy meta 文件
|
|
93
|
-
const metaJosnPath = path.join(materialsSrcDir, 'meta.json');
|
|
94
|
-
if (fs.existsSync(metaJosnPath)) {
|
|
95
|
-
!isBrowserMpBuilder
|
|
96
|
-
? await fs.copy(metaJosnPath, path.join(targetDir, 'meta.json'))
|
|
97
|
-
: (0, generateFiles_1.copyRecursiveSync)(metaJosnPath, path.join(targetDir, 'meta.json'));
|
|
98
|
-
}
|
|
99
|
-
// #3 copy 组件库代码文件到项目目录
|
|
100
|
-
!isBrowserMpBuilder
|
|
101
|
-
? await fs.copy(materialsSrcDirPath, targetDir, {
|
|
102
|
-
filter(src, dest) {
|
|
103
|
-
const path = src.split('/');
|
|
104
|
-
return !junk.is(path[path.length - 1]);
|
|
105
|
-
},
|
|
106
|
-
})
|
|
107
|
-
: (0, generateFiles_1.copyRecursiveSync)(materialsSrcDirPath, targetDir, {
|
|
108
|
-
filter: filterMaterial,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
console.log(`Copying material ${materialId} from ${materialsSrcDir} to ${targetDir}`);
|
|
113
|
-
// #2 link material to current project
|
|
127
|
+
const targetDir = path.join(outDir, config_1.materialsDirName, name);
|
|
128
|
+
if (libUpdated(targetDir, version)) {
|
|
129
|
+
const materialsSrcDirPath = path.join(materialsSrcDir, 'src');
|
|
130
|
+
if (fs.existsSync(materialsSrcDirPath)) {
|
|
131
|
+
console.log(`Copying material ${materialId} from ${isBrowserMpBuilder ? materialsSrcDirPath : materialsSrcDir}/src to ${targetDir}`);
|
|
132
|
+
// #2 从根目录 copy meta 文件
|
|
133
|
+
const metaJosnPath = path.join(materialsSrcDir, 'meta.json');
|
|
134
|
+
if (fs.existsSync(metaJosnPath)) {
|
|
114
135
|
!isBrowserMpBuilder
|
|
115
|
-
? await fs.copy(
|
|
116
|
-
|
|
117
|
-
const path = src.split('/');
|
|
118
|
-
return !junk.is(path[path.length - 1]);
|
|
119
|
-
},
|
|
120
|
-
})
|
|
121
|
-
: (0, generateFiles_1.copyRecursiveSync)(materialsSrcDir, targetDir, {
|
|
122
|
-
filter: filterMaterial,
|
|
123
|
-
});
|
|
136
|
+
? await fs.copy(metaJosnPath, path.join(targetDir, 'meta.json'))
|
|
137
|
+
: (0, generateFiles_1.copyRecursiveSync)(metaJosnPath, path.join(targetDir, 'meta.json'));
|
|
124
138
|
}
|
|
139
|
+
// #3 copy 组件库代码文件到项目目录
|
|
140
|
+
!isBrowserMpBuilder
|
|
141
|
+
? await fs.copy(materialsSrcDirPath, targetDir, {
|
|
142
|
+
filter: filterMaterial,
|
|
143
|
+
})
|
|
144
|
+
: (0, generateFiles_1.copyRecursiveSync)(materialsSrcDirPath, targetDir, {
|
|
145
|
+
filter: filterMaterial,
|
|
146
|
+
});
|
|
125
147
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
148
|
+
else {
|
|
149
|
+
console.log(`Copying material ${materialId} from ${materialsSrcDir} to ${targetDir}`);
|
|
150
|
+
// #2 link material to current project
|
|
151
|
+
!isBrowserMpBuilder
|
|
152
|
+
? await fs.copy(materialsSrcDir, targetDir, {
|
|
153
|
+
filter(src, dest) {
|
|
154
|
+
const path = src.split('/');
|
|
155
|
+
return !junk.is(path[path.length - 1]);
|
|
156
|
+
},
|
|
157
|
+
})
|
|
158
|
+
: (0, generateFiles_1.copyRecursiveSync)(materialsSrcDir, targetDir, {
|
|
159
|
+
filter: filterMaterial,
|
|
133
160
|
});
|
|
134
|
-
});
|
|
135
161
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
162
|
+
}
|
|
163
|
+
const libMeta = (0, util_1.readComponentLibMata)(targetDir);
|
|
164
|
+
if (!lib.components) {
|
|
165
|
+
lib.components = Object.keys((libMeta === null || libMeta === void 0 ? void 0 : libMeta.components) || {}).map((name) => {
|
|
166
|
+
var _a;
|
|
167
|
+
return ({
|
|
168
|
+
name,
|
|
169
|
+
meta: (_a = libMeta === null || libMeta === void 0 ? void 0 : libMeta.components[name]) === null || _a === void 0 ? void 0 : _a.meta,
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
lib.styles = libMeta === null || libMeta === void 0 ? void 0 : libMeta.styles;
|
|
174
|
+
lib.dependencies = libMeta === null || libMeta === void 0 ? void 0 : libMeta.dependencies;
|
|
139
175
|
}));
|
|
140
176
|
// clean unused comps
|
|
141
|
-
ctx.materialLibs = materialLibs;
|
|
142
177
|
materialLibs.forEach((lib) => {
|
|
143
|
-
lib.components = lib.components.filter((comp) => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
lib.components.map((comp) => {
|
|
148
|
-
comp.materialName = lib.name;
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
materialLibs.map((lib) => {
|
|
152
|
-
lib.dependencies = lib.dependencies || {};
|
|
153
|
-
lib.components.map((cmp) => {
|
|
154
|
-
cmp.meta.syncProps = {};
|
|
155
|
-
const { dataForm = {} } = cmp;
|
|
156
|
-
for (const prop in dataForm) {
|
|
157
|
-
const { inputProp, syncProp } = dataForm[prop];
|
|
158
|
-
if (syncProp || inputProp) {
|
|
159
|
-
cmp.meta.syncProps[prop] = syncProp || inputProp;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (lib.isComposite) {
|
|
163
|
-
cmp.meta.platforms = {
|
|
164
|
-
mp: {
|
|
165
|
-
path: `${cmp.name}/index`,
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
lib.dependencies = { ...lib.dependencies, ...cmp.npmDependencies };
|
|
178
|
+
lib.components = lib.components.filter((comp) => {
|
|
179
|
+
var _a, _b;
|
|
180
|
+
if (!usedMeta) {
|
|
181
|
+
return true;
|
|
169
182
|
}
|
|
183
|
+
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);
|
|
170
184
|
});
|
|
185
|
+
normalizeCompositeDependienciesForBuild(lib);
|
|
171
186
|
});
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
// #2 Generate composited libs
|
|
175
|
-
await Promise.all(compositedLibs.map(async (lib) => {
|
|
176
|
-
console.log(`Generate composited library ${lib.name}`);
|
|
177
|
-
await (0, util_2.writeLibCommonRes2file)(lib, path.join(outDir, config_1.materialsDirName, lib.name, 'libCommonRes'));
|
|
178
|
-
await Promise.all(lib.components.map(async (cmp) => {
|
|
179
|
-
return generateCompositeComponent({
|
|
180
|
-
...ctx,
|
|
181
|
-
/**
|
|
182
|
-
* 此处强行覆盖为 rpx 是为了兼容老的复合组件
|
|
183
|
-
* $template 应该跟随应用的配置
|
|
184
|
-
*/
|
|
185
|
-
processCssUnit: lib.name !== '$template' ? 'rpx' : ctx.processCssUnit,
|
|
186
|
-
// 只生成在主目录中,减少冗余
|
|
187
|
-
// rootPath: app.rootPath || '', // 主包是没有 rootPath 的
|
|
188
|
-
}, cmp, path.join(outDir, config_1.materialsDirName), lib.compLibCommonResource);
|
|
189
|
-
}));
|
|
190
|
-
}));
|
|
187
|
+
ctx.materialLibs = materialLibs;
|
|
188
|
+
await generateCompLibs(ctx, outDir, mode);
|
|
191
189
|
}
|
|
192
190
|
exports.installMaterials = installMaterials;
|
|
193
191
|
/**
|
|
@@ -206,21 +204,17 @@ async function downloadMaterial(zipUrl, dstFolder, isBrowser = false, noCache =
|
|
|
206
204
|
return;
|
|
207
205
|
await (0, net_1.downloadZip)(zipUrl, dstFolder, isBrowser, noCache);
|
|
208
206
|
}
|
|
209
|
-
async function generateCompositeComponent(
|
|
210
|
-
const compositeCtx = {
|
|
211
|
-
...ctx,
|
|
212
|
-
isPage: false,
|
|
213
|
-
enableLoading: false,
|
|
214
|
-
};
|
|
207
|
+
async function generateCompositeComponent(compositeCtx, compositedComp, lowcalWedaRoot, componentLibRoot, compLibCommonResource, mode = 'inline') {
|
|
215
208
|
const { materialName } = compositedComp;
|
|
216
|
-
const
|
|
209
|
+
const componentRelativeDir = path.posix.join(componentLibRoot, compositedComp.name);
|
|
210
|
+
const componentDir = path.join(lowcalWedaRoot, componentLibRoot, compositedComp.name);
|
|
217
211
|
const LOWCODE_DIR_NAME = 'lowcode';
|
|
218
212
|
console.log(`Generating composited component ${materialName}:${compositedComp.name} to ${componentDir}`);
|
|
219
213
|
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!compositeCtx.isProduction);
|
|
220
214
|
// # Generating page
|
|
221
215
|
const usingComponents = {};
|
|
222
216
|
const componentGenerics = {};
|
|
223
|
-
const componentInstances = (0,
|
|
217
|
+
const componentInstances = (0, util_2.processRepeaterSchema)(compositeCtx, compositedComp.componentInstances);
|
|
224
218
|
const cmpContainer = Object.values(componentInstances)[0];
|
|
225
219
|
const wxml = (0, wxml_1.generateWxml)(compositeCtx, componentInstances, `Component ${materialName}:${compositedComp.name}`, wxmlDataPrefix, usingComponents, componentGenerics, (cmp, node) => {
|
|
226
220
|
if (cmp === cmpContainer) {
|
|
@@ -233,7 +227,7 @@ async function generateCompositeComponent(ctx, compositedComp, outDir, compLibCo
|
|
|
233
227
|
}
|
|
234
228
|
});
|
|
235
229
|
// prepare form field change events
|
|
236
|
-
const { syncProps } = compositedComp.meta;
|
|
230
|
+
const { syncProps = {} } = compositedComp.meta;
|
|
237
231
|
const formEvents = {};
|
|
238
232
|
Object.keys(syncProps).map((prop) => {
|
|
239
233
|
const config = syncProps[prop];
|
|
@@ -251,39 +245,46 @@ async function generateCompositeComponent(ctx, compositedComp, outDir, compLibCo
|
|
|
251
245
|
}
|
|
252
246
|
});
|
|
253
247
|
const codes = (0, cals_1.processRuntimeCodeResources)({ id: '$comp' }, compositedComp.lowCodes, 'component');
|
|
254
|
-
const importor = (0,
|
|
248
|
+
const importor = (0, util_1.generateLowcodeImportor)(codes);
|
|
255
249
|
const pageFileData = {
|
|
256
250
|
'index.js': {
|
|
251
|
+
relativeWedaRoot: path.posix.relative(path.posix.join('/', componentRelativeDir), '/') || '.',
|
|
257
252
|
materialName,
|
|
258
253
|
propDefs,
|
|
259
254
|
handlers: compositedComp.lowCodes
|
|
260
255
|
.filter((m) => m.type === cals_1.ECodeType.HANDLER_FN && m.name !== cals_1.ECodeName.PLACEHOLDER)
|
|
261
256
|
.map((m) => m.name),
|
|
262
|
-
eventHandlers: (0,
|
|
263
|
-
// protectEventKeys: builtinMpEvents,
|
|
257
|
+
eventHandlers: (0, util_2.createEventHandlers)(compositeCtx, componentInstances, weapps_core_1.COMPONENT_API_PREFIX),
|
|
264
258
|
emitEvents: (compositedComp.emitEvents || []).map((evt) => evt.eventName),
|
|
265
|
-
widgetProps: (0,
|
|
259
|
+
widgetProps: (0, util_2.createWidgetProps)(compositeCtx, componentInstances),
|
|
266
260
|
compApi: weapps_core_1.COMPONENT_API_PREFIX,
|
|
267
261
|
jsonSchemaType2jsClass: mp_1.jsonSchemaType2jsClass,
|
|
268
|
-
key: `${
|
|
269
|
-
dataBinds: (0,
|
|
262
|
+
key: `${materialName}:${compositedComp.name}`,
|
|
263
|
+
dataBinds: (0, util_2.createDataBinds)(compositeCtx, componentInstances),
|
|
270
264
|
debug: !compositeCtx.isProduction,
|
|
271
|
-
/**
|
|
272
|
-
* @deprecated
|
|
273
|
-
*/
|
|
274
|
-
stringifyObj: util_1.inspect,
|
|
275
265
|
// dataPropNames: wxmlDataPrefix,
|
|
276
266
|
formEvents: Object.keys(formEvents).length > 0 ? formEvents : null,
|
|
277
267
|
config: compositedComp.compConfig,
|
|
278
268
|
importor,
|
|
279
269
|
},
|
|
280
|
-
'index.json': {
|
|
270
|
+
'index.json': {
|
|
271
|
+
usingComponents: Object.entries(usingComponents).reduce((map, [key, value]) => {
|
|
272
|
+
if (new RegExp(`^${path.posix.join('/', compositeCtx.wedaRoot || '', '\\w')}`).test(value)) {
|
|
273
|
+
map[key] = path.posix.relative(path.posix.join('/', compositeCtx.wedaRoot || '', componentRelativeDir), value);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
map[key] = value;
|
|
277
|
+
}
|
|
278
|
+
return map;
|
|
279
|
+
}, {}),
|
|
280
|
+
componentGenerics,
|
|
281
|
+
},
|
|
281
282
|
'index.wxml': {
|
|
282
283
|
content: wxml,
|
|
283
284
|
},
|
|
284
285
|
'index.wxss': {
|
|
285
286
|
importStyles: importor.styles.map((mod) => path.posix.join(LOWCODE_DIR_NAME, (0, weapps_core_1.getCodeModuleFilePath)('global', mod, { style: '.wxss' }))),
|
|
286
|
-
content: (0,
|
|
287
|
+
content: (0, util_2.generateScopedStyleText)(componentInstances),
|
|
287
288
|
},
|
|
288
289
|
};
|
|
289
290
|
// Generating file by template and data
|
|
@@ -315,7 +316,7 @@ async function generateCompositeComponent(ctx, compositedComp, outDir, compLibCo
|
|
|
315
316
|
if (mod.name === 'index') {
|
|
316
317
|
return;
|
|
317
318
|
}
|
|
318
|
-
return (0, lowcode_1.writeCode2file)(compositeCtx, mod, path.join(componentDir, LOWCODE_DIR_NAME), { comp: compositedComp }, themeCode);
|
|
319
|
+
return (0, lowcode_1.writeCode2file)(compositeCtx, mod, path.join(componentDir, LOWCODE_DIR_NAME), { comp: compositedComp }, themeCode, mode === 'lib' ? true : false);
|
|
319
320
|
});
|
|
320
321
|
// await writeLowCodeFiles(weapp, appRoot)
|
|
321
322
|
// await generateFramework(weapp, appRoot)
|
|
@@ -341,6 +342,9 @@ function getWxmlTag(ctx, cmp, nameMangler) {
|
|
|
341
342
|
return { tagName };
|
|
342
343
|
}
|
|
343
344
|
if (materialLib) {
|
|
345
|
+
const libRootInMiniprogram = path.posix.join('/', ctx.wedaRoot || '', (materialLib === null || materialLib === void 0 ? void 0 : materialLib.rootPath)
|
|
346
|
+
? materialLib === null || materialLib === void 0 ? void 0 : materialLib.rootPath
|
|
347
|
+
: path.posix.join(`${config_1.materialsDirName}/${cmp.moduleName}`));
|
|
344
348
|
let cmpMeta = (findComponent === null || findComponent === void 0 ? void 0 : findComponent.meta) || { platforms: undefined };
|
|
345
349
|
if (!cmpMeta.platforms) {
|
|
346
350
|
return { tagName };
|
|
@@ -353,7 +357,7 @@ function getWxmlTag(ctx, cmp, nameMangler) {
|
|
|
353
357
|
compPath =
|
|
354
358
|
compPath.startsWith('/') || compPath.indexOf('://') > 0
|
|
355
359
|
? compPath
|
|
356
|
-
: path.posix.join(
|
|
360
|
+
: path.posix.join(libRootInMiniprogram, compPath);
|
|
357
361
|
tagName = `${/^\$/.test(moduleName) ? NAME_MANAGER.mangle(moduleName) : moduleName}-${name}`;
|
|
358
362
|
if (nameMangler) {
|
|
359
363
|
tagName = nameMangler.mangle(tagName);
|
package/lib/builder/mp/util.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { IDynamicValue, IWeAppComponentInstance, ActionType, ICompositedComponent, IWeAppPage, IEventListener, IQueryData } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
|
-
import {
|
|
2
|
+
import { IMpCommonBuildContext } from './BuildContext';
|
|
3
3
|
export declare function generatedDynamicData(data: {
|
|
4
4
|
[key: string]: IDynamicValue;
|
|
5
5
|
}, compInfo?: ICompositedComponent, filterBuiltInProps?: boolean): {
|
|
6
6
|
staticProps: {};
|
|
7
7
|
boundProps: {};
|
|
8
8
|
};
|
|
9
|
-
export declare function createWidgetProps(ctx:
|
|
9
|
+
export declare function createWidgetProps(ctx: IMpCommonBuildContext, widgets: {
|
|
10
10
|
[key: string]: IWeAppComponentInstance;
|
|
11
11
|
}): {};
|
|
12
|
-
export declare function createEventHandlers(ctx:
|
|
12
|
+
export declare function createEventHandlers(ctx: IMpCommonBuildContext, widgets: {
|
|
13
13
|
[key: string]: IWeAppComponentInstance;
|
|
14
14
|
}, componentApi: string, page?: IWeAppPage): {};
|
|
15
15
|
export declare function generateSyncListeners(syncConfigs: any): IEventListener[];
|
|
@@ -19,10 +19,10 @@ export declare function generateDataContainerListeners(): {
|
|
|
19
19
|
type: ActionType;
|
|
20
20
|
data: {};
|
|
21
21
|
}[];
|
|
22
|
-
export declare function createTemplateQuery(ctx:
|
|
22
|
+
export declare function createTemplateQuery(ctx: IMpCommonBuildContext, query?: {
|
|
23
23
|
[key: string]: IQueryData;
|
|
24
24
|
}): {};
|
|
25
|
-
export declare function createTemplateEventFlows(ctx:
|
|
25
|
+
export declare function createTemplateEventFlows(ctx: IMpCommonBuildContext, eventFlows?: any[]): any[];
|
|
26
26
|
export declare function generateArgsDynamicValueFromData(args?: {
|
|
27
27
|
[prop: string]: IDynamicValue;
|
|
28
28
|
}, data?: {
|
|
@@ -30,11 +30,11 @@ export declare function generateArgsDynamicValueFromData(args?: {
|
|
|
30
30
|
}): {
|
|
31
31
|
[prop: string]: IDynamicValue;
|
|
32
32
|
} | undefined;
|
|
33
|
-
export declare function createDataBinds(ctx:
|
|
33
|
+
export declare function createDataBinds(ctx: IMpCommonBuildContext, widgets: {
|
|
34
34
|
[key: string]: IWeAppComponentInstance;
|
|
35
35
|
}): {};
|
|
36
36
|
export declare function setDataBind(target: any, prop: string, val: IDynamicValue): void;
|
|
37
|
-
export declare function processRepeaterSchema(ctx:
|
|
37
|
+
export declare function processRepeaterSchema(ctx: Pick<IMpCommonBuildContext, 'materialLibs' | 'miniprogramPlugins'>, componentInstanceMap: {
|
|
38
38
|
[key: string]: IWeAppComponentInstance;
|
|
39
39
|
}): {
|
|
40
40
|
[key: string]: IWeAppComponentInstance;
|
|
@@ -45,8 +45,11 @@ export declare function processRepeaterSchema(ctx: any, componentInstanceMap: {
|
|
|
45
45
|
export declare function findComponentInfo(xComponent: {
|
|
46
46
|
moduleName: string;
|
|
47
47
|
name: string;
|
|
48
|
-
}, { materialLibs, miniprogramPlugins }:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
}, { materialLibs, miniprogramPlugins }: Pick<IMpCommonBuildContext, 'materialLibs' | 'miniprogramPlugins'>): ICompositedComponent | undefined;
|
|
49
|
+
export declare function generateScopedStyleText(widgets: Record<string, IWeAppComponentInstance>, weightPrefix?: string): string;
|
|
50
|
+
export declare function isRepeaterWidget(w: {
|
|
51
|
+
widgetType: string;
|
|
52
|
+
getConfig: () => {
|
|
53
|
+
componentType?: string;
|
|
54
|
+
};
|
|
55
|
+
}, repeaterComponentName: string): true | undefined;
|