@cloudbase/lowcode-builder 1.0.20 → 1.0.23

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,4 +1,4 @@
1
- export { REPLACE_SIGN, MP_CONFIG_MODULE_NAME, KBONE_PAGE_KEYS, npmRegistry, remConfig, rpxConfig, } from '@cloudbase/lowcode-generator/lib/generator/config/index';
1
+ export { REPLACE_SIGN, MP_CONFIG_MODULE_NAME, KBONE_PAGE_KEYS, npmRegistry, remConfig, rpxConfig, OFFICIAL_LIB_KEY, } from '@cloudbase/lowcode-generator/lib/generator/config/index';
2
2
  export declare const sharedMaterialsDir: string;
3
3
  export declare const appTemplateDir: string;
4
4
  export declare const materialsDirName = "materials";
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.miniprogramDir = exports.miniprogramURL = exports.builderTemplateURL = exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
29
+ exports.miniprogramDir = exports.miniprogramURL = exports.builderTemplateURL = exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.OFFICIAL_LIB_KEY = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
30
30
  const path = __importStar(require("path"));
31
31
  const os_1 = __importDefault(require("os"));
32
32
  var index_1 = require("@cloudbase/lowcode-generator/lib/generator/config/index");
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "KBONE_PAGE_KEYS", { enumerable: true, get: funct
36
36
  Object.defineProperty(exports, "npmRegistry", { enumerable: true, get: function () { return index_1.npmRegistry; } });
37
37
  Object.defineProperty(exports, "remConfig", { enumerable: true, get: function () { return index_1.remConfig; } });
38
38
  Object.defineProperty(exports, "rpxConfig", { enumerable: true, get: function () { return index_1.rpxConfig; } });
39
+ Object.defineProperty(exports, "OFFICIAL_LIB_KEY", { enumerable: true, get: function () { return index_1.OFFICIAL_LIB_KEY; } });
39
40
  exports.sharedMaterialsDir = path.join(os_1.default.homedir(), '.weapps-materials');
40
41
  exports.appTemplateDir = path.resolve(__dirname, '../../../template');
41
42
  exports.materialsDirName = 'materials'; // materials diretory of current project
@@ -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,12 +13,12 @@ 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");
20
19
  const mp_1 = require("../mp");
21
20
  const common_2 = require("../../utils/common");
21
+ const config_1 = require("../config");
22
22
  async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraData, cals, buildTypeList = [common_1.BuildType.WEB], subAppCalsList, mode, devTool, runtime = types_1.RUNTIME.NONE, deployMode = types_1.DEPLOY_MODE.PREVIEW, ignoreInstall = false, domain = '', }) {
23
23
  var _a, _b;
24
24
  try {
@@ -52,7 +52,7 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
52
52
  // 前置操作
53
53
  const { publicPath, basename, assets = '' } = ((_b = mainAppData.appConfig) === null || _b === void 0 ? void 0 : _b.window) || {};
54
54
  // 获取 插入的cdn 资源
55
- const jsAssets = await (0, generate_2.handleAssets)({
55
+ const jsAssets = await (0, generate_1.handleAssets)({
56
56
  appBuildDir: buildDir,
57
57
  buildTypeList,
58
58
  assets,
@@ -63,17 +63,17 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
63
63
  // // 素材库
64
64
  const runHandleMaterialTag = '🚥 buildWebApp-runHandleMaterial';
65
65
  console.time(runHandleMaterialTag);
66
- // 精简只使用用到的组件库
67
- const filteredDependiences = dependencies.filter((lib) => {
68
- return !!allAppUsedComps[lib.name];
69
- });
70
- await (0, material_1.runHandleMaterial)(h5BuildDir, filteredDependiences, materialsDir, runtime, ignoreInstall);
66
+ // 精简只使用用到的组件库,并获取补齐json格式
67
+ const processedDependiencies = await (0, material_1.runHandleMaterial)(h5BuildDir, dependencies.filter((lib) => {
68
+ // 注意需要包涵官方的(gsd),部分平台方法需要由其补充
69
+ return lib.name === config_1.OFFICIAL_LIB_KEY || !!allAppUsedComps[lib.name];
70
+ }), materialsDir, runtime, ignoreInstall);
71
71
  console.timeEnd(runHandleMaterialTag);
72
72
  // // 获取 generate 需要的构建文件
73
73
  const runGenerateTag = '🚥 buildWebApp-generateProjectFiles';
74
74
  console.time(runGenerateTag);
75
75
  await (0, generate_1.generateProjectFiles)({
76
- dependencies: filteredDependiences,
76
+ dependencies: processedDependiencies,
77
77
  cals,
78
78
  mainAppData,
79
79
  subAppDataList,
@@ -95,7 +95,7 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
95
95
  mainAppData,
96
96
  subAppDataList,
97
97
  appBuildDir: h5BuildDir,
98
- dependencies: filteredDependiences,
98
+ dependencies: processedDependiencies,
99
99
  mode,
100
100
  devTool,
101
101
  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[];
@@ -459,6 +459,10 @@ function getAppendableJson(json) {
459
459
  return '';
460
460
  }
461
461
  // 处理使用到的组件
462
+ /**
463
+ * TODO: 与 cals 里的实现进行整合
464
+ * 关键点在于 appUsedComps 分组, 与 generic componen 的实现
465
+ */
462
466
  function handleUsedComponents({ buildContext, weapps, materials, }) {
463
467
  const appUsedComps = weapps.map((app) => {
464
468
  var _a;
@@ -277,7 +277,7 @@ async function generateCompositeComponent(compositedComp, ctx, compLibCommonReso
277
277
  materialName,
278
278
  propDefs,
279
279
  handlers: compositedComp.lowCodes
280
- .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)
281
281
  .map((m) => m.name),
282
282
  eventHandlers: (0, util_3.createEventHanlders)(compositedComp.componentInstances, weapps_core_1.COMPONENT_API_PREFIX, ctx),
283
283
  // protectEventKeys: builtinMpEvents,
@@ -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 config_1 = require("../config");
14
15
  const os_1 = __importDefault(require("os"));
15
16
  var common_1 = require("@cloudbase/lowcode-generator/lib/generator/util/common");
16
17
  Object.defineProperty(exports, "getMetaInfoBySourceKey", { enumerable: true, get: function () { return common_1.getMetaInfoBySourceKey; } });
@@ -108,7 +109,7 @@ async function getComponentsInfo(appBuildDir, dependencies) {
108
109
  await Promise.all(dependencies.map(async ({ name: materialName, version, components = [], isComposite }) => {
109
110
  if (isComposite) {
110
111
  components.forEach((component) => {
111
- let compItem = component;
112
+ let { lowCodes, componentInstances, ...compItem } = component;
112
113
  const sourceKey = `${materialName}:${compItem.name}`;
113
114
  outputObj[sourceKey] = {
114
115
  isComposite,
@@ -217,7 +218,7 @@ function readComponentLibMata(libDir) {
217
218
  }
218
219
  exports.readComponentLibMata = readComponentLibMata;
219
220
  const _OFFICIAL_COMPONENT_LIB = {
220
- 'gsd-h5-react': ['*'],
221
+ [config_1.OFFICIAL_LIB_KEY]: ['*'],
221
222
  CLOUDBASE_BUSSINESS: ['1627377179261'],
222
223
  };
223
224
  function isOfficialComponentLib(name, version) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "1.0.20",
3
+ "version": "1.0.23",
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.1",
42
- "@cloudbase/lowcode-generator": "^1.0.6",
41
+ "@cloudbase/cals": "^0.4.3",
42
+ "@cloudbase/lowcode-generator": "^1.0.9",
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.aa184d8a35d646df4cc0.bundle.js"
464
+ src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.d09b61499ac932efe330.bundle.js"
465
465
  ></script>
466
466
  </body>
467
467
  </html>
@@ -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