@cloudbase/lowcode-builder 0.1.14 → 0.1.17

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.
@@ -46,9 +46,8 @@ const types_1 = require("../../types");
46
46
  const common_1 = require("../types/common");
47
47
  const lodash_1 = require("lodash");
48
48
  const junk = __importStar(require("../util/junk"));
49
- const path_2 = __importDefault(require("path"));
50
49
  const net_1 = require("../util/net");
51
- const templateDir = config_1.appTemplateDir + '/mp/';
50
+ const templateDir = `${config_1.appTemplateDir}/mp/`;
52
51
  const em = chalk_1.default.blue.bold;
53
52
  const error = chalk_1.default.redBright;
54
53
  async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, extraData, isMixMode, options, buildTypeList, isBrowserMpBuilder = false, }) {
@@ -85,7 +84,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
85
84
  const projectFileData = {
86
85
  'project.config.json': { content: projConfig },
87
86
  };
88
- console.log('Generating ' + em('project') + ' files');
87
+ console.log(`Generating ${em('project')} files`);
89
88
  await (0, generateFiles_1.default)(projectFileData, templateDir, projDir, buildContext);
90
89
  }
91
90
  // #2 生成主包
@@ -143,17 +142,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
143
142
  await (0, generateFiles_1.writeFile)(projectConfigJsonPath, JSON.stringify(projectConfigJson, undefined, 2));
144
143
  let appJsonPath = path_1.default.join(miniprogramRoot, 'app.json');
145
144
  let appJson = await fs.readJson(appJsonPath);
146
- let subpackages = appJson.subpackages || [];
147
- for (let item of appConfig.subpackages || []) {
148
- let find = subpackages.find((config) => config.root === item.root);
149
- if (find) {
150
- find.pages = Array.from(new Set([].concat(find.pages || []).concat(item.pages || [])));
151
- }
152
- else {
153
- subpackages.push(item);
154
- }
155
- }
156
- appJson.subpackages = subpackages;
145
+ appJson.subpackages = (0, mp_config_1.mergeSubPackages)(appJson.subpackages, appConfig.subpackages);
157
146
  await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
158
147
  }
159
148
  else {
@@ -328,7 +317,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
328
317
  dataBinds: (0, util_2.createDataBinds)(page.componentInstances, ctx),
329
318
  debug: ctx.debugMode,
330
319
  stringifyObj: util_1.inspect,
331
- subLevelPath: rootPath ? path_2.default.relative(rootPath, '') + '/' : '',
320
+ subLevelPath: rootPath ? path_1.default.relative(rootPath, '') + '/' : '',
332
321
  },
333
322
  [`index.json|${pageFileName}.json`]: {
334
323
  usingComponents,
@@ -341,7 +330,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
341
330
  },
342
331
  [`index.wxss|${pageFileName}.wxss`]: {
343
332
  subWxss: rootPath && !((_a = ctx.mainAppData) === null || _a === void 0 ? void 0 : _a.mpPkgUrl)
344
- ? `@import "${path_2.default.relative(`/${rootPath}/pages/${page.id}`, '/lowcode')}/style.wxss";`
333
+ ? `@import "${path_1.default.relative(`/${rootPath}/pages/${page.id}`, '/lowcode')}/style.wxss";`
345
334
  : '',
346
335
  content: (0, weapps_core_1.toCssText)((0, weapps_core_1.toCssStyle)(page.commonStyle, {
347
336
  toRem: false,
@@ -426,14 +415,17 @@ async function generateFramework(appData, outDir, ctx) {
426
415
  await (0, generateFiles_1.default)(fileData, templateDir, outDir, ctx);
427
416
  }
428
417
  async function writeLowCodeFiles(appData, outDir, ctx) {
429
- console.log('Writing ' + em('lowcode') + ' files:');
418
+ console.log(`Writing ${em('lowcode')} files:`);
430
419
  const lowcodeRootDir = path_1.default.join(outDir, 'lowcode');
431
420
  const themeStyle = (0, style_1.generateDefaultTheme)(appData);
432
421
  // 混合模式,子包不生成顶级(应用级)的 lowcodes
433
422
  if (!(ctx.isMixMode && appData.rootPath)) {
434
423
  await Promise.all(appData.lowCodes
435
424
  .filter((mod) => mod.name !== '____index____')
436
- .map((m) => (0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { appDir: outDir }, themeStyle.code)));
425
+ .filter((mod) => mod.type !== 'renderer')
426
+ .map((m) => {
427
+ (0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { appDir: outDir }, themeStyle.code);
428
+ }));
437
429
  }
438
430
  await Promise.all((0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList, async (page) => {
439
431
  var _a;
@@ -447,7 +439,9 @@ async function writeLowCodeFiles(appData, outDir, ctx) {
447
439
  path: 'xx/index',
448
440
  });
449
441
  }
450
- await ((_a = page === null || page === void 0 ? void 0 : page.lowCodes) === null || _a === void 0 ? void 0 : _a.filter((mod) => mod.name !== '____index____').forEach((m) => (0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { pageId: page.id, appDir: outDir }, themeStyle.code, ctx)));
442
+ 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) => {
443
+ (0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { pageId: page.id, appDir: outDir }, themeStyle.code, ctx);
444
+ }));
451
445
  }));
452
446
  }
453
447
  exports.writeLowCodeFiles = writeLowCodeFiles;
@@ -7,11 +7,17 @@ import { IBuildContext } from './BuildContext';
7
7
  * @param appConfigs app config from prop edit panel
8
8
  */
9
9
  export declare function generateMpConfig(weapps: IWeAppData[], ctx: IBuildContext): {
10
- appConfig: {
11
- useExtendedLib: {
12
- weui: boolean;
13
- };
14
- };
10
+ appConfig: any;
15
11
  projConfig: any;
16
12
  pageConfigs: {}[];
17
13
  };
14
+ interface ISubpackage {
15
+ root: string;
16
+ pages?: string[];
17
+ plugins?: Record<string, {
18
+ version?: string;
19
+ provider?: string;
20
+ }>;
21
+ }
22
+ export declare function mergeSubPackages(base?: ISubpackage[], extra?: ISubpackage[]): ISubpackage[];
23
+ export {};
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.generateMpConfig = void 0;
25
+ exports.mergeSubPackages = exports.generateMpConfig = void 0;
26
26
  const path = __importStar(require("path"));
27
27
  const lodash_1 = require("lodash");
28
28
  const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
@@ -43,7 +43,8 @@ function generateMpConfig(weapps, ctx) {
43
43
  };
44
44
  const { miniprogramPlugins = [] } = ctx;
45
45
  const projConfig = (0, lodash_1.merge)({}, mp_1.defaultProjConfig, {
46
- projectname: (ctx.mainAppData && ctx.mainAppData.label) || ('WeDa-' + ctx.appId),
46
+ projectname: (ctx.mainAppData && ctx.mainAppData.label) ||
47
+ `WeDa-${ctx.appId}`,
47
48
  });
48
49
  const pageConfigs = weapps.map((app) => {
49
50
  var _a;
@@ -80,7 +81,9 @@ function generateMpConfig(weapps, ctx) {
80
81
  projConfig.packOptions.ignore.push(...matertialMetaIgnores);
81
82
  const { tradingCapability, ...mainAppConfig } = weapps[0].appConfig || {};
82
83
  // keep main app config only, ignore subapp config
83
- (0, lodash_1.merge)(appConfig, mainAppConfig, extractPages(weapps, pageConfigs));
84
+ const { subpackages, ...extra } = extractPages(weapps, pageConfigs);
85
+ (0, lodash_1.merge)(appConfig, mainAppConfig, extra);
86
+ appConfig.subpackages = mergeSubPackages(appConfig.subpackages, subpackages);
84
87
  if (tradingCapability) {
85
88
  const tradePluginKey = `weda-mini-shop-plugin`;
86
89
  const pluginMeta = {
@@ -179,10 +182,29 @@ function parseTabConfig(tabBar, projDir) {
179
182
  console.error(chalk_1.default.red('App.json invalid tabbar icon path'), iconUrl);
180
183
  return;
181
184
  }
182
- const iconPath = 'assets/tab' + index + '/' + filename + path.extname(iconUrl);
183
- (0, net_1.downloadFile)(iconUrl, projDir + '/' + iconPath).catch((e) => {
185
+ const iconPath = `assets/tab${index}/${filename}${path.extname(iconUrl)}`;
186
+ (0, net_1.downloadFile)(iconUrl, `${projDir}/${iconPath}`).catch((e) => {
184
187
  console.error(chalk_1.default.red(`Fail to download tabBar icon from ${iconUrl}`), e);
185
188
  });
186
189
  return iconPath;
187
190
  }
188
191
  }
192
+ function mergeSubPackages(base = [], extra = []) {
193
+ const baseMap = base.reduce((map, item) => {
194
+ map[item.root] = item;
195
+ return map;
196
+ }, {});
197
+ for (const subpackage of extra) {
198
+ if (!baseMap[subpackage.root]) {
199
+ base.push(subpackage);
200
+ continue;
201
+ }
202
+ const current = baseMap[subpackage.root];
203
+ current.pages = Array.from(new Set([...(current.pages || []), ...(subpackage.pages || [])]));
204
+ if (current.plugins || subpackage.plugins) {
205
+ current.plugins = (0, lodash_1.merge)(current.pplugins, subpackage.plugins);
206
+ }
207
+ }
208
+ return base;
209
+ }
210
+ exports.mergeSubPackages = mergeSubPackages;
@@ -161,7 +161,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
161
161
  node.attributes['wx:key'] = 'id';
162
162
  }
163
163
  const compSchema = componentProto.dataForm;
164
- for (const prop of Object.keys(data)) {
164
+ for (const prop of Object.keys(data || {})) {
165
165
  if (compSchema) {
166
166
  const fieldDef = compSchema[prop];
167
167
  if (!fieldDef && !isGlobalAttr(prop)) {
@@ -245,7 +245,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
245
245
  componentKey === 'gsd-h5-react:Swiper') {
246
246
  node.elements = node.elements.map((item, index) => {
247
247
  var _a, _b;
248
- let { ['wx:for']: wxFor, ['wx:for-index']: wxForIndex, ['wx:key']: wxKey, ...itemRestKey } = item.attributes || {};
248
+ let { ['wx:for']: wxFor, ['wx:for-index']: wxForIndex, ['wx:key']: wxKey, ['wx:if']: wxIf, ...itemRestKey } = item.attributes || {};
249
249
  if (item.name !== 'swiper-item') {
250
250
  let SwiperItem = {
251
251
  type: 'element',
@@ -255,6 +255,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
255
255
  'wx:for': wxFor,
256
256
  'wx:for-index': wxForIndex,
257
257
  'wx:key': wxKey,
258
+ 'wx:if': wxIf,
258
259
  },
259
260
  elements: [],
260
261
  _order: index || 0,
@@ -32,6 +32,7 @@ exports.mergePages = exports.mergePackageDependiences = exports.mergePackageJson
32
32
  */
33
33
  const fs = __importStar(require("fs-extra"));
34
34
  const lodash_1 = __importDefault(require("lodash"));
35
+ const mp_config_1 = require("../mp/mp_config");
35
36
  // 将后面的子包配置合并到前面
36
37
  // 暂时不考虑 root 会重名的情况
37
38
  async function mergeSubPackages(baseAppJsonPath, mergeAppJsonPath) {
@@ -40,24 +41,7 @@ async function mergeSubPackages(baseAppJsonPath, mergeAppJsonPath) {
40
41
  if (!getSubPackages(mergeJson))
41
42
  return;
42
43
  const newJson = { ...baseJson };
43
- if (!baseJson.subpackages) {
44
- newJson.subpackages = getSubPackages(mergeJson);
45
- }
46
- else {
47
- getSubPackages(mergeJson).forEach((mergeItem) => {
48
- // 找到重复的进行合并再去重
49
- const targetItemIdx = newJson.subpackages.findIndex((item) => {
50
- return item.root === mergeItem.root;
51
- });
52
- if (newJson.subpackages[targetItemIdx]) {
53
- const pages = lodash_1.default.uniq([].concat(newJson.subpackages[targetItemIdx].pages, mergeItem.pages));
54
- newJson.subpackages[targetItemIdx].pages = pages;
55
- }
56
- else {
57
- newJson.subpackages.push(mergeItem);
58
- }
59
- });
60
- }
44
+ newJson.subpackages = (0, mp_config_1.mergeSubPackages)(baseJson.subpackages, mergeJson.subpackages);
61
45
  fs.writeJSONSync(baseAppJsonPath, newJson, { spaces: 2 });
62
46
  // 处理兼容
63
47
  function getSubPackages(json) {