@cloudbase/lowcode-builder 1.0.18 → 1.0.21

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.
@@ -1,3 +1,3 @@
1
1
  import { IWebRuntimeAppData, II18nConfig, IMaterialItem } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  export declare function runCopy(appBuildDir: string, webRuntimeAppData: IWebRuntimeAppData, i18nConfig?: II18nConfig): Promise<void>;
3
- export declare function copyMaterialLibraries(dependencies: IMaterialItem[] | undefined, materialsDir: string, appBuildDir: string): Promise<void>;
3
+ export declare function copyMaterialLibraries(dependencies: IMaterialItem[] | undefined, materialsDir: string, appBuildDir: string): Promise<void[]>;
@@ -57,8 +57,7 @@ async function runCopy(appBuildDir, webRuntimeAppData, i18nConfig) {
57
57
  exports.runCopy = runCopy;
58
58
  async function copyMaterialLibraries(dependencies = [], materialsDir, appBuildDir) {
59
59
  const localPkg = (0, common_1.getCurrentPackageJson)();
60
- await Promise.all(dependencies.map(async (componentLib) => {
61
- var _a, _b, _c, _d, _e;
60
+ return Promise.all(dependencies.map(async (componentLib) => {
62
61
  const { name, version } = componentLib;
63
62
  const materialNameVersion = `${name}@${version}`;
64
63
  const materialDir = path.join(materialsDir, materialNameVersion);
@@ -85,36 +84,6 @@ async function copyMaterialLibraries(dependencies = [], materialsDir, appBuildDi
85
84
  if (fs_extra_1.default.existsSync(nodeModulesPath) && !fs_extra_1.default.existsSync(targetNodeModulesPath)) {
86
85
  await fs_extra_1.default.symlink(nodeModulesPath, targetNodeModulesPath, 'dir');
87
86
  }
88
- // 副作用修改了dependence定义,trycatch 不阻塞主流程
89
- try {
90
- const meta = (0, common_1.readComponentLibMata)(librariesDir);
91
- if (meta === null || meta === void 0 ? void 0 : meta.schemaVersion) {
92
- componentLib['schemaVersion'] = meta === null || meta === void 0 ? void 0 : meta.schemaVersion;
93
- }
94
- let [major] = ((_a = meta === null || meta === void 0 ? void 0 : meta.schemaVersion) === null || _a === void 0 ? void 0 : _a.split('.')) || [];
95
- if (Number(major) >= 3) {
96
- componentLib['isPlainProps'] = true;
97
- }
98
- }
99
- catch (e) { }
100
- try {
101
- const packageJson = fs_extra_1.default.readJsonSync(path.join(materialDir, 'package.json'));
102
- if ((_c = (_b = packageJson.weda) === null || _b === void 0 ? void 0 : _b.platform) === null || _c === void 0 ? void 0 : _c.web) {
103
- const entries = (_e = (_d = packageJson.weda) === null || _d === void 0 ? void 0 : _d.platform) === null || _e === void 0 ? void 0 : _e.web;
104
- componentLib['entries'] = {
105
- entry: path.posix.relative(srcDir, entries.entry),
106
- components: path.posix.relative(srcDir, entries.components),
107
- actions: path.posix.relative(srcDir, entries.actions),
108
- };
109
- }
110
- else if (packageJson.lowcode) {
111
- const entry = path.posix.relative(srcDir, packageJson.lowcode);
112
- componentLib['entries'] = {
113
- entry,
114
- };
115
- }
116
- }
117
- catch (e) { }
118
87
  }));
119
88
  }
120
89
  exports.copyMaterialLibraries = copyMaterialLibraries;
@@ -13,7 +13,6 @@ const webpack_2 = require("../service/webpack");
13
13
  const npm_1 = require("./npm");
14
14
  const copy_1 = require("./copy");
15
15
  const common_1 = require("../types/common");
16
- const generate_2 = require("./generate");
17
16
  const compile_1 = require("./compile");
18
17
  const util_1 = require("../util");
19
18
  const types_1 = require("../../types");
@@ -52,7 +51,7 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
52
51
  // 前置操作
53
52
  const { publicPath, basename, assets = '' } = ((_b = mainAppData.appConfig) === null || _b === void 0 ? void 0 : _b.window) || {};
54
53
  // 获取 插入的cdn 资源
55
- const jsAssets = await (0, generate_2.handleAssets)({
54
+ const jsAssets = await (0, generate_1.handleAssets)({
56
55
  appBuildDir: buildDir,
57
56
  buildTypeList,
58
57
  assets,
@@ -63,17 +62,16 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
63
62
  // // 素材库
64
63
  const runHandleMaterialTag = '🚥 buildWebApp-runHandleMaterial';
65
64
  console.time(runHandleMaterialTag);
66
- // 精简只使用用到的组件库
67
- const filteredDependiences = dependencies.filter((lib) => {
65
+ // 精简只使用用到的组件库,并获取补齐json格式
66
+ const processedDependiencies = await (0, material_1.runHandleMaterial)(h5BuildDir, dependencies.filter((lib) => {
68
67
  return !!allAppUsedComps[lib.name];
69
- });
70
- await (0, material_1.runHandleMaterial)(h5BuildDir, filteredDependiences, materialsDir, runtime, ignoreInstall);
68
+ }), materialsDir, runtime, ignoreInstall);
71
69
  console.timeEnd(runHandleMaterialTag);
72
70
  // // 获取 generate 需要的构建文件
73
71
  const runGenerateTag = '🚥 buildWebApp-generateProjectFiles';
74
72
  console.time(runGenerateTag);
75
73
  await (0, generate_1.generateProjectFiles)({
76
- dependencies: filteredDependiences,
74
+ dependencies: processedDependiencies,
77
75
  cals,
78
76
  mainAppData,
79
77
  subAppDataList,
@@ -95,7 +93,7 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
95
93
  mainAppData,
96
94
  subAppDataList,
97
95
  appBuildDir: h5BuildDir,
98
- dependencies: filteredDependiences,
96
+ dependencies: processedDependiencies,
99
97
  mode,
100
98
  devTool,
101
99
  ignoreInstall,
@@ -24,71 +24,124 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.runHandleMaterial = void 0;
27
- const fs = __importStar(require("fs"));
27
+ const fs = __importStar(require("fs-extra"));
28
28
  const path = __importStar(require("path"));
29
- const lodash_1 = require("lodash");
30
29
  const webpack_1 = require("../service/webpack");
31
30
  const copy_1 = require("./copy");
32
31
  const types_1 = require("../../types");
33
32
  const common_1 = require("../util/common");
34
33
  async function runHandleMaterial(appBuildDir, dependencies = [], materialsDir, runtime = types_1.RUNTIME.NONE, ignoreInstall = false) {
35
- const allMaterials = [
36
- await handleNormalMaterial({
37
- dependencies,
38
- materialsDir,
39
- appBuildDir,
40
- runtime,
41
- ignoreInstall,
42
- }),
43
- ];
44
- return (0, lodash_1.flatten)(allMaterials);
34
+ const normalDependencies = [];
35
+ const compositeDependencies = [];
36
+ dependencies.forEach((item) => {
37
+ if (item.isComposite) {
38
+ compositeDependencies.push(item);
39
+ }
40
+ else {
41
+ normalDependencies.push(item);
42
+ }
43
+ });
44
+ const allMaterials = await handleNormalMaterial({
45
+ dependencies: normalDependencies,
46
+ materialsDir,
47
+ appBuildDir,
48
+ runtime,
49
+ ignoreInstall,
50
+ });
51
+ return allMaterials.concat(compositeDependencies);
45
52
  // TODO: 确认这里是否需要生成复合组件
46
53
  // await handleCompositeComponent({ dependencies, appBuildDir });
47
54
  }
48
55
  exports.runHandleMaterial = runHandleMaterial;
49
- async function handleNormalMaterial({ dependencies, materialsDir, appBuildDir, runtime, ignoreInstall = false }) {
56
+ async function handleNormalMaterial({ dependencies: normalDependencies, materialsDir, appBuildDir, runtime, ignoreInstall = false, }) {
50
57
  const timeTag = '-------------------- handleNormalMaterial';
51
58
  console.time(timeTag);
52
- const normalDependencies = dependencies.filter((item) => !item.isComposite);
53
59
  await (0, webpack_1.downloadAndInstallDependencies)(normalDependencies, materialsDir, {
54
60
  runtime,
55
61
  ignoreInstall,
56
62
  });
57
63
  await (0, copy_1.copyMaterialLibraries)(normalDependencies, materialsDir, appBuildDir);
58
64
  console.timeEnd(timeTag);
59
- return normalDependencies.map((metaInfo) => {
60
- var _a, _b;
61
- const { name: materialName } = metaInfo;
65
+ return Promise.all(normalDependencies.map(async (metaInfo) => {
66
+ var _a, _b, _c, _d, _e, _f;
67
+ const materialNameVersion = `${metaInfo.name}@${metaInfo.version}`;
62
68
  const materialItemPath = path
63
- .resolve(appBuildDir, 'src/libraries', `${metaInfo.name}@${metaInfo.version}`)
69
+ .resolve(appBuildDir, 'src/libraries', materialNameVersion)
64
70
  .replace(/packages\/\w+\//, ''); // HACK:去除子包的目录,找根目录的素材地址。后续提供一个方法获取这些关键路径。
65
71
  const materialComponentsPath = path.resolve(materialItemPath, `components`);
66
72
  const actionsDir = path.join(materialItemPath, 'actions');
67
73
  const meta = (0, common_1.readComponentLibMata)(materialItemPath);
68
74
  let actions = [];
69
75
  let components = [];
76
+ let { schemaVersion, isPlainProps, entries } = metaInfo;
77
+ try {
78
+ const packageJson = fs.readJsonSync(path.join(materialsDir, materialNameVersion, 'package.json'));
79
+ if ((_b = (_a = packageJson.weda) === null || _a === void 0 ? void 0 : _a.platform) === null || _b === void 0 ? void 0 : _b.web) {
80
+ const _entries = (_d = (_c = packageJson.weda) === null || _c === void 0 ? void 0 : _c.platform) === null || _d === void 0 ? void 0 : _d.web;
81
+ entries = {
82
+ entry: path.posix.relative('src', _entries.entry),
83
+ components: path.posix.relative('src', _entries.components),
84
+ actions: path.posix.relative('src', _entries.actions),
85
+ };
86
+ }
87
+ else if (packageJson.lowcode) {
88
+ entries = {
89
+ entry: path.posix.relative('src', packageJson.lowcode),
90
+ };
91
+ }
92
+ }
93
+ catch (e) { }
70
94
  if (meta) {
95
+ if (meta === null || meta === void 0 ? void 0 : meta.schemaVersion) {
96
+ schemaVersion = meta === null || meta === void 0 ? void 0 : meta.schemaVersion;
97
+ }
98
+ let [major] = ((_e = meta === null || meta === void 0 ? void 0 : meta.schemaVersion) === null || _e === void 0 ? void 0 : _e.split('.')) || [];
99
+ if (Number(major) >= 3) {
100
+ isPlainProps = true;
101
+ }
71
102
  const { components: componentsMap, actions: actionsMap = {} } = meta;
72
103
  for (let name in componentsMap) {
73
- components.push({ name });
104
+ const { $schema, platforms, data, dataForm, events, emitEvents, ...rest } = componentsMap[name];
105
+ components.push({
106
+ ...rest,
107
+ dataForm: dataForm || data.properties,
108
+ emitEvents: emitEvents ||
109
+ (events === null || events === void 0 ? void 0 : events.map((event) => {
110
+ return {
111
+ eventName: event.name,
112
+ name: event.title,
113
+ };
114
+ })),
115
+ name,
116
+ type: 'component',
117
+ });
74
118
  }
75
119
  for (let name in actionsMap) {
76
- actions.push({ name: name });
120
+ actions.push({ name });
77
121
  }
78
122
  }
79
123
  else {
80
124
  // 老格式,需要从子目录下读取
81
- actions = ((_a = fs.readdirSync(actionsDir)) === null || _a === void 0 ? void 0 : _a.map((dirName) => ({ name: dirName }))) || [];
82
- components = (_b = fs.readdirSync(materialComponentsPath)) === null || _b === void 0 ? void 0 : _b.map((dirName) => ({ name: dirName }));
125
+ actions = ((_f = fs.readdirSync(actionsDir)) === null || _f === void 0 ? void 0 : _f.map((dirName) => ({ name: dirName }))) || [];
126
+ components = await Promise.all((fs.readdirSync(materialComponentsPath) || []).map(async (name) => {
127
+ const componentMetaPath = `${materialComponentsPath}/${name}/meta.json`;
128
+ let metaJson = {
129
+ name,
130
+ meta: await fs.readJson(componentMetaPath),
131
+ };
132
+ return metaJson;
133
+ }));
83
134
  }
84
- // TODO: 根据mata判断而非readdir
85
135
  return {
86
136
  ...metaInfo,
87
- actions,
88
- components,
137
+ schemaVersion,
138
+ isPlainProps,
139
+ entries,
140
+ actions: actions.length ? actions : metaInfo.actions,
141
+ components: components.length ? components : metaInfo.components,
89
142
  plugins: [],
90
143
  };
91
- });
144
+ }));
92
145
  }
93
146
  // async function handleCompositeComponent({ dependencies, appBuildDir }) {
94
147
  // console.time('handleCompositeComponent');
@@ -23,6 +23,10 @@ export declare function generateWxMp({ weapps, projDir, appId, domain, materials
23
23
  miniprogramRoot: string;
24
24
  }>;
25
25
  export declare function writeLowCodeFiles(appData: IWeAppData, outDir: string, ctx: IBuildContext): Promise<void>;
26
+ /**
27
+ * TODO: 与 cals 里的实现进行整合
28
+ * 关键点在于 appUsedComps 分组, 与 generic componen 的实现
29
+ */
26
30
  export declare function handleUsedComponents({ buildContext, weapps, materials, }: {
27
31
  buildContext: IBuildContext;
28
32
  weapps: IWeAppData[];
@@ -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 { appUsedComps, allAppUsedComps } = handleUsedComponents({
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': { yyptConfig, appConfig },
157
+ 'app.js': { appConfig, importor },
157
158
  'app.json': { content: appConfig },
158
159
  'app.wxss': {
159
- importStyles: materials.reduce((styles, lib) => {
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
- isBare: true,
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
- isBare: false,
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 === 'normal-module' && m.name !== '____index____')
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 themeStyle = (0, style_1.generateDefaultTheme)(appData);
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(appData.lowCodes
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
- var _a;
431
- (0, style_1.generateDefaultStyle)(page);
432
- const codes = [...((page === null || page === void 0 ? void 0 : page.lowCodes) || [])];
433
- if (!codes.find((m) => m.name === 'index')) {
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;
@@ -461,6 +459,10 @@ function getAppendableJson(json) {
461
459
  return '';
462
460
  }
463
461
  // 处理使用到的组件
462
+ /**
463
+ * TODO: 与 cals 里的实现进行整合
464
+ * 关键点在于 appUsedComps 分组, 与 generic componen 的实现
465
+ */
464
466
  function handleUsedComponents({ buildContext, weapps, materials, }) {
465
467
  const appUsedComps = weapps.map((app) => {
466
468
  var _a;
@@ -8,16 +8,17 @@ 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.code;
15
- if (mod.type !== 'style' && mod.type !== 'theme') {
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
24
  'const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }})',
@@ -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 templateDir = config_1.appTemplateDir + '/mp/';
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, util_4.readComponentLibMata)(libDir);
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: function (src, dest) {
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: function (src, dest) {
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, util_4.readComponentLibMata)(targetDir);
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 + '/index',
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('Generate composited library ' + lib.name);
175
- await (0, util_4.writeLibCommonRes2file)(lib, path.join(ctx.projDir, config_1.materialsDirName, lib.name, 'libCommonRes'));
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 + ':' + cmpName);
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, 'Component ' + materialName + ':' + compositedComp.name, wxmlDataPrefix, { ...ctx, isPage: false }, usingComponents, componentGenerics, (cmp, node) => {
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,12 +270,14 @@ 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: materialName,
277
+ materialName,
281
278
  propDefs,
282
279
  handlers: compositedComp.lowCodes
283
- .filter((m) => m.type === 'handler-fn' && m.name !== '____index____')
280
+ .filter((m) => m.type === cals_1.ECodeType.HANDLER_FN && m.name !== cals_1.ECodeName.PLACEHOLDER)
284
281
  .map((m) => m.name),
285
282
  eventHandlers: (0, util_3.createEventHanlders)(compositedComp.componentInstances, weapps_core_1.COMPONENT_API_PREFIX, ctx),
286
283
  // protectEventKeys: builtinMpEvents,
@@ -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 + ':' + compositedComp.name,
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 + '/component', outDir, ctx);
308
+ await (0, generateFiles_1.default)(pageFileData, `${templateDir}/component`, outDir, ctx);
309
309
  // #3 writing lowcode files
310
- const codes = [...compositedComp.lowCodes];
311
- if (!codes.find((m) => m.name === 'index')) {
312
- // @ts-ignore
313
- codes.push({
314
- code: 'export default {}',
315
- name: 'index',
316
- path: 'index',
317
- });
318
- }
319
- codes
320
- .filter((mod) => mod.name !== '____index____')
321
- .map((mod) => {
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 === 'style' && compLibCommonResource) {
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, 'lowcode'), { comp: compositedComp }, themeCode, ctx);
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 { ICompositedComponent, IMaterialItem, IPageInstance, IWeAppComponentInstance } from '@cloudbase/lowcode-generator/lib/weapps-core';
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.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.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, function (match, expression) {
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,
@@ -113,7 +108,7 @@ async function getComponentsInfo(appBuildDir, dependencies) {
113
108
  await Promise.all(dependencies.map(async ({ name: materialName, version, components = [], isComposite }) => {
114
109
  if (isComposite) {
115
110
  components.forEach((component) => {
116
- let compItem = component;
111
+ let { lowCodes, componentInstances, ...compItem } = component;
117
112
  const sourceKey = `${materialName}:${compItem.name}`;
118
113
  outputObj[sourceKey] = {
119
114
  isComposite,
@@ -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.compLibCommonResource;
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'}`),
@@ -205,6 +200,7 @@ function readComponentLibMata(libDir) {
205
200
  if (!isExistsMeta) {
206
201
  return null;
207
202
  }
203
+ console.log('meta path', metaPath);
208
204
  let meta = fs_extra_1.default.readJSONSync(metaPath);
209
205
  let [major] = ((_a = meta === null || meta === void 0 ? void 0 : meta.schemaVersion) === null || _a === void 0 ? void 0 : _a.split('.')) || [];
210
206
  const originComponentMetaMap = meta.components;
@@ -227,35 +223,16 @@ const _OFFICIAL_COMPONENT_LIB = {
227
223
  };
228
224
  function isOfficialComponentLib(name, version) {
229
225
  var _a, _b;
230
- return (!!((_a = _OFFICIAL_COMPONENT_LIB[name]) === null || _a === void 0 ? void 0 : _a.includes(version)) ||
231
- ((_b = _OFFICIAL_COMPONENT_LIB[name]) === null || _b === void 0 ? void 0 : _b.includes('*')));
226
+ 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
227
  }
233
228
  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
229
  /**
251
230
  * 能否使用 Vite
252
231
  * @param mode 当前 mode 模式
253
232
  */
254
233
  function canUseVite(mode, devTool) {
255
234
  return false;
256
- return (devTool === 'vite' &&
257
- mode !== 'production' &&
258
- (0, compare_versions_1.default)(process.version, '12.0.0') >= 0);
235
+ return devTool === 'vite' && mode !== 'production' && (0, compare_versions_1.default)(process.version, '12.0.0') >= 0;
259
236
  }
260
237
  exports.canUseVite = canUseVite;
261
238
  function deepDealComponentSchemaJson(schema, dealFn) {
@@ -282,3 +259,38 @@ function getCompileDirs(appKey = 'test') {
282
259
  };
283
260
  }
284
261
  exports.getCompileDirs = getCompileDirs;
262
+ function generateLowcodeImportor(lowcodes = []) {
263
+ const importor = {
264
+ state: false,
265
+ computed: false,
266
+ lifecycle: false,
267
+ common: false,
268
+ styles: [],
269
+ };
270
+ lowcodes.forEach((mod) => {
271
+ switch (mod.type) {
272
+ case cals_1.ECodeType.STYLE: {
273
+ importor.styles.push(mod);
274
+ break;
275
+ }
276
+ case cals_1.ECodeType.LIFECYCLE: {
277
+ importor.lifecycle = true;
278
+ break;
279
+ }
280
+ case cals_1.ECodeType.STATE: {
281
+ importor.state = true;
282
+ break;
283
+ }
284
+ case cals_1.ECodeType.COMPUTEDN: {
285
+ importor.computed = true;
286
+ break;
287
+ }
288
+ case cals_1.ECodeType.NORMAL_MODULE: {
289
+ importor.common = true;
290
+ break;
291
+ }
292
+ }
293
+ });
294
+ return importor;
295
+ }
296
+ exports.generateLowcodeImportor = generateLowcodeImportor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "1.0.18",
3
+ "version": "1.0.21",
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.4.0",
42
- "@cloudbase/lowcode-generator": "^1.0.5",
41
+ "@cloudbase/cals": "^0.4.2",
42
+ "@cloudbase/lowcode-generator": "^1.0.7",
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.3a66f83a42344bba1e13.bundle.js"
464
+ src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.51d9d452d9a709afe6a4.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, EXTRA_API } from '<%= subLevelPath %>../datasources/index'
6
+ import { createDataset } from '<%= subLevelPath %>../datasources/index'
7
7
 
8
- <% if (!isBare) {%>
9
- import state from '../lowcode/state'
10
- import computed from '../lowcode/computed'
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
 
@@ -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'
@@ -95,23 +95,15 @@ App({
95
95
  createStateDataSourceVar('$global', generateParamsParser({ app }))
96
96
 
97
97
  onLaunch && onLaunch.call(this, options)
98
- <% if (yyptConfig.yyptAppKey) { %>
99
- // 挂运营平台上报对象到app里
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
- <% if (yyptConfig.yyptAppKey) { %>
112
- wxReport.startReport()
113
- <% }%>
114
- },
106
+ },
115
107
  onHide() {
116
108
  const fn = lifeCycle.onHide || lifeCycle.onAppHide
117
109
  fn && fn.call(this)
@@ -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,6 +2,7 @@
2
2
  import { findForItemsOfWidget, getWidget } from './widget'
3
3
  import { observable } from 'mobx';
4
4
  import { getAccessToken } from '../datasources/index'
5
+ import { app } from '../app/weapps-api'
5
6
 
6
7
  /**
7
8
  * Convert abcWordSnd -> abc-word-snd
@@ -44,10 +45,10 @@ export function createEventHandlers(evtListeners, context) {
44
45
  listeners.forEach(async l => {
45
46
  let { data = {}, boundData = {} } = l
46
47
  data = { ...data }
47
- for (const k in boundData) {
48
- set(data, k, boundData[k].call(owner, owner, lists, itemsById, event, context))
49
- }
50
48
  try {
49
+ for (const k in boundData) {
50
+ set(data, k, boundData[k].call(owner, owner, lists, itemsById, event, context))
51
+ }
51
52
  let res = await l.handler.call(owner, { event, lists, forItems: itemsById, data })
52
53
  let eventName = prefix && l.key ? `${prefix}$${l.key}_success` : ''
53
54
  self[eventName] && self[eventName]({
@@ -57,11 +58,16 @@ export function createEventHandlers(evtListeners, context) {
57
58
  } catch (e) {
58
59
  let eventName = l.key ? `${prefix}$${l.key}_fail` : ''
59
60
  if (self[eventName]) {
61
+ console.error(`事件响应失败`, e)
60
62
  await self[eventName]({
61
63
  ...event,
62
64
  detail: e
63
65
  })
64
66
  } else {
67
+ app.showToast({
68
+ icon: 'error',
69
+ title: `事件响应失败`
70
+ })
65
71
  throw e
66
72
  }
67
73
 
@@ -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 index from './lowcode/index'
6
- import lifeCycle from './lowcode/lifecycle'
7
- import stateFn from './lowcode/state'
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
- index, lifeCycle, stateFn, computedFuncs, config, { const: constObj, tools: toolsObj }, libCode, context)
63
+ {}, lifeCycle, stateFn, computedFuncs, config, { const: constObj, tools: toolsObj }, libCode, context)
@@ -1 +1,2 @@
1
- @import './lowcode/style.wxss';
1
+ <% importStyles.map(style => {%>
2
+ @import '<%= style %>';<%})%>
@@ -3,9 +3,9 @@ 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/<%= pageName %>/lifecycle'
7
- import state from '../../lowcode/<%= pageName %>/state'
8
- import computed from '../../lowcode/<%= pageName %>/computed'
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
11
  const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});