@cloudbase/lowcode-builder 1.0.17 → 1.0.20
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/mp/index.js +23 -25
- package/lib/builder/mp/lowcode.js +6 -5
- package/lib/builder/mp/materials.js +38 -38
- package/lib/builder/util/common.d.ts +8 -2
- package/lib/builder/util/common.js +43 -32
- package/package.json +3 -3
- package/template/html/index.html.ejs +1 -1
- package/template/mp/app/weapps-api.js +4 -10
- package/template/mp/app.js +5 -13
- package/template/mp/app.wxss +1 -4
- package/template/mp/component/index.js +4 -5
- package/template/mp/component/index.wxss +2 -1
- package/template/mp/page/index.js +4 -4
package/lib/builder/mp/index.js
CHANGED
|
@@ -44,13 +44,13 @@ 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
54
|
const templateDir = `${config_1.appTemplateDir}/mp/`;
|
|
55
55
|
const em = chalk_1.default.blue.bold;
|
|
56
56
|
const error = chalk_1.default.redBright;
|
|
@@ -73,7 +73,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
73
73
|
isBrowserMpBuilder,
|
|
74
74
|
};
|
|
75
75
|
const yyptConfig = await (0, util_3.getYyptConfigInfo)(extraData);
|
|
76
|
-
const {
|
|
76
|
+
const { allAppUsedComps } = handleUsedComponents({
|
|
77
77
|
buildContext,
|
|
78
78
|
weapps,
|
|
79
79
|
materials,
|
|
@@ -150,16 +150,19 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
150
150
|
await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
|
|
151
151
|
}
|
|
152
152
|
else {
|
|
153
|
+
const importor = (0, util_3.generateLowcodeImportor)(mainAppData.lowCodes || []);
|
|
153
154
|
appFileData = {
|
|
154
155
|
...appFileData,
|
|
155
156
|
'common/wx_yypt_report_v2.js': {},
|
|
156
|
-
'app.js': {
|
|
157
|
+
'app.js': { appConfig, importor },
|
|
157
158
|
'app.json': { content: appConfig },
|
|
158
159
|
'app.wxss': {
|
|
159
|
-
importStyles: materials
|
|
160
|
+
importStyles: materials
|
|
161
|
+
.reduce((styles, lib) => {
|
|
160
162
|
styles = styles.concat((lib.styles || []).map((stylePath) => stylePath && !stylePath.startsWith('/') ? `/${config_1.materialsDirName}/${lib.name}/${stylePath}` : stylePath) || []);
|
|
161
163
|
return styles;
|
|
162
|
-
}, [])
|
|
164
|
+
}, [])
|
|
165
|
+
.concat(importor.styles.map((mod) => path_1.default.join('lowcode', (0, weapps_core_1.getCodeModuleFilePath)('global', mod, { style: '.wxss' })))),
|
|
163
166
|
},
|
|
164
167
|
'package.json': {
|
|
165
168
|
appId,
|
|
@@ -303,6 +306,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
|
|
|
303
306
|
const usingComponents = {};
|
|
304
307
|
const componentGenerics = {};
|
|
305
308
|
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);
|
|
309
|
+
const importor = (0, util_3.generateLowcodeImportor)(page.lowCodes);
|
|
306
310
|
const pageFileName = (0, lodash_1.get)(pageConfigs, `${page.id}.pageFileName`, 'index');
|
|
307
311
|
const pageFileData = {
|
|
308
312
|
[`api.js|api.js`]: {},
|
|
@@ -319,6 +323,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
|
|
|
319
323
|
debug: ctx.debugMode,
|
|
320
324
|
stringifyObj: util_1.inspect,
|
|
321
325
|
subLevelPath: rootPath ? `${path_1.default.relative(rootPath, '')}/` : '',
|
|
326
|
+
importor,
|
|
322
327
|
},
|
|
323
328
|
[`index.json|${pageFileName}.json`]: {
|
|
324
329
|
usingComponents,
|
|
@@ -337,7 +342,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
|
|
|
337
342
|
toRem: false,
|
|
338
343
|
toRpx: true,
|
|
339
344
|
}), 'page'),
|
|
340
|
-
pageWxss: `@import "../../lowcode/${page.id}/style.wxss"
|
|
345
|
+
pageWxss: importor.styles.length ? `@import "../../lowcode/${page.id}/style.wxss"` : '',
|
|
341
346
|
},
|
|
342
347
|
};
|
|
343
348
|
// Generating file by template and data
|
|
@@ -358,7 +363,7 @@ async function generateFramework(appData, outDir, ctx) {
|
|
|
358
363
|
appId: ctx.appId,
|
|
359
364
|
subLevelPath: '',
|
|
360
365
|
subPackageName: '',
|
|
361
|
-
|
|
366
|
+
importor: (0, util_3.generateLowcodeImportor)([]),
|
|
362
367
|
domain: ctx.domain || '',
|
|
363
368
|
appConfig: JSON.stringify({}),
|
|
364
369
|
},
|
|
@@ -379,6 +384,7 @@ async function generateFramework(appData, outDir, ctx) {
|
|
|
379
384
|
// 子包混合模式 只在子包中生成 handlers
|
|
380
385
|
const isMixSubpackage = ctx.isMixMode && appData.rootPath;
|
|
381
386
|
if (!isMixSubpackage) {
|
|
387
|
+
const importor = (0, util_3.generateLowcodeImportor)(appData.lowCodes);
|
|
382
388
|
fileData = {
|
|
383
389
|
...fileData,
|
|
384
390
|
'app/app-global.js': {},
|
|
@@ -387,7 +393,7 @@ async function generateFramework(appData, outDir, ctx) {
|
|
|
387
393
|
domain: ctx.domain || '',
|
|
388
394
|
subLevelPath: appData.rootPath ? `${path_1.default.relative(`${appData.rootPath}`, '')}/` : '',
|
|
389
395
|
subPackageName: appData.rootPath || '',
|
|
390
|
-
|
|
396
|
+
importor,
|
|
391
397
|
appConfig: (0, util_3.JsonToStringWithVariableName)({
|
|
392
398
|
id: ctx.appId,
|
|
393
399
|
envId: appData.envId,
|
|
@@ -403,7 +409,7 @@ async function generateFramework(appData, outDir, ctx) {
|
|
|
403
409
|
},
|
|
404
410
|
'app/common.js': {
|
|
405
411
|
mods: appData.lowCodes
|
|
406
|
-
.filter((m) => m.type ===
|
|
412
|
+
.filter((m) => m.type === cals_1.ECodeType.NORMAL_MODULE && m.name !== '____index____')
|
|
407
413
|
.map((m) => m.name)
|
|
408
414
|
.sort(),
|
|
409
415
|
},
|
|
@@ -416,31 +422,23 @@ async function generateFramework(appData, outDir, ctx) {
|
|
|
416
422
|
async function writeLowCodeFiles(appData, outDir, ctx) {
|
|
417
423
|
console.log(`Writing ${em('lowcode')} files:`);
|
|
418
424
|
const lowcodeRootDir = path_1.default.join(outDir, 'lowcode');
|
|
419
|
-
const
|
|
425
|
+
const lowCodes = (0, cals_1.processRuntimeCodeResources)({ id: 'global' }, appData.lowCodes || appData.codeModules, 'app');
|
|
426
|
+
const themeStyle = lowCodes.find((mod) => mod.type === cals_1.ECodeType.THEME);
|
|
420
427
|
// 混合模式,子包不生成顶级(应用级)的 lowcodes
|
|
421
428
|
if (!(ctx.isMixMode && appData.rootPath)) {
|
|
422
|
-
await Promise.all(
|
|
423
|
-
.filter((mod) => mod.name !== '____index____')
|
|
429
|
+
await Promise.all(lowCodes
|
|
424
430
|
.filter((mod) => mod.type !== 'renderer')
|
|
425
431
|
.map((m) => {
|
|
426
432
|
(0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { appDir: outDir }, themeStyle.code);
|
|
427
433
|
}));
|
|
428
434
|
}
|
|
429
435
|
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) => {
|
|
436
|
+
const codes = (0, cals_1.processRuntimeCodeResources)({ id: page.id }, page.lowCodes || page.codeModules, 'page');
|
|
437
|
+
await codes
|
|
438
|
+
.filter((mod) => mod.type !== 'renderer')
|
|
439
|
+
.forEach((m) => {
|
|
442
440
|
(0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { pageId: page.id, appDir: outDir }, themeStyle.code, ctx);
|
|
443
|
-
})
|
|
441
|
+
});
|
|
444
442
|
}));
|
|
445
443
|
}
|
|
446
444
|
exports.writeLowCodeFiles = writeLowCodeFiles;
|
|
@@ -8,19 +8,20 @@ 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
19
|
const baseDir = path_1.default.relative(path_1.default.dirname(file), appDir).replace(/\\/g, '/');
|
|
19
20
|
// 子包混合模式需要添加相对索引到根目录
|
|
20
|
-
const relativeRoot = (ctx === null || ctx === void 0 ? void 0 : ctx.isMixMode) && ctx.rootPath ? path_1.default.relative(ctx.rootPath, '')
|
|
21
|
+
const relativeRoot = (ctx === null || ctx === void 0 ? void 0 : ctx.isMixMode) && ctx.rootPath ? `${path_1.default.relative(ctx.rootPath, '')}/` : '';
|
|
21
22
|
let weappsApiPrefix = [
|
|
22
23
|
`import { app, process } from '${relativeRoot}${baseDir}/app/weapps-api';`,
|
|
23
|
-
'const $app = app
|
|
24
|
+
'const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }})',
|
|
24
25
|
]; // windows compatibility
|
|
25
26
|
if (pageId !== 'global') {
|
|
26
27
|
weappsApiPrefix.push(`import { $page } from '${baseDir}/pages/${pageId}/api'`);
|
|
@@ -29,7 +30,7 @@ async function writeCode2file(mod, lowcodeRootDir, opts = {}, themeCode, ctx) {
|
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
32
|
// Generate component lowcode
|
|
32
|
-
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)}`;
|
|
33
|
+
code = `import process from '${mod.type === 'handler-fn' ? '../' : ''}../../../../common/process'\nimport app from '${mod.type === 'handler-fn' ? '../' : ''}../../../../common/weapp-sdk';\nconst $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});\n${code.replace(/\$comp/g, weapps_core_1.COMPONENT_API_PREFIX)}`;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
else {
|
|
@@ -36,14 +36,12 @@ 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
|
|
40
|
+
const cals_1 = require("@cloudbase/cals");
|
|
41
|
+
const templateDir = `${config_1.appTemplateDir}/mp/`;
|
|
42
42
|
async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
43
43
|
let { materialLibs, isBrowserMpBuilder } = ctx;
|
|
44
|
-
const weappsList = ctx.isMixMode
|
|
45
|
-
? weapps
|
|
46
|
-
: weapps.filter((item) => !item.rootPath);
|
|
44
|
+
const weappsList = ctx.isMixMode ? weapps : weapps.filter((item) => !item.rootPath);
|
|
47
45
|
// #1 Download uploaded libs
|
|
48
46
|
const localPkg = (0, util_2.getCurrentPackageJson)();
|
|
49
47
|
await Promise.all(materialLibs
|
|
@@ -62,7 +60,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
62
60
|
await downloadMaterial(mpPkgUrl, materialsSrcDir, ctx.isBrowserMpBuilder);
|
|
63
61
|
}
|
|
64
62
|
function libUpdated(libDir, version) {
|
|
65
|
-
const meta = (0,
|
|
63
|
+
const meta = (0, util_2.readComponentLibMata)(libDir);
|
|
66
64
|
if (!meta) {
|
|
67
65
|
return true;
|
|
68
66
|
}
|
|
@@ -98,7 +96,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
98
96
|
// #3 copy 组件库代码文件到项目目录
|
|
99
97
|
!isBrowserMpBuilder
|
|
100
98
|
? await fs.copy(materialsSrcDirPath, targetDir, {
|
|
101
|
-
filter
|
|
99
|
+
filter(src, dest) {
|
|
102
100
|
const path = src.split('/');
|
|
103
101
|
return !junk.is(path[path.length - 1]);
|
|
104
102
|
},
|
|
@@ -112,7 +110,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
112
110
|
// #2 link material to current project
|
|
113
111
|
!isBrowserMpBuilder
|
|
114
112
|
? await fs.copy(materialsSrcDir, targetDir, {
|
|
115
|
-
filter
|
|
113
|
+
filter(src, dest) {
|
|
116
114
|
const path = src.split('/');
|
|
117
115
|
return !junk.is(path[path.length - 1]);
|
|
118
116
|
},
|
|
@@ -122,7 +120,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
122
120
|
});
|
|
123
121
|
}
|
|
124
122
|
}
|
|
125
|
-
const libMeta = (0,
|
|
123
|
+
const libMeta = (0, util_2.readComponentLibMata)(targetDir);
|
|
126
124
|
if (!lib.components) {
|
|
127
125
|
lib.components = Object.keys((libMeta === null || libMeta === void 0 ? void 0 : libMeta.components) || {}).map((name) => {
|
|
128
126
|
var _a;
|
|
@@ -163,7 +161,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
163
161
|
}
|
|
164
162
|
cmp.meta.platforms = {
|
|
165
163
|
mp: {
|
|
166
|
-
path: cmp.name
|
|
164
|
+
path: `${cmp.name}/index`,
|
|
167
165
|
},
|
|
168
166
|
};
|
|
169
167
|
lib.dependencies = { ...lib.dependencies, ...cmp.npmDependencies };
|
|
@@ -171,8 +169,8 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
|
|
|
171
169
|
});
|
|
172
170
|
// #2 Generate composited libs
|
|
173
171
|
await Promise.all(compositedLibs.map(async (lib) => {
|
|
174
|
-
console.log(
|
|
175
|
-
await (0,
|
|
172
|
+
console.log(`Generate composited library ${lib.name}`);
|
|
173
|
+
await (0, util_2.writeLibCommonRes2file)(lib, path.join(ctx.projDir, config_1.materialsDirName, lib.name, 'libCommonRes'));
|
|
176
174
|
await Promise.all(lib.components.map(async (cmp) => {
|
|
177
175
|
return generateCompositeComponent(cmp, {
|
|
178
176
|
...ctx,
|
|
@@ -206,7 +204,7 @@ function extractUsedCompsRecursively(comps, checkedComps, compositedLibs, output
|
|
|
206
204
|
cmpNames.forEach((cmpName) => {
|
|
207
205
|
const cmp = lib.components.find((c) => c.name === cmpName);
|
|
208
206
|
if (!cmp) {
|
|
209
|
-
console.warn('Component not found', libName
|
|
207
|
+
console.warn('Component not found', `${libName}:${cmpName}`);
|
|
210
208
|
return;
|
|
211
209
|
}
|
|
212
210
|
if (checkedComps.indexOf(cmp) > -1)
|
|
@@ -237,23 +235,20 @@ async function generateCompositeComponent(compositedComp, ctx, compLibCommonReso
|
|
|
237
235
|
const { materialName } = compositedComp;
|
|
238
236
|
const outDir = path.join(ctx.projDir, ctx.rootPath || '', // 混合模式下,可能会有 rootPath
|
|
239
237
|
config_1.materialsDirName, materialName, compositedComp.name);
|
|
238
|
+
const LOWCODE_DIR_NAME = 'lowcode';
|
|
240
239
|
console.log(`Generating composited component ${materialName}:${compositedComp.name} to ${outDir}`);
|
|
241
240
|
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!ctx.isProduction);
|
|
242
241
|
// # Generating page
|
|
243
242
|
const usingComponents = {};
|
|
244
243
|
const componentGenerics = {};
|
|
245
244
|
const cmpContainer = Object.values(compositedComp.componentInstances)[0];
|
|
246
|
-
const wxml = (0, wxml_1.generateWxml)(compositedComp.componentInstances,
|
|
245
|
+
const wxml = (0, wxml_1.generateWxml)(compositedComp.componentInstances, `Component ${materialName}:${compositedComp.name}`, wxmlDataPrefix, { ...ctx, isPage: false }, usingComponents, componentGenerics, (cmp, node) => {
|
|
247
246
|
if (cmp === cmpContainer) {
|
|
248
247
|
// Set className & style passed from parent for root component
|
|
249
248
|
const { attributes } = node;
|
|
250
249
|
const classAttrName = (0, mp_1.getClassAttrName)(node.name);
|
|
251
250
|
const oldClass = attributes[classAttrName];
|
|
252
|
-
attributes[classAttrName] =
|
|
253
|
-
(0, weapps_core_1.getCompositedComponentClass)(compositedComp) +
|
|
254
|
-
' ' +
|
|
255
|
-
oldClass +
|
|
256
|
-
' {{className}}';
|
|
251
|
+
attributes[classAttrName] = `${(0, weapps_core_1.getCompositedComponentClass)(compositedComp)} ${oldClass} {{className}}`;
|
|
257
252
|
attributes.style += ';{{style}}';
|
|
258
253
|
}
|
|
259
254
|
});
|
|
@@ -275,9 +270,11 @@ async function generateCompositeComponent(compositedComp, ctx, compLibCommonReso
|
|
|
275
270
|
delete propDefs[p];
|
|
276
271
|
}
|
|
277
272
|
});
|
|
273
|
+
const codes = (0, cals_1.processRuntimeCodeResources)({ id: '$comp' }, compositedComp.lowCodes, 'component');
|
|
274
|
+
const importor = (0, util_2.generateLowcodeImportor)(codes);
|
|
278
275
|
const pageFileData = {
|
|
279
276
|
'index.js': {
|
|
280
|
-
materialName
|
|
277
|
+
materialName,
|
|
281
278
|
propDefs,
|
|
282
279
|
handlers: compositedComp.lowCodes
|
|
283
280
|
.filter((m) => m.type === 'handler-fn' && m.name !== '____index____')
|
|
@@ -288,13 +285,14 @@ async function generateCompositeComponent(compositedComp, ctx, compLibCommonReso
|
|
|
288
285
|
widgetProps: (0, util_3.createWidgetProps)(compositedComp.componentInstances, ctx),
|
|
289
286
|
compApi: weapps_core_1.COMPONENT_API_PREFIX,
|
|
290
287
|
jsonSchemaType2jsClass: mp_1.jsonSchemaType2jsClass,
|
|
291
|
-
key: compositedComp.materialName
|
|
288
|
+
key: `${compositedComp.materialName}:${compositedComp.name}`,
|
|
292
289
|
dataBinds: (0, util_3.createDataBinds)(compositedComp.componentInstances, ctx),
|
|
293
290
|
debug: !ctx.isProduction,
|
|
294
291
|
stringifyObj: util_1.inspect,
|
|
295
292
|
// dataPropNames: wxmlDataPrefix,
|
|
296
293
|
formEvents: Object.keys(formEvents).length > 0 ? formEvents : null,
|
|
297
294
|
config: compositedComp.compConfig,
|
|
295
|
+
importor,
|
|
298
296
|
},
|
|
299
297
|
'index.json': { usingComponents, componentGenerics },
|
|
300
298
|
'index.wxml': {
|
|
@@ -302,32 +300,34 @@ async function generateCompositeComponent(compositedComp, ctx, compLibCommonReso
|
|
|
302
300
|
// wrapperClass: getCompositedComponentClass(compositedComp),
|
|
303
301
|
content: wxml,
|
|
304
302
|
},
|
|
305
|
-
'index.wxss': {
|
|
303
|
+
'index.wxss': {
|
|
304
|
+
importStyles: importor.styles.map((mod) => path.join(LOWCODE_DIR_NAME, (0, weapps_core_1.getCodeModuleFilePath)('global', mod, { style: '.wxss' }))),
|
|
305
|
+
},
|
|
306
306
|
};
|
|
307
307
|
// Generating file by template and data
|
|
308
|
-
await (0, generateFiles_1.default)(pageFileData, templateDir
|
|
308
|
+
await (0, generateFiles_1.default)(pageFileData, `${templateDir}/component`, outDir, ctx);
|
|
309
309
|
// #3 writing lowcode files
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
310
|
+
/**
|
|
311
|
+
* 低码没有开放 index 类别,直接去掉
|
|
312
|
+
*/
|
|
313
|
+
// if (!codes.find((m) => m.name === 'index')) {
|
|
314
|
+
// // @ts-ignore
|
|
315
|
+
// codes.push({
|
|
316
|
+
// code: 'export default {}',
|
|
317
|
+
// name: 'index',
|
|
318
|
+
// path: 'index',
|
|
319
|
+
// });
|
|
320
|
+
// }
|
|
321
|
+
codes.map((mod) => {
|
|
322
322
|
let themeCode;
|
|
323
|
-
if (mod.type ===
|
|
323
|
+
if (mod.type === cals_1.ECodeType.STYLE && compLibCommonResource) {
|
|
324
324
|
themeCode = `
|
|
325
325
|
${compLibCommonResource.theme.variable || ''}
|
|
326
326
|
${compLibCommonResource.class || ''}
|
|
327
327
|
${compLibCommonResource.theme.class || ''}
|
|
328
328
|
`;
|
|
329
329
|
}
|
|
330
|
-
return (0, lowcode_1.writeCode2file)(mod, path.join(outDir,
|
|
330
|
+
return (0, lowcode_1.writeCode2file)(mod, path.join(outDir, LOWCODE_DIR_NAME), { comp: compositedComp }, themeCode, ctx);
|
|
331
331
|
});
|
|
332
332
|
// await writeLowCodeFiles(weapp, appRoot)
|
|
333
333
|
// await generateFramework(weapp, appRoot)
|
|
@@ -368,7 +368,7 @@ function getWxmlTag(cmp, ctx, nameMangler) {
|
|
|
368
368
|
compPath.startsWith('/') || compPath.indexOf('://') > 0
|
|
369
369
|
? compPath
|
|
370
370
|
: path.posix.join(
|
|
371
|
-
/*ctx.isMixMode ? '/' + rootPath : */ '', `/${config_1.materialsDirName}/${cmp.moduleName}`, compPath);
|
|
371
|
+
/* ctx.isMixMode ? '/' + rootPath : */ '', `/${config_1.materialsDirName}/${cmp.moduleName}`, compPath);
|
|
372
372
|
tagName = `${moduleName}-${name}`;
|
|
373
373
|
if (nameMangler) {
|
|
374
374
|
tagName = nameMangler.mangle(tagName);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IComponentInputProps, IComponentsInfoMap, IPackageJson } from '../types/common';
|
|
2
|
-
import {
|
|
2
|
+
import { IMaterialItem, 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>;
|
|
@@ -37,7 +37,6 @@ export declare function readComponentLibMata(libDir: any): {
|
|
|
37
37
|
};
|
|
38
38
|
} | null;
|
|
39
39
|
export declare function isOfficialComponentLib(name: any, version: any): boolean;
|
|
40
|
-
export declare function gererateIndexAPI(data: IPageInstance | ICompositedComponent, isComponent?: boolean): void;
|
|
41
40
|
/**
|
|
42
41
|
* 能否使用 Vite
|
|
43
42
|
* @param mode 当前 mode 模式
|
|
@@ -50,3 +49,10 @@ interface ICompileDirs {
|
|
|
50
49
|
materialsDir: string;
|
|
51
50
|
}
|
|
52
51
|
export declare function getCompileDirs(appKey?: string): ICompileDirs;
|
|
52
|
+
export declare function generateLowcodeImportor(lowcodes?: IWeAppCode[]): {
|
|
53
|
+
state: boolean;
|
|
54
|
+
computed: boolean;
|
|
55
|
+
lifecycle: boolean;
|
|
56
|
+
common: boolean;
|
|
57
|
+
styles: IWeAppCode[];
|
|
58
|
+
};
|
|
@@ -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.
|
|
6
|
+
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;
|
|
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,35 +222,16 @@ 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
|
-
function gererateIndexAPI(data, isComponent) {
|
|
235
|
-
const lowCodes = data.lowCodes ||
|
|
236
|
-
data.codeModules ||
|
|
237
|
-
[];
|
|
238
|
-
if (!lowCodes.find(({ name }) => name === 'index')) {
|
|
239
|
-
// 补充组件不存在的 index 类型代码
|
|
240
|
-
lowCodes.push({
|
|
241
|
-
type: 'index',
|
|
242
|
-
path: isComponent ? 'index' : `${data.id}/index`,
|
|
243
|
-
name: 'index',
|
|
244
|
-
code: 'export default {}',
|
|
245
|
-
system: true,
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
exports.gererateIndexAPI = gererateIndexAPI;
|
|
250
228
|
/**
|
|
251
229
|
* 能否使用 Vite
|
|
252
230
|
* @param mode 当前 mode 模式
|
|
253
231
|
*/
|
|
254
232
|
function canUseVite(mode, devTool) {
|
|
255
233
|
return false;
|
|
256
|
-
return
|
|
257
|
-
mode !== 'production' &&
|
|
258
|
-
(0, compare_versions_1.default)(process.version, '12.0.0') >= 0);
|
|
234
|
+
return devTool === 'vite' && mode !== 'production' && (0, compare_versions_1.default)(process.version, '12.0.0') >= 0;
|
|
259
235
|
}
|
|
260
236
|
exports.canUseVite = canUseVite;
|
|
261
237
|
function deepDealComponentSchemaJson(schema, dealFn) {
|
|
@@ -282,3 +258,38 @@ function getCompileDirs(appKey = 'test') {
|
|
|
282
258
|
};
|
|
283
259
|
}
|
|
284
260
|
exports.getCompileDirs = getCompileDirs;
|
|
261
|
+
function generateLowcodeImportor(lowcodes = []) {
|
|
262
|
+
const importor = {
|
|
263
|
+
state: false,
|
|
264
|
+
computed: false,
|
|
265
|
+
lifecycle: false,
|
|
266
|
+
common: false,
|
|
267
|
+
styles: [],
|
|
268
|
+
};
|
|
269
|
+
lowcodes.forEach((mod) => {
|
|
270
|
+
switch (mod.type) {
|
|
271
|
+
case cals_1.ECodeType.STYLE: {
|
|
272
|
+
importor.styles.push(mod);
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
case cals_1.ECodeType.LIFECYCLE: {
|
|
276
|
+
importor.lifecycle = true;
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
case cals_1.ECodeType.STATE: {
|
|
280
|
+
importor.state = true;
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case cals_1.ECodeType.COMPUTEDN: {
|
|
284
|
+
importor.computed = true;
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
case cals_1.ECodeType.NORMAL_MODULE: {
|
|
288
|
+
importor.common = true;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
return importor;
|
|
294
|
+
}
|
|
295
|
+
exports.generateLowcodeImportor = generateLowcodeImportor;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "云开发 Tencent CloudBase Framework Low Code Plugin,将低码配置生成完整项目并一键部署云开发资源。",
|
|
5
5
|
"author": "yhsunshining@gmail.com",
|
|
6
6
|
"homepage": "https://github.com/TencentCloudBase/cloudbase-framework#readme",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@cloudbase/cals": "^0.
|
|
42
|
-
"@cloudbase/lowcode-generator": "^1.0.
|
|
41
|
+
"@cloudbase/cals": "^0.4.1",
|
|
42
|
+
"@cloudbase/lowcode-generator": "^1.0.6",
|
|
43
43
|
"axios": "^0.21.0",
|
|
44
44
|
"browserfs": "^1.4.3",
|
|
45
45
|
"browserify-zlib": "^0.2.0",
|
|
@@ -461,7 +461,7 @@
|
|
|
461
461
|
></script>
|
|
462
462
|
<script
|
|
463
463
|
crossorigin
|
|
464
|
-
src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.
|
|
464
|
+
src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.aa184d8a35d646df4cc0.bundle.js"
|
|
465
465
|
></script>
|
|
466
466
|
</body>
|
|
467
467
|
</html>
|
|
@@ -3,17 +3,11 @@ import { createMpApp } from '@cloudbase/weda-client';
|
|
|
3
3
|
import { createComputed, formatEnum, enumOptions } from '<%= subLevelPath %>../common/util'
|
|
4
4
|
import process from '<%= subLevelPath %>../common/process'
|
|
5
5
|
import appGlobal from '<%= subLevelPath %>../app/app-global'
|
|
6
|
-
import { createDataset
|
|
6
|
+
import { createDataset } from '<%= subLevelPath %>../datasources/index'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import common from './common'
|
|
12
|
-
<%} else {%>
|
|
13
|
-
const state = {}
|
|
14
|
-
const computed = {}
|
|
15
|
-
const common = {}
|
|
16
|
-
<%}%>
|
|
8
|
+
<%= importor.state? `import state from '../lowcode/state'` : "const state = {}" %>
|
|
9
|
+
<%= importor.computed? `import computed from '../lowcode/computed'` : "const computed = {}" %>
|
|
10
|
+
<%= importor.common? `import common from './common'` : "const common = {}" %>
|
|
17
11
|
|
|
18
12
|
const mainAppKey = '__weappsMainApp'
|
|
19
13
|
|
package/template/mp/app.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import lifeCycle from './lowcode/lifecycle'
|
|
1
|
+
<%= importor.lifecycle? "import lifeCycle from './lowcode/lifecycle'" : "const lifeCycle = {}" %>
|
|
2
2
|
import { app } from './app/weapps-api'
|
|
3
3
|
// 引入数据源管理器并进行初始化
|
|
4
4
|
import { setConfig, getAccessToken, EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index'
|
|
@@ -15,7 +15,7 @@ console.warn = (...args) => {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const $app = app;
|
|
18
|
+
const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});
|
|
19
19
|
// 设置数据源请求的 loading 及 toast 处理
|
|
20
20
|
setConfig({
|
|
21
21
|
beforeDSRequest: (cfg) => {
|
|
@@ -95,23 +95,15 @@ App({
|
|
|
95
95
|
createStateDataSourceVar('$global', generateParamsParser({ app }))
|
|
96
96
|
|
|
97
97
|
onLaunch && onLaunch.call(this, options)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
app.yyptReport = wxReport
|
|
101
|
-
<% }%>
|
|
102
|
-
|
|
103
|
-
// 初始私有全局数据
|
|
104
|
-
this.$$global = {
|
|
98
|
+
// 初始私有全局数据
|
|
99
|
+
this.$$global = {
|
|
105
100
|
homePageId: '<%= appConfig.homePageId %>'
|
|
106
101
|
}
|
|
107
102
|
},
|
|
108
103
|
onShow(options) {
|
|
109
104
|
const fn = lifeCycle.onShow || lifeCycle.onAppShow
|
|
110
105
|
fn && fn.call(this, options)
|
|
111
|
-
|
|
112
|
-
wxReport.startReport()
|
|
113
|
-
<% }%>
|
|
114
|
-
},
|
|
106
|
+
},
|
|
115
107
|
onHide() {
|
|
116
108
|
const fn = lifeCycle.onHide || lifeCycle.onAppHide
|
|
117
109
|
fn && fn.call(this)
|
package/template/mp/app.wxss
CHANGED
|
@@ -8,8 +8,5 @@ page view, page element, page text, page image {
|
|
|
8
8
|
box-sizing: border-box;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
/** import styles specified by material libs*/<% importStyles.map(style => {%>
|
|
11
|
+
/** import styles specified by material libs & lowcode styles if exist*/<% importStyles.map(style => {%>
|
|
12
12
|
@import '<%= style %>';<%})%>
|
|
13
|
-
|
|
14
|
-
/** import lowcode styles */
|
|
15
|
-
@import 'lowcode/style.wxss';
|
|
@@ -2,10 +2,9 @@ import { observable } from 'mobx';
|
|
|
2
2
|
import { createComponent } from '../../../common/weapp-component'
|
|
3
3
|
import { concatClassList, px2rpx } from '../../../common/style'
|
|
4
4
|
import app from '../../../common/weapp-sdk'
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import computedFuncs from './lowcode/computed'
|
|
5
|
+
<%= importor.lifecycle? "import lifeCycle from './lowcode/lifecycle'" : "const lifeCycle = {}" %>
|
|
6
|
+
<%= importor.state? "import stateFn from './lowcode/state'" : "const stateFn = {}" %>
|
|
7
|
+
<%= importor.computed? "import computedFuncs from './lowcode/computed'" : "const computedFuncs = {}" %>
|
|
9
8
|
<% handlers.forEach(h => {%>
|
|
10
9
|
import _handler<%= h %> from './lowcode/handler/<%= h %>' <%}) %>
|
|
11
10
|
import * as constObj from '../libCommonRes/const'
|
|
@@ -61,4 +60,4 @@ const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
|
|
|
61
60
|
const config = <%= JSON.stringify(config || {})%>
|
|
62
61
|
|
|
63
62
|
createComponent('<%= key %>', behaviors, properties, events, handler, dataBinds, evtListeners, widgetProps,
|
|
64
|
-
|
|
63
|
+
{}, lifeCycle, stateFn, computedFuncs, config, { const: constObj, tools: toolsObj }, libCode, context)
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
<% importStyles.map(style => {%>
|
|
2
|
+
@import '<%= style %>';<%})%>
|
|
@@ -3,12 +3,12 @@ import { createPage } from '<%= subLevelPath %>../../common/weapp-page'
|
|
|
3
3
|
import { concatClassList, px2rpx } from '<%= subLevelPath %>../../common/style'
|
|
4
4
|
import { app } from '<%= subLevelPath %>../../app/weapps-api'
|
|
5
5
|
import { <%= pageName %> as handlers } from '../../app/handlers'
|
|
6
|
-
import lifecyle from '../../lowcode
|
|
7
|
-
import state from '../../lowcode
|
|
8
|
-
import computed from '../../lowcode
|
|
6
|
+
<%= importor.lifecycle? `import lifecyle from '../../lowcode/${pageName}/lifecycle'` : "const lifecyle = {}" %>
|
|
7
|
+
<%= importor.state? `import state from '../../lowcode/${pageName}/state'` : "const state = {}" %>
|
|
8
|
+
<%= importor.computed? `import computed from '../../lowcode/${pageName}/computed'` : "const computed = {}" %>
|
|
9
9
|
import { $page } from './api'
|
|
10
10
|
|
|
11
|
-
const $app = app;
|
|
11
|
+
const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});
|
|
12
12
|
const context = observable({});
|
|
13
13
|
|
|
14
14
|
const widgetProps = <%= stringifyObj(widgetProps, {depth: null}) %>
|