@cloudbase/lowcode-builder 0.1.14 → 0.1.15

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,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -46,9 +50,8 @@ const types_1 = require("../../types");
46
50
  const common_1 = require("../types/common");
47
51
  const lodash_1 = require("lodash");
48
52
  const junk = __importStar(require("../util/junk"));
49
- const path_2 = __importDefault(require("path"));
50
53
  const net_1 = require("../util/net");
51
- const templateDir = config_1.appTemplateDir + '/mp/';
54
+ const templateDir = `${config_1.appTemplateDir}/mp/`;
52
55
  const em = chalk_1.default.blue.bold;
53
56
  const error = chalk_1.default.redBright;
54
57
  async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, extraData, isMixMode, options, buildTypeList, isBrowserMpBuilder = false, }) {
@@ -85,7 +88,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
85
88
  const projectFileData = {
86
89
  'project.config.json': { content: projConfig },
87
90
  };
88
- console.log('Generating ' + em('project') + ' files');
91
+ console.log(`Generating ${em('project')} files`);
89
92
  await (0, generateFiles_1.default)(projectFileData, templateDir, projDir, buildContext);
90
93
  }
91
94
  // #2 生成主包
@@ -143,17 +146,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
143
146
  await (0, generateFiles_1.writeFile)(projectConfigJsonPath, JSON.stringify(projectConfigJson, undefined, 2));
144
147
  let appJsonPath = path_1.default.join(miniprogramRoot, 'app.json');
145
148
  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;
149
+ appJson.subpackages = (0, mp_config_1.mergeSubPackages)(appJson.subpackages, appConfig.subpackages);
157
150
  await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
158
151
  }
159
152
  else {
@@ -328,7 +321,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
328
321
  dataBinds: (0, util_2.createDataBinds)(page.componentInstances, ctx),
329
322
  debug: ctx.debugMode,
330
323
  stringifyObj: util_1.inspect,
331
- subLevelPath: rootPath ? path_2.default.relative(rootPath, '') + '/' : '',
324
+ subLevelPath: rootPath ? path_1.default.relative(rootPath, '') + '/' : '',
332
325
  },
333
326
  [`index.json|${pageFileName}.json`]: {
334
327
  usingComponents,
@@ -341,7 +334,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
341
334
  },
342
335
  [`index.wxss|${pageFileName}.wxss`]: {
343
336
  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";`
337
+ ? `@import "${path_1.default.relative(`/${rootPath}/pages/${page.id}`, '/lowcode')}/style.wxss";`
345
338
  : '',
346
339
  content: (0, weapps_core_1.toCssText)((0, weapps_core_1.toCssStyle)(page.commonStyle, {
347
340
  toRem: false,
@@ -426,14 +419,17 @@ async function generateFramework(appData, outDir, ctx) {
426
419
  await (0, generateFiles_1.default)(fileData, templateDir, outDir, ctx);
427
420
  }
428
421
  async function writeLowCodeFiles(appData, outDir, ctx) {
429
- console.log('Writing ' + em('lowcode') + ' files:');
422
+ console.log(`Writing ${em('lowcode')} files:`);
430
423
  const lowcodeRootDir = path_1.default.join(outDir, 'lowcode');
431
424
  const themeStyle = (0, style_1.generateDefaultTheme)(appData);
432
425
  // 混合模式,子包不生成顶级(应用级)的 lowcodes
433
426
  if (!(ctx.isMixMode && appData.rootPath)) {
434
427
  await Promise.all(appData.lowCodes
435
428
  .filter((mod) => mod.name !== '____index____')
436
- .map((m) => (0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { appDir: outDir }, themeStyle.code)));
429
+ .filter((mod) => mod.type !== 'renderer')
430
+ .map((m) => {
431
+ (0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { appDir: outDir }, themeStyle.code);
432
+ }));
437
433
  }
438
434
  await Promise.all((0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList, async (page) => {
439
435
  var _a;
@@ -447,7 +443,9 @@ async function writeLowCodeFiles(appData, outDir, ctx) {
447
443
  path: 'xx/index',
448
444
  });
449
445
  }
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)));
446
+ 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) => {
447
+ (0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { pageId: page.id, appDir: outDir }, themeStyle.code, ctx);
448
+ }));
451
449
  }));
452
450
  }
453
451
  exports.writeLowCodeFiles = writeLowCodeFiles;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -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 {};
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -22,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
27
  };
24
28
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.generateMpConfig = void 0;
29
+ exports.mergeSubPackages = exports.generateMpConfig = void 0;
26
30
  const path = __importStar(require("path"));
27
31
  const lodash_1 = require("lodash");
28
32
  const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
@@ -43,7 +47,8 @@ function generateMpConfig(weapps, ctx) {
43
47
  };
44
48
  const { miniprogramPlugins = [] } = ctx;
45
49
  const projConfig = (0, lodash_1.merge)({}, mp_1.defaultProjConfig, {
46
- projectname: (ctx.mainAppData && ctx.mainAppData.label) || ('WeDa-' + ctx.appId),
50
+ projectname: (ctx.mainAppData && ctx.mainAppData.label) ||
51
+ `WeDa-${ctx.appId}`,
47
52
  });
48
53
  const pageConfigs = weapps.map((app) => {
49
54
  var _a;
@@ -80,7 +85,9 @@ function generateMpConfig(weapps, ctx) {
80
85
  projConfig.packOptions.ignore.push(...matertialMetaIgnores);
81
86
  const { tradingCapability, ...mainAppConfig } = weapps[0].appConfig || {};
82
87
  // keep main app config only, ignore subapp config
83
- (0, lodash_1.merge)(appConfig, mainAppConfig, extractPages(weapps, pageConfigs));
88
+ const { subpackages, ...extra } = extractPages(weapps, pageConfigs);
89
+ (0, lodash_1.merge)(appConfig, mainAppConfig, extra);
90
+ appConfig.subpackages = mergeSubPackages(appConfig.subpackages, subpackages);
84
91
  if (tradingCapability) {
85
92
  const tradePluginKey = `weda-mini-shop-plugin`;
86
93
  const pluginMeta = {
@@ -102,8 +109,8 @@ function generateMpConfig(weapps, ctx) {
102
109
  appConfig.plugins = plugins;
103
110
  }
104
111
  miniprogramPlugins.forEach((plugin) => {
105
- var _a, _b;
106
- if (!((_b = (_a = appConfig) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b[plugin.name])) {
112
+ var _a;
113
+ if (!((_a = appConfig === null || appConfig === void 0 ? void 0 : appConfig.plugins) === null || _a === void 0 ? void 0 : _a[plugin.name])) {
107
114
  (0, lodash_1.set)(appConfig, `plugins.${plugin.name}`, {
108
115
  version: plugin.version,
109
116
  provider: plugin.pluginAppId,
@@ -179,10 +186,29 @@ function parseTabConfig(tabBar, projDir) {
179
186
  console.error(chalk_1.default.red('App.json invalid tabbar icon path'), iconUrl);
180
187
  return;
181
188
  }
182
- const iconPath = 'assets/tab' + index + '/' + filename + path.extname(iconUrl);
183
- (0, net_1.downloadFile)(iconUrl, projDir + '/' + iconPath).catch((e) => {
189
+ const iconPath = `assets/tab${index}/${filename}${path.extname(iconUrl)}`;
190
+ (0, net_1.downloadFile)(iconUrl, `${projDir}/${iconPath}`).catch((e) => {
184
191
  console.error(chalk_1.default.red(`Fail to download tabBar icon from ${iconUrl}`), e);
185
192
  });
186
193
  return iconPath;
187
194
  }
188
195
  }
196
+ function mergeSubPackages(base = [], extra = []) {
197
+ const baseMap = base.reduce((map, item) => {
198
+ map[item.root] = item;
199
+ return map;
200
+ }, {});
201
+ for (const subpackage of extra) {
202
+ if (!baseMap[subpackage.root]) {
203
+ base.push(subpackage);
204
+ continue;
205
+ }
206
+ const current = baseMap[subpackage.root];
207
+ current.pages = Array.from(new Set([...(current.pages || []), ...(subpackage.pages || [])]));
208
+ if (current.plugins || subpackage.plugins) {
209
+ current.plugins = (0, lodash_1.merge)(current.pplugins, subpackage.plugins);
210
+ }
211
+ }
212
+ return base;
213
+ }
214
+ exports.mergeSubPackages = mergeSubPackages;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -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,
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -32,6 +36,7 @@ exports.mergePages = exports.mergePackageDependiences = exports.mergePackageJson
32
36
  */
33
37
  const fs = __importStar(require("fs-extra"));
34
38
  const lodash_1 = __importDefault(require("lodash"));
39
+ const mp_config_1 = require("../mp/mp_config");
35
40
  // 将后面的子包配置合并到前面
36
41
  // 暂时不考虑 root 会重名的情况
37
42
  async function mergeSubPackages(baseAppJsonPath, mergeAppJsonPath) {
@@ -40,24 +45,7 @@ async function mergeSubPackages(baseAppJsonPath, mergeAppJsonPath) {
40
45
  if (!getSubPackages(mergeJson))
41
46
  return;
42
47
  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
- }
48
+ newJson.subpackages = (0, mp_config_1.mergeSubPackages)(baseJson.subpackages, mergeJson.subpackages);
61
49
  fs.writeJSONSync(baseAppJsonPath, newJson, { spaces: 2 });
62
50
  // 处理兼容
63
51
  function getSubPackages(json) {
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { ChildProcess } from 'child_process';
3
4
  interface IProcessOptions {
4
5
  onStdout?: (data: Buffer) => any;