@cloudbase/lowcode-builder 1.0.13 → 1.0.16
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/config/index.d.ts +1 -1
- package/lib/builder/config/index.js +1 -1
- package/lib/builder/mp/index.js +23 -24
- package/lib/builder/mp/lowcode.js +7 -10
- package/lib/builder/mp/materials.js +23 -25
- package/lib/builder/mp/wxml.js +5 -4
- package/lib/builder/util/common.d.ts +8 -1
- package/lib/builder/util/common.js +44 -19
- package/lib/builder.web.js +13 -21
- package/package.json +5 -5
- package/template/html/index.html.ejs +1 -1
- package/template/mp/app/weapps-api.js +14 -14
- package/template/mp/common/util.js +44 -2
- package/template/mp/common/weapp-component.js +2 -2
- package/template/mp/common/weapp-page.js +11 -9
- package/template/mp/page/api.js +1 -1
- package/template/mp/page/index.js +0 -1
- package/dist/builder.web.js +0 -79
|
@@ -11,7 +11,7 @@ export declare const builderTemplateURL = "https://comp-public-1303824488.cos.ap
|
|
|
11
11
|
* miniprogram的代码,IDE插件后续会提供端功能
|
|
12
12
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
13
13
|
*/
|
|
14
|
-
export declare const miniprogramURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/
|
|
14
|
+
export declare const miniprogramURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/miniprogram_npm_20220722.zip";
|
|
15
15
|
/**
|
|
16
16
|
* miniprogram_npm存放目录。IDE插件builder用到
|
|
17
17
|
*/
|
|
@@ -48,7 +48,7 @@ exports.builderTemplateURL = 'https://comp-public-1303824488.cos.ap-shanghai.myq
|
|
|
48
48
|
* miniprogram的代码,IDE插件后续会提供端功能
|
|
49
49
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
50
50
|
*/
|
|
51
|
-
exports.miniprogramURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/
|
|
51
|
+
exports.miniprogramURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/miniprogram_npm_20220722.zip';
|
|
52
52
|
/**
|
|
53
53
|
* miniprogram_npm存放目录。IDE插件builder用到
|
|
54
54
|
*/
|
package/lib/builder/mp/index.js
CHANGED
|
@@ -44,13 +44,14 @@ const mp_config_1 = require("./mp_config");
|
|
|
44
44
|
const plugin_1 = require("./plugin");
|
|
45
45
|
const plugin_2 = require("../core/plugin");
|
|
46
46
|
const util_3 = require("../util");
|
|
47
|
-
const style_1 = require("@cloudbase/lowcode-generator/lib/generator/util/style");
|
|
48
47
|
const lowcode_generator_1 = require("@cloudbase/lowcode-generator");
|
|
49
48
|
const types_1 = require("../../types");
|
|
50
49
|
const common_1 = require("../types/common");
|
|
51
50
|
const lodash_1 = require("lodash");
|
|
52
51
|
const junk = __importStar(require("../util/junk"));
|
|
53
52
|
const net_1 = require("../util/net");
|
|
53
|
+
const cals_1 = require("@cloudbase/cals");
|
|
54
|
+
const common_2 = require("@cloudbase/lowcode-generator/lib/generator/util/common");
|
|
54
55
|
const templateDir = `${config_1.appTemplateDir}/mp/`;
|
|
55
56
|
const em = chalk_1.default.blue.bold;
|
|
56
57
|
const error = chalk_1.default.redBright;
|
|
@@ -73,7 +74,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
73
74
|
isBrowserMpBuilder,
|
|
74
75
|
};
|
|
75
76
|
const yyptConfig = await (0, util_3.getYyptConfigInfo)(extraData);
|
|
76
|
-
const {
|
|
77
|
+
const { allAppUsedComps } = handleUsedComponents({
|
|
77
78
|
buildContext,
|
|
78
79
|
weapps,
|
|
79
80
|
materials,
|
|
@@ -150,16 +151,19 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
150
151
|
await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
|
|
151
152
|
}
|
|
152
153
|
else {
|
|
154
|
+
const importor = (0, util_3.generateLowcodeImportor)(mainAppData.lowCodes || []);
|
|
153
155
|
appFileData = {
|
|
154
156
|
...appFileData,
|
|
155
157
|
'common/wx_yypt_report_v2.js': {},
|
|
156
|
-
'app.js': {
|
|
158
|
+
'app.js': { appConfig, importor },
|
|
157
159
|
'app.json': { content: appConfig },
|
|
158
160
|
'app.wxss': {
|
|
159
|
-
importStyles: materials
|
|
161
|
+
importStyles: materials
|
|
162
|
+
.reduce((styles, lib) => {
|
|
160
163
|
styles = styles.concat((lib.styles || []).map((stylePath) => stylePath && !stylePath.startsWith('/') ? `/${config_1.materialsDirName}/${lib.name}/${stylePath}` : stylePath) || []);
|
|
161
164
|
return styles;
|
|
162
|
-
}, [])
|
|
165
|
+
}, [])
|
|
166
|
+
.concat(importor.styles.map((mod) => path_1.default.join('lowcode', (0, weapps_core_1.getCodeModuleFilePath)('global', mod, { style: '.wxss' })))),
|
|
163
167
|
},
|
|
164
168
|
'package.json': {
|
|
165
169
|
appId,
|
|
@@ -303,6 +307,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
|
|
|
303
307
|
const usingComponents = {};
|
|
304
308
|
const componentGenerics = {};
|
|
305
309
|
const wxml = (0, wxml_1.generateWxml)(page.componentInstances, `Page ${rootPath ? path_1.default.join(rootPath, 'pages') : ''}/${page.id}`, wxmlDataPrefix, { ...ctx, rootPath, isPage: true }, usingComponents, componentGenerics);
|
|
310
|
+
const importor = (0, util_3.generateLowcodeImportor)(page.lowCodes);
|
|
306
311
|
const pageFileName = (0, lodash_1.get)(pageConfigs, `${page.id}.pageFileName`, 'index');
|
|
307
312
|
const pageFileData = {
|
|
308
313
|
[`api.js|api.js`]: {},
|
|
@@ -319,6 +324,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
|
|
|
319
324
|
debug: ctx.debugMode,
|
|
320
325
|
stringifyObj: util_1.inspect,
|
|
321
326
|
subLevelPath: rootPath ? `${path_1.default.relative(rootPath, '')}/` : '',
|
|
327
|
+
importor,
|
|
322
328
|
},
|
|
323
329
|
[`index.json|${pageFileName}.json`]: {
|
|
324
330
|
usingComponents,
|
|
@@ -337,7 +343,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
|
|
|
337
343
|
toRem: false,
|
|
338
344
|
toRpx: true,
|
|
339
345
|
}), 'page'),
|
|
340
|
-
pageWxss: `@import "../../lowcode/${page.id}/style.wxss"
|
|
346
|
+
pageWxss: importor.styles.length ? `@import "../../lowcode/${page.id}/style.wxss"` : '',
|
|
341
347
|
},
|
|
342
348
|
};
|
|
343
349
|
// Generating file by template and data
|
|
@@ -358,7 +364,7 @@ async function generateFramework(appData, outDir, ctx) {
|
|
|
358
364
|
appId: ctx.appId,
|
|
359
365
|
subLevelPath: '',
|
|
360
366
|
subPackageName: '',
|
|
361
|
-
|
|
367
|
+
importor: (0, util_3.generateLowcodeImportor)([]),
|
|
362
368
|
domain: ctx.domain || '',
|
|
363
369
|
appConfig: JSON.stringify({}),
|
|
364
370
|
},
|
|
@@ -379,6 +385,7 @@ async function generateFramework(appData, outDir, ctx) {
|
|
|
379
385
|
// 子包混合模式 只在子包中生成 handlers
|
|
380
386
|
const isMixSubpackage = ctx.isMixMode && appData.rootPath;
|
|
381
387
|
if (!isMixSubpackage) {
|
|
388
|
+
const importor = (0, util_3.generateLowcodeImportor)(appData.lowCodes);
|
|
382
389
|
fileData = {
|
|
383
390
|
...fileData,
|
|
384
391
|
'app/app-global.js': {},
|
|
@@ -387,7 +394,7 @@ async function generateFramework(appData, outDir, ctx) {
|
|
|
387
394
|
domain: ctx.domain || '',
|
|
388
395
|
subLevelPath: appData.rootPath ? `${path_1.default.relative(`${appData.rootPath}`, '')}/` : '',
|
|
389
396
|
subPackageName: appData.rootPath || '',
|
|
390
|
-
|
|
397
|
+
importor,
|
|
391
398
|
appConfig: (0, util_3.JsonToStringWithVariableName)({
|
|
392
399
|
id: ctx.appId,
|
|
393
400
|
envId: appData.envId,
|
|
@@ -416,31 +423,23 @@ async function generateFramework(appData, outDir, ctx) {
|
|
|
416
423
|
async function writeLowCodeFiles(appData, outDir, ctx) {
|
|
417
424
|
console.log(`Writing ${em('lowcode')} files:`);
|
|
418
425
|
const lowcodeRootDir = path_1.default.join(outDir, 'lowcode');
|
|
419
|
-
const
|
|
426
|
+
const lowCodes = (0, common_2.generateDefaultLowcodeIndex)(appData, 'global');
|
|
427
|
+
const themeStyle = lowCodes.find((mod) => mod.type === cals_1.ECodeType.THEME);
|
|
420
428
|
// 混合模式,子包不生成顶级(应用级)的 lowcodes
|
|
421
429
|
if (!(ctx.isMixMode && appData.rootPath)) {
|
|
422
|
-
await Promise.all(
|
|
423
|
-
.filter((mod) => mod.name !== '____index____')
|
|
430
|
+
await Promise.all(lowCodes
|
|
424
431
|
.filter((mod) => mod.type !== 'renderer')
|
|
425
432
|
.map((m) => {
|
|
426
433
|
(0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { appDir: outDir }, themeStyle.code);
|
|
427
434
|
}));
|
|
428
435
|
}
|
|
429
436
|
await Promise.all((0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList, async (page) => {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
// @ts-ignore
|
|
435
|
-
codes.push({
|
|
436
|
-
code: 'export default {}',
|
|
437
|
-
name: 'index',
|
|
438
|
-
path: 'xx/index',
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
await ((_a = page === null || page === void 0 ? void 0 : page.lowCodes) === null || _a === void 0 ? void 0 : _a.filter((mod) => mod.name !== '____index____').filter((mod) => mod.type !== 'renderer').forEach((m) => {
|
|
437
|
+
const codes = (0, common_2.generateDefaultLowcodeIndex)(page, page.id);
|
|
438
|
+
await codes
|
|
439
|
+
.filter((mod) => mod.type !== 'renderer')
|
|
440
|
+
.forEach((m) => {
|
|
442
441
|
(0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { pageId: page.id, appDir: outDir }, themeStyle.code, ctx);
|
|
443
|
-
})
|
|
442
|
+
});
|
|
444
443
|
}));
|
|
445
444
|
}
|
|
446
445
|
exports.writeLowCodeFiles = writeLowCodeFiles;
|
|
@@ -8,32 +8,29 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
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
|
+
const cals_1 = require("@cloudbase/cals");
|
|
11
12
|
async function writeCode2file(mod, lowcodeRootDir, opts = {}, themeCode, ctx) {
|
|
12
13
|
const { pageId = 'global', appDir, comp } = opts;
|
|
13
14
|
const file = path_1.default.join(lowcodeRootDir, (0, weapps_core_1.getCodeModuleFilePath)(pageId || 'global', mod, { style: '.wxss' }));
|
|
14
|
-
let code = mod
|
|
15
|
-
if (mod.type !==
|
|
15
|
+
let { code } = mod;
|
|
16
|
+
if (mod.type !== cals_1.ECodeType.STYLE && mod.type !== cals_1.ECodeType.THEME) {
|
|
16
17
|
if (appDir) {
|
|
17
18
|
// Generate app lowcode
|
|
18
|
-
const baseDir = path_1.default
|
|
19
|
-
.relative(path_1.default.dirname(file), appDir)
|
|
20
|
-
.replace(/\\/g, '/');
|
|
19
|
+
const baseDir = path_1.default.relative(path_1.default.dirname(file), appDir).replace(/\\/g, '/');
|
|
21
20
|
// 子包混合模式需要添加相对索引到根目录
|
|
22
|
-
const relativeRoot = (ctx === null || ctx === void 0 ? void 0 : ctx.isMixMode) && ctx.rootPath
|
|
23
|
-
? path_1.default.relative(ctx.rootPath, '') + '/'
|
|
24
|
-
: '';
|
|
21
|
+
const relativeRoot = (ctx === null || ctx === void 0 ? void 0 : ctx.isMixMode) && ctx.rootPath ? `${path_1.default.relative(ctx.rootPath, '')}/` : '';
|
|
25
22
|
let weappsApiPrefix = [
|
|
26
23
|
`import { app, process } from '${relativeRoot}${baseDir}/app/weapps-api';`,
|
|
27
24
|
'const $app = app;',
|
|
28
25
|
]; // windows compatibility
|
|
29
26
|
if (pageId !== 'global') {
|
|
30
|
-
weappsApiPrefix.push(`import { $page } from '${
|
|
27
|
+
weappsApiPrefix.push(`import { $page } from '${baseDir}/pages/${pageId}/api'`);
|
|
31
28
|
}
|
|
32
29
|
code = `${weappsApiPrefix.join('\n')}\n${code}`;
|
|
33
30
|
}
|
|
34
31
|
else {
|
|
35
32
|
// Generate component lowcode
|
|
36
|
-
code = `import process from '${mod.type === 'handler-fn' ? '../' : ''}../../../../common/process'\nimport app from '${mod.type === 'handler-fn' ? '../' : ''}../../../../common/weapp-sdk'
|
|
33
|
+
code = `import process from '${mod.type === 'handler-fn' ? '../' : ''}../../../../common/process'\nimport app from '${mod.type === 'handler-fn' ? '../' : ''}../../../../common/weapp-sdk';\nconst $app = app;\n${code.replace(/\$comp/g, weapps_core_1.COMPONENT_API_PREFIX)}`;
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
36
|
else {
|
|
@@ -36,14 +36,11 @@ const wxml_1 = require("./wxml");
|
|
|
36
36
|
const generateFiles_1 = __importStar(require("../util/generateFiles"));
|
|
37
37
|
const lowcode_1 = require("./lowcode");
|
|
38
38
|
const net_1 = require("../util/net");
|
|
39
|
-
const util_4 = require("../util");
|
|
40
39
|
const junk = __importStar(require("../util/junk"));
|
|
41
|
-
const templateDir = config_1.appTemplateDir
|
|
40
|
+
const templateDir = `${config_1.appTemplateDir}/mp/`;
|
|
42
41
|
async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
43
42
|
let { materialLibs, isBrowserMpBuilder } = ctx;
|
|
44
|
-
const weappsList = ctx.isMixMode
|
|
45
|
-
? weapps
|
|
46
|
-
: weapps.filter((item) => !item.rootPath);
|
|
43
|
+
const weappsList = ctx.isMixMode ? weapps : weapps.filter((item) => !item.rootPath);
|
|
47
44
|
// #1 Download uploaded libs
|
|
48
45
|
const localPkg = (0, util_2.getCurrentPackageJson)();
|
|
49
46
|
await Promise.all(materialLibs
|
|
@@ -62,7 +59,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
62
59
|
await downloadMaterial(mpPkgUrl, materialsSrcDir, ctx.isBrowserMpBuilder);
|
|
63
60
|
}
|
|
64
61
|
function libUpdated(libDir, version) {
|
|
65
|
-
const meta = (0,
|
|
62
|
+
const meta = (0, util_2.readComponentLibMata)(libDir);
|
|
66
63
|
if (!meta) {
|
|
67
64
|
return true;
|
|
68
65
|
}
|
|
@@ -98,7 +95,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
98
95
|
// #3 copy 组件库代码文件到项目目录
|
|
99
96
|
!isBrowserMpBuilder
|
|
100
97
|
? await fs.copy(materialsSrcDirPath, targetDir, {
|
|
101
|
-
filter
|
|
98
|
+
filter(src, dest) {
|
|
102
99
|
const path = src.split('/');
|
|
103
100
|
return !junk.is(path[path.length - 1]);
|
|
104
101
|
},
|
|
@@ -112,7 +109,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
112
109
|
// #2 link material to current project
|
|
113
110
|
!isBrowserMpBuilder
|
|
114
111
|
? await fs.copy(materialsSrcDir, targetDir, {
|
|
115
|
-
filter
|
|
112
|
+
filter(src, dest) {
|
|
116
113
|
const path = src.split('/');
|
|
117
114
|
return !junk.is(path[path.length - 1]);
|
|
118
115
|
},
|
|
@@ -122,7 +119,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
122
119
|
});
|
|
123
120
|
}
|
|
124
121
|
}
|
|
125
|
-
const libMeta = (0,
|
|
122
|
+
const libMeta = (0, util_2.readComponentLibMata)(targetDir);
|
|
126
123
|
if (!lib.components) {
|
|
127
124
|
lib.components = Object.keys((libMeta === null || libMeta === void 0 ? void 0 : libMeta.components) || {}).map((name) => {
|
|
128
125
|
var _a;
|
|
@@ -163,7 +160,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
163
160
|
}
|
|
164
161
|
cmp.meta.platforms = {
|
|
165
162
|
mp: {
|
|
166
|
-
path: cmp.name
|
|
163
|
+
path: `${cmp.name}/index`,
|
|
167
164
|
},
|
|
168
165
|
};
|
|
169
166
|
lib.dependencies = { ...lib.dependencies, ...cmp.npmDependencies };
|
|
@@ -171,8 +168,8 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
171
168
|
});
|
|
172
169
|
// #2 Generate composited libs
|
|
173
170
|
await Promise.all(compositedLibs.map(async (lib) => {
|
|
174
|
-
console.log(
|
|
175
|
-
await (0,
|
|
171
|
+
console.log(`Generate composited library ${lib.name}`);
|
|
172
|
+
await (0, util_2.writeLibCommonRes2file)(lib, path.join(ctx.projDir, config_1.materialsDirName, lib.name, 'libCommonRes'));
|
|
176
173
|
await Promise.all(lib.components.map(async (cmp) => {
|
|
177
174
|
return generateCompositeComponent(cmp, {
|
|
178
175
|
...ctx,
|
|
@@ -206,7 +203,7 @@ function extractUsedCompsRecursively(comps, checkedComps, compositedLibs, output
|
|
|
206
203
|
cmpNames.forEach((cmpName) => {
|
|
207
204
|
const cmp = lib.components.find((c) => c.name === cmpName);
|
|
208
205
|
if (!cmp) {
|
|
209
|
-
console.warn('Component not found', libName
|
|
206
|
+
console.warn('Component not found', `${libName}:${cmpName}`);
|
|
210
207
|
return;
|
|
211
208
|
}
|
|
212
209
|
if (checkedComps.indexOf(cmp) > -1)
|
|
@@ -237,23 +234,20 @@ async function generateCompositeComponent(compositedComp, ctx, compLibCommonReso
|
|
|
237
234
|
const { materialName } = compositedComp;
|
|
238
235
|
const outDir = path.join(ctx.projDir, ctx.rootPath || '', // 混合模式下,可能会有 rootPath
|
|
239
236
|
config_1.materialsDirName, materialName, compositedComp.name);
|
|
237
|
+
const LOWCODE_DIR_NAME = 'lowcode';
|
|
240
238
|
console.log(`Generating composited component ${materialName}:${compositedComp.name} to ${outDir}`);
|
|
241
239
|
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!ctx.isProduction);
|
|
242
240
|
// # Generating page
|
|
243
241
|
const usingComponents = {};
|
|
244
242
|
const componentGenerics = {};
|
|
245
243
|
const cmpContainer = Object.values(compositedComp.componentInstances)[0];
|
|
246
|
-
const wxml = (0, wxml_1.generateWxml)(compositedComp.componentInstances,
|
|
244
|
+
const wxml = (0, wxml_1.generateWxml)(compositedComp.componentInstances, `Component ${materialName}:${compositedComp.name}`, wxmlDataPrefix, { ...ctx, isPage: false }, usingComponents, componentGenerics, (cmp, node) => {
|
|
247
245
|
if (cmp === cmpContainer) {
|
|
248
246
|
// Set className & style passed from parent for root component
|
|
249
247
|
const { attributes } = node;
|
|
250
248
|
const classAttrName = (0, mp_1.getClassAttrName)(node.name);
|
|
251
249
|
const oldClass = attributes[classAttrName];
|
|
252
|
-
attributes[classAttrName] =
|
|
253
|
-
(0, weapps_core_1.getCompositedComponentClass)(compositedComp) +
|
|
254
|
-
' ' +
|
|
255
|
-
oldClass +
|
|
256
|
-
' {{className}}';
|
|
250
|
+
attributes[classAttrName] = `${(0, weapps_core_1.getCompositedComponentClass)(compositedComp)} ${oldClass} {{className}}`;
|
|
257
251
|
attributes.style += ';{{style}}';
|
|
258
252
|
}
|
|
259
253
|
});
|
|
@@ -275,9 +269,10 @@ async function generateCompositeComponent(compositedComp, ctx, compLibCommonReso
|
|
|
275
269
|
delete propDefs[p];
|
|
276
270
|
}
|
|
277
271
|
});
|
|
272
|
+
const importor = (0, util_2.generateLowcodeImportor)(compositedComp.lowCodes);
|
|
278
273
|
const pageFileData = {
|
|
279
274
|
'index.js': {
|
|
280
|
-
materialName
|
|
275
|
+
materialName,
|
|
281
276
|
propDefs,
|
|
282
277
|
handlers: compositedComp.lowCodes
|
|
283
278
|
.filter((m) => m.type === 'handler-fn' && m.name !== '____index____')
|
|
@@ -288,13 +283,14 @@ async function generateCompositeComponent(compositedComp, ctx, compLibCommonReso
|
|
|
288
283
|
widgetProps: (0, util_3.createWidgetProps)(compositedComp.componentInstances, ctx),
|
|
289
284
|
compApi: weapps_core_1.COMPONENT_API_PREFIX,
|
|
290
285
|
jsonSchemaType2jsClass: mp_1.jsonSchemaType2jsClass,
|
|
291
|
-
key: compositedComp.materialName
|
|
286
|
+
key: `${compositedComp.materialName}:${compositedComp.name}`,
|
|
292
287
|
dataBinds: (0, util_3.createDataBinds)(compositedComp.componentInstances, ctx),
|
|
293
288
|
debug: !ctx.isProduction,
|
|
294
289
|
stringifyObj: util_1.inspect,
|
|
295
290
|
// dataPropNames: wxmlDataPrefix,
|
|
296
291
|
formEvents: Object.keys(formEvents).length > 0 ? formEvents : null,
|
|
297
292
|
config: compositedComp.compConfig,
|
|
293
|
+
importor,
|
|
298
294
|
},
|
|
299
295
|
'index.json': { usingComponents, componentGenerics },
|
|
300
296
|
'index.wxml': {
|
|
@@ -302,10 +298,12 @@ async function generateCompositeComponent(compositedComp, ctx, compLibCommonReso
|
|
|
302
298
|
// wrapperClass: getCompositedComponentClass(compositedComp),
|
|
303
299
|
content: wxml,
|
|
304
300
|
},
|
|
305
|
-
'index.wxss': {
|
|
301
|
+
'index.wxss': {
|
|
302
|
+
importStyles: importor.styles.map((mod) => path.join(LOWCODE_DIR_NAME, (0, weapps_core_1.getCodeModuleFilePath)('global', mod, { style: '.wxss' }))),
|
|
303
|
+
},
|
|
306
304
|
};
|
|
307
305
|
// Generating file by template and data
|
|
308
|
-
await (0, generateFiles_1.default)(pageFileData, templateDir
|
|
306
|
+
await (0, generateFiles_1.default)(pageFileData, `${templateDir}/component`, outDir, ctx);
|
|
309
307
|
// #3 writing lowcode files
|
|
310
308
|
const codes = [...compositedComp.lowCodes];
|
|
311
309
|
if (!codes.find((m) => m.name === 'index')) {
|
|
@@ -327,7 +325,7 @@ async function generateCompositeComponent(compositedComp, ctx, compLibCommonReso
|
|
|
327
325
|
${compLibCommonResource.theme.class || ''}
|
|
328
326
|
`;
|
|
329
327
|
}
|
|
330
|
-
return (0, lowcode_1.writeCode2file)(mod, path.join(outDir,
|
|
328
|
+
return (0, lowcode_1.writeCode2file)(mod, path.join(outDir, LOWCODE_DIR_NAME), { comp: compositedComp }, themeCode, ctx);
|
|
331
329
|
});
|
|
332
330
|
// await writeLowCodeFiles(weapp, appRoot)
|
|
333
331
|
// await generateFramework(weapp, appRoot)
|
|
@@ -368,7 +366,7 @@ function getWxmlTag(cmp, ctx, nameMangler) {
|
|
|
368
366
|
compPath.startsWith('/') || compPath.indexOf('://') > 0
|
|
369
367
|
? compPath
|
|
370
368
|
: path.posix.join(
|
|
371
|
-
/*ctx.isMixMode ? '/' + rootPath : */ '', `/${config_1.materialsDirName}/${cmp.moduleName}`, compPath);
|
|
369
|
+
/* ctx.isMixMode ? '/' + rootPath : */ '', `/${config_1.materialsDirName}/${cmp.moduleName}`, compPath);
|
|
372
370
|
tagName = `${moduleName}-${name}`;
|
|
373
371
|
if (nameMangler) {
|
|
374
372
|
tagName = nameMangler.mangle(tagName);
|
package/lib/builder/mp/wxml.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getUsedComponents = exports.getMpEventHanlderName = exports.generateWxml = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
|
|
8
9
|
const xml_js_1 = require("xml-js");
|
|
9
10
|
const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
|
|
10
11
|
const materials_1 = require("./materials");
|
|
@@ -54,7 +55,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
54
55
|
function createXml(widgets, parent = null, parentForNodes = []) {
|
|
55
56
|
var _a, _b, _c, _d, _e, _f;
|
|
56
57
|
const elements = [];
|
|
57
|
-
for (const id
|
|
58
|
+
for (const id in widgets) {
|
|
58
59
|
const { xComponent, xProps, properties, xIndex, genericComp } = widgets[id];
|
|
59
60
|
const { data: data0 = {}, listeners = [], directives = {}, staticResourceAttribute = ['src'] } = xProps || {};
|
|
60
61
|
const data = { ...data0 };
|
|
@@ -130,8 +131,8 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
130
131
|
name: tagName,
|
|
131
132
|
attributes: {
|
|
132
133
|
id: idAttr,
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
'bind:attached': '__mnt__',
|
|
135
|
+
'bind:detached': '__unmnt__',
|
|
135
136
|
style: `{{${attrPrefix}.style}}`,
|
|
136
137
|
[(0, mp_1.getClassAttrName)(tagName)]: `{{${attrPrefix}.className}}`,
|
|
137
138
|
},
|
|
@@ -352,7 +353,7 @@ function getUsedComponents(widgets, usedCmps = {}) {
|
|
|
352
353
|
exports.getUsedComponents = getUsedComponents;
|
|
353
354
|
function getAttrBind(dVale, widgetBind, isStaticResource) {
|
|
354
355
|
const { type, value } = dVale;
|
|
355
|
-
const attrVal = widgetBind;
|
|
356
|
+
const attrVal = type === weapps_core_1.PropBindType.prop ? value : widgetBind;
|
|
356
357
|
return isStaticResource ? `{{wxsUtils._getStaticResourceAttribute(${attrVal})}}` : `{{${attrVal}}}`;
|
|
357
358
|
}
|
|
358
359
|
function getGenericCompTagName(propName) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IComponentInputProps, IComponentsInfoMap, IPackageJson } from '../types/common';
|
|
2
|
-
import { ICompositedComponent, IMaterialItem, IPageInstance, IWeAppComponentInstance } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
|
+
import { ICompositedComponent, IMaterialItem, IPageInstance, IWeAppComponentInstance, IWeAppCode } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
3
3
|
export { getMetaInfoBySourceKey, isArray, isPlainObject, deepDeal, simpleDeepClone, deepDealSchema, getFileNameByUrl, } from '@cloudbase/lowcode-generator/lib/generator/util/common';
|
|
4
4
|
export declare type PromiseResult<T> = Promise<[null, T] | [Error, null]>;
|
|
5
5
|
export declare function promiseWrapper<T>(p: Promise<T>): PromiseResult<T>;
|
|
@@ -50,3 +50,10 @@ interface ICompileDirs {
|
|
|
50
50
|
materialsDir: string;
|
|
51
51
|
}
|
|
52
52
|
export declare function getCompileDirs(appKey?: string): ICompileDirs;
|
|
53
|
+
export declare function generateLowcodeImportor(lowcodes?: IWeAppCode[]): {
|
|
54
|
+
state: boolean;
|
|
55
|
+
computed: boolean;
|
|
56
|
+
lifecycle: boolean;
|
|
57
|
+
common: boolean;
|
|
58
|
+
styles: IWeAppCode[];
|
|
59
|
+
};
|
|
@@ -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.getCompileDirs = exports.deepDealComponentSchemaJson = exports.canUseVite = exports.gererateIndexAPI = 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.generateLowcodeImportor = exports.getCompileDirs = exports.deepDealComponentSchemaJson = exports.canUseVite = exports.gererateIndexAPI = 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;
|
|
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"));
|
|
@@ -11,6 +11,7 @@ const style_1 = require("@cloudbase/lowcode-generator/lib/generator/util/style")
|
|
|
11
11
|
const generateFiles_1 = require("./generateFiles");
|
|
12
12
|
const cals_1 = require("@cloudbase/cals");
|
|
13
13
|
const compare_versions_1 = __importDefault(require("compare-versions"));
|
|
14
|
+
const os_1 = __importDefault(require("os"));
|
|
14
15
|
var common_1 = require("@cloudbase/lowcode-generator/lib/generator/util/common");
|
|
15
16
|
Object.defineProperty(exports, "getMetaInfoBySourceKey", { enumerable: true, get: function () { return common_1.getMetaInfoBySourceKey; } });
|
|
16
17
|
Object.defineProperty(exports, "isArray", { enumerable: true, get: function () { return common_1.isArray; } });
|
|
@@ -19,7 +20,6 @@ Object.defineProperty(exports, "deepDeal", { enumerable: true, get: function ()
|
|
|
19
20
|
Object.defineProperty(exports, "simpleDeepClone", { enumerable: true, get: function () { return common_1.simpleDeepClone; } });
|
|
20
21
|
Object.defineProperty(exports, "deepDealSchema", { enumerable: true, get: function () { return common_1.deepDealSchema; } });
|
|
21
22
|
Object.defineProperty(exports, "getFileNameByUrl", { enumerable: true, get: function () { return common_1.getFileNameByUrl; } });
|
|
22
|
-
const os_1 = __importDefault(require("os"));
|
|
23
23
|
const homeDir = os_1.default.homedir();
|
|
24
24
|
const commandConfigPath = path_1.default.join(homeDir, '.warc');
|
|
25
25
|
function promiseWrapper(p) {
|
|
@@ -56,12 +56,8 @@ function getSelfPackageJson() {
|
|
|
56
56
|
}
|
|
57
57
|
exports.getSelfPackageJson = getSelfPackageJson;
|
|
58
58
|
function JsonToStringWithVariableName(copyJson, options = {}) {
|
|
59
|
-
let variable = JSON.stringify(copyJson, null, 2).replace(/"%%%(.*?)%%%"/g,
|
|
60
|
-
return expression
|
|
61
|
-
.replace(/\\"/g, '"')
|
|
62
|
-
.replace(/\\'/g, "'")
|
|
63
|
-
.replace(/\\r/g, '\r')
|
|
64
|
-
.replace(/\\n/g, '\n');
|
|
59
|
+
let variable = JSON.stringify(copyJson, null, 2).replace(/"%%%(.*?)%%%"/g, (match, expression) => {
|
|
60
|
+
return expression.replace(/\\"/g, '"').replace(/\\'/g, "'").replace(/\\r/g, '\r').replace(/\\n/g, '\n');
|
|
65
61
|
});
|
|
66
62
|
return variable;
|
|
67
63
|
}
|
|
@@ -88,8 +84,7 @@ function getInputProps(componentsMetaMap) {
|
|
|
88
84
|
let compItem = component;
|
|
89
85
|
Object.keys(compItem.dataForm || {}).forEach((key) => {
|
|
90
86
|
var _a, _b;
|
|
91
|
-
const inputProps = ((_a = compItem.dataForm[key]) === null || _a === void 0 ? void 0 : _a.inputProp) ||
|
|
92
|
-
((_b = compItem.dataForm[key]) === null || _b === void 0 ? void 0 : _b.syncProps);
|
|
87
|
+
const inputProps = ((_a = compItem.dataForm[key]) === null || _a === void 0 ? void 0 : _a.inputProp) || ((_b = compItem.dataForm[key]) === null || _b === void 0 ? void 0 : _b.syncProps);
|
|
93
88
|
if (inputProps) {
|
|
94
89
|
outputObj[sourceKey] = {
|
|
95
90
|
[key]: inputProps,
|
|
@@ -177,7 +172,7 @@ async function getYyptConfigInfo(extraData) {
|
|
|
177
172
|
}
|
|
178
173
|
exports.getYyptConfigInfo = getYyptConfigInfo;
|
|
179
174
|
async function writeLibCommonRes2file(gItem, codeDir) {
|
|
180
|
-
const compLibCommonResource = gItem
|
|
175
|
+
const { compLibCommonResource } = gItem;
|
|
181
176
|
const libCommonResFiles = [];
|
|
182
177
|
libCommonResFiles.push({
|
|
183
178
|
path: path_1.default.join(codeDir, `class.${codeDir.includes('/mp/') ? 'wxss' : 'less'}`),
|
|
@@ -227,14 +222,11 @@ const _OFFICIAL_COMPONENT_LIB = {
|
|
|
227
222
|
};
|
|
228
223
|
function isOfficialComponentLib(name, version) {
|
|
229
224
|
var _a, _b;
|
|
230
|
-
return
|
|
231
|
-
((_b = _OFFICIAL_COMPONENT_LIB[name]) === null || _b === void 0 ? void 0 : _b.includes('*')));
|
|
225
|
+
return !!((_a = _OFFICIAL_COMPONENT_LIB[name]) === null || _a === void 0 ? void 0 : _a.includes(version)) || ((_b = _OFFICIAL_COMPONENT_LIB[name]) === null || _b === void 0 ? void 0 : _b.includes('*'));
|
|
232
226
|
}
|
|
233
227
|
exports.isOfficialComponentLib = isOfficialComponentLib;
|
|
234
228
|
function gererateIndexAPI(data, isComponent) {
|
|
235
|
-
const lowCodes = data.lowCodes ||
|
|
236
|
-
data.codeModules ||
|
|
237
|
-
[];
|
|
229
|
+
const lowCodes = data.lowCodes || data.codeModules || [];
|
|
238
230
|
if (!lowCodes.find(({ name }) => name === 'index')) {
|
|
239
231
|
// 补充组件不存在的 index 类型代码
|
|
240
232
|
lowCodes.push({
|
|
@@ -253,9 +245,7 @@ exports.gererateIndexAPI = gererateIndexAPI;
|
|
|
253
245
|
*/
|
|
254
246
|
function canUseVite(mode, devTool) {
|
|
255
247
|
return false;
|
|
256
|
-
return
|
|
257
|
-
mode !== 'production' &&
|
|
258
|
-
(0, compare_versions_1.default)(process.version, '12.0.0') >= 0);
|
|
248
|
+
return devTool === 'vite' && mode !== 'production' && (0, compare_versions_1.default)(process.version, '12.0.0') >= 0;
|
|
259
249
|
}
|
|
260
250
|
exports.canUseVite = canUseVite;
|
|
261
251
|
function deepDealComponentSchemaJson(schema, dealFn) {
|
|
@@ -282,3 +272,38 @@ function getCompileDirs(appKey = 'test') {
|
|
|
282
272
|
};
|
|
283
273
|
}
|
|
284
274
|
exports.getCompileDirs = getCompileDirs;
|
|
275
|
+
function generateLowcodeImportor(lowcodes = []) {
|
|
276
|
+
const importor = {
|
|
277
|
+
state: false,
|
|
278
|
+
computed: false,
|
|
279
|
+
lifecycle: false,
|
|
280
|
+
common: false,
|
|
281
|
+
styles: [],
|
|
282
|
+
};
|
|
283
|
+
lowcodes.forEach((mod) => {
|
|
284
|
+
switch (mod.type) {
|
|
285
|
+
case cals_1.ECodeType.STYLE: {
|
|
286
|
+
importor.styles.push(mod);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case cals_1.ECodeType.LIFECYCLE: {
|
|
290
|
+
importor.lifecycle = true;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
case cals_1.ECodeType.STATE: {
|
|
294
|
+
importor.state = true;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
case cals_1.ECodeType.COMPUTEDN: {
|
|
298
|
+
importor.computed = true;
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
case cals_1.ECodeType.NORMAL_MODULE: {
|
|
302
|
+
importor.common = true;
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
return importor;
|
|
308
|
+
}
|
|
309
|
+
exports.generateLowcodeImportor = generateLowcodeImportor;
|