@cloudbase/lowcode-builder 1.8.86 → 1.8.88

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.
@@ -58,12 +58,8 @@ const templateDir = `${config_1.appTemplateDir}/mp/`;
58
58
  const em = chalk_1.default.blue.bold;
59
59
  const error = chalk_1.default.redBright;
60
60
  function patchBuildContext(ctx, calses) {
61
- var _a, _b;
62
61
  const { mainAppData } = ctx;
63
62
  const used = (0, cals_1.getUsedComps)(calses, ctx.materialLibs, { streamline: true, withAction: true });
64
- if ((_a = used.component) === null || _a === void 0 ? void 0 : _a['$template']) {
65
- ctx.materialLibs = [...ctx.materialLibs, (0, cals_1.processTemplatesToDependiencies)((_b = calses === null || calses === void 0 ? void 0 : calses[0]) === null || _b === void 0 ? void 0 : _b.templates)];
66
- }
67
63
  /**
68
64
  * 修改 buildContext 进行 miniprogramPlugins 精简
69
65
  */
@@ -71,7 +67,7 @@ function patchBuildContext(ctx, calses) {
71
67
  return { used: used };
72
68
  }
73
69
  async function generateWxMp({ buildContext: _buildContext, weapps, calses, deployOptions, options, buildTypeList, ignoreInstall = false, cdnEndpoints = {}, mpConfig = {}, }) {
74
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
70
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
75
71
  const operationLabel = em('Wexin MiniProgram Generated');
76
72
  console.time(operationLabel);
77
73
  console.log(`Generating ${em('Wexin MiniProgram')} to ${_buildContext.projDir}`);
@@ -84,10 +80,30 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
84
80
  * 依据所有应用的低码配置生成默认项目json
85
81
  * 次高优先级,生成整个小程序的配置信息
86
82
  */
87
- const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(_buildContext, weapps, calses, {
83
+ const { projConfig, appConfig, pageConfigs } = await (0, mp_config_1.generateMpConfig)(_buildContext, weapps, calses, {
88
84
  mpAppId: options.mpAppId,
89
85
  mpConfig,
90
86
  });
87
+ Object.values((appConfig === null || appConfig === void 0 ? void 0 : appConfig.usingComponents) || {}).forEach((path) => {
88
+ var _a;
89
+ const matched = path.match(new RegExp(`(?:\\.)?(?:\\/)?${config_1.materialsDirName}\\/\\$template\\/(.*)?\\/index`));
90
+ if (matched) {
91
+ const componentName = matched[1];
92
+ if (!((_a = used.component) === null || _a === void 0 ? void 0 : _a['$template'])) {
93
+ used.component['$template'] = new Set();
94
+ }
95
+ used.component['$template'].add(componentName);
96
+ }
97
+ });
98
+ /**
99
+ * 此处逻辑分离自 patchBuildContext
100
+ * 因为 materialLibs 依赖 used 修正,used 依赖 generateMpConfig 后获取 appConfig 修正,generateMpConfig 有依赖 materialLibs 中源码组件库信息进行生成产生了循环
101
+ * 根据当前的逻辑牺牲封装在此继续修正
102
+ */
103
+ if ((_a = used.component) === null || _a === void 0 ? void 0 : _a['$template']) {
104
+ const templateLib = (0, cals_1.processTemplatesToDependiencies)((_b = calses === null || calses === void 0 ? void 0 : calses[0]) === null || _b === void 0 ? void 0 : _b.templates);
105
+ _buildContext.materialLibs = [..._buildContext.materialLibs, templateLib];
106
+ }
91
107
  const { uin = '', appId, projDir, materialLibs: materials, isProduction, mainAppData, domain, isPrivateMode = false, endpointType = '', isBrowserMpBuilder = false, } = _buildContext;
92
108
  const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
93
109
  const hasLowcodePkg = weapps.find((item) => !item.mpPkgUrl);
@@ -132,7 +148,7 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
132
148
  endpointType,
133
149
  }, localWedaRoot);
134
150
  const expirationStartTimesnap = buildContext.enableExpiredTag ? Date.now() : 0;
135
- const cssVarMap = Object.entries((0, theme_1.mergeCssVarConfig)((_b = (_a = calses[0]) === null || _a === void 0 ? void 0 : _a.theme) === null || _b === void 0 ? void 0 : _b.cssVarConfig, 'MP'))
151
+ const cssVarMap = Object.entries((0, theme_1.mergeCssVarConfig)((_d = (_c = calses[0]) === null || _c === void 0 ? void 0 : _c.theme) === null || _d === void 0 ? void 0 : _d.cssVarConfig, 'MP'))
136
152
  .map(([key, _value]) => {
137
153
  const value = _value || '';
138
154
  return [key, value.replace(/;$/, '')];
@@ -142,8 +158,8 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
142
158
  return map;
143
159
  }, {}) || {};
144
160
  let customLoginConfig;
145
- let loginConfigPathname = ((_d = (_c = calses[0]) === null || _c === void 0 ? void 0 : _c.extra) === null || _d === void 0 ? void 0 : _d.loginConfigVersion)
146
- ? (0, cals_1.generateCustomLoginConfigPathname)({ appId, version: (_f = (_e = calses[0]) === null || _e === void 0 ? void 0 : _e.extra) === null || _f === void 0 ? void 0 : _f.loginConfigVersion })
161
+ let loginConfigPathname = ((_f = (_e = calses[0]) === null || _e === void 0 ? void 0 : _e.extra) === null || _f === void 0 ? void 0 : _f.loginConfigVersion)
162
+ ? (0, cals_1.generateCustomLoginConfigPathname)({ appId, version: (_h = (_g = calses[0]) === null || _g === void 0 ? void 0 : _g.extra) === null || _h === void 0 ? void 0 : _h.loginConfigVersion })
147
163
  : '';
148
164
  if (loginConfigPathname) {
149
165
  const url = `https://${domain}${loginConfigPathname}`;
@@ -165,8 +181,8 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
165
181
  expirationStartTimesnap,
166
182
  runtimeDynamicConfig: buildContext.runtimeDynamicConfig,
167
183
  RUNTIME_CONFIG_URL: index_1.RUNTIME_CONFIG_URL,
168
- loginConfigPathname: ((_h = (_g = calses[0]) === null || _g === void 0 ? void 0 : _g.extra) === null || _h === void 0 ? void 0 : _h.loginConfigVersion)
169
- ? (0, cals_1.generateCustomLoginConfigPathname)({ appId, version: (_k = (_j = calses[0]) === null || _j === void 0 ? void 0 : _j.extra) === null || _k === void 0 ? void 0 : _k.loginConfigVersion })
184
+ loginConfigPathname: ((_k = (_j = calses[0]) === null || _j === void 0 ? void 0 : _j.extra) === null || _k === void 0 ? void 0 : _k.loginConfigVersion)
185
+ ? (0, cals_1.generateCustomLoginConfigPathname)({ appId, version: (_m = (_l = calses[0]) === null || _l === void 0 ? void 0 : _l.extra) === null || _m === void 0 ? void 0 : _m.loginConfigVersion })
170
186
  : '',
171
187
  customLoginConfig: customLoginConfig ? JSON.stringify(customLoginConfig, undefined, 2) : 'null',
172
188
  },
@@ -220,9 +236,9 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
220
236
  appID: appId,
221
237
  resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
222
238
  isProd: (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.UPLOAD,
223
- clientID: ((_l = mainAppData.extra) === null || _l === void 0 ? void 0 : _l.enableLoginStatusShare)
239
+ clientID: ((_o = mainAppData.extra) === null || _o === void 0 ? void 0 : _o.enableLoginStatusShare)
224
240
  ? mainAppData.envId
225
- : (_m = mainAppData.extra) === null || _m === void 0 ? void 0 : _m.clientId,
241
+ : (_p = mainAppData.extra) === null || _p === void 0 ? void 0 : _p.clientId,
226
242
  cdnEndpoints,
227
243
  builderVersion: core_1.version || '',
228
244
  officialLibVersion: (officialLib === null || officialLib === void 0 ? void 0 : officialLib.version) || '',
@@ -272,8 +288,8 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
272
288
  projectConfigJson.setting = {
273
289
  ...projectConfigJson.setting,
274
290
  ...projConfig.setting,
275
- packNpmRelationList: ((_o = projConfig.setting) === null || _o === void 0 ? void 0 : _o.packNpmRelationList) || ((_p = projectConfigJson.setting) === null || _p === void 0 ? void 0 : _p.packNpmRelationList)
276
- ? (0, mp_config_1.mergePackNpmRelationList)(projConfig.setting.packNpmRelationList, (_q = projectConfigJson.setting) === null || _q === void 0 ? void 0 : _q.packNpmRelationList)
291
+ packNpmRelationList: ((_q = projConfig.setting) === null || _q === void 0 ? void 0 : _q.packNpmRelationList) || ((_r = projectConfigJson.setting) === null || _r === void 0 ? void 0 : _r.packNpmRelationList)
292
+ ? (0, mp_config_1.mergePackNpmRelationList)(projConfig.setting.packNpmRelationList, (_s = projectConfigJson.setting) === null || _s === void 0 ? void 0 : _s.packNpmRelationList)
277
293
  : undefined,
278
294
  };
279
295
  const wedaRoot = path_1.default.posix.join('./', projectConfigJson.miniprogramRoot || '/', projectConfigJson.wedaRoot || '');
@@ -291,9 +307,9 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
291
307
  let appJsContent = await fs.readFile(appJsPath);
292
308
  await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './${path_1.default.posix.join('./', projectConfigJson.wedaRoot, 'app/weapps-api')}'\n${appJsContent}`);
293
309
  }
294
- let appJsonPath = path_1.default.join(miniprogramRoot, 'app.json');
295
- let appJson = await fs.readJson(appJsonPath);
296
- appJson.subpackages = (0, mp_config_1.mergeSubPackages)(appJson.subpackages, appConfig.subpackages);
310
+ const appJsonPath = path_1.default.join(miniprogramRoot, 'app.json');
311
+ const appJson = await fs.readJson(appJsonPath);
312
+ appJson.subpackages = (0, mp_config_1.mergeSubPackages)(((_u = (_t = appJson.subpackages) === null || _t === void 0 ? void 0 : _t.filter) === null || _u === void 0 ? void 0 : _u.call(_t, (item) => item.name !== 'wd-sys-module' && item.name !== 'wd-sys-materials')) || [], appConfig.subpackages);
297
313
  await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
298
314
  }
299
315
  else {
@@ -11,11 +11,11 @@ import { IPlatformApp } from '@cloudbase/cals';
11
11
  export declare function generateMpConfig(ctx: Omit<IBuildContext, 'wedaRoot'>, weapps: IWeAppData[], calses: IPlatformApp[], options: {
12
12
  mpAppId?: string;
13
13
  mpConfig?: IBuildWedaApp['mpConfig'];
14
- }): {
14
+ }): Promise<{
15
15
  appConfig: any;
16
16
  projConfig: any;
17
17
  pageConfigs: {}[];
18
- };
18
+ }>;
19
19
  interface ISubpackage {
20
20
  root: string;
21
21
  pages?: string[];
@@ -41,8 +41,8 @@ const util_1 = require("../util");
41
41
  * @param kboneConfig https://wechat-miniprogram.github.io/kbone/docs/config/
42
42
  * @param appConfigs app config from prop edit panel
43
43
  */
44
- function generateMpConfig(ctx, weapps, calses, options) {
45
- var _a, _b, _c, _d, _e;
44
+ async function generateMpConfig(ctx, weapps, calses, options) {
45
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
46
46
  const appConfig = {
47
47
  useExtendedLib: { weui: true },
48
48
  };
@@ -84,10 +84,6 @@ function generateMpConfig(ctx, weapps, calses, options) {
84
84
  const { projectConfigJson = {}, appJson = {} } = config;
85
85
  // # project.config.json, https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html
86
86
  (0, lodash_1.merge)(projConfig, projectConfigJson);
87
- // # app.json, https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html
88
- if (appJson.tabBar) {
89
- parseTabConfig(appJson.tabBar, ctx.projDir);
90
- }
91
87
  (0, lodash_1.merge)(appConfig, appJson);
92
88
  }
93
89
  });
@@ -95,6 +91,10 @@ function generateMpConfig(ctx, weapps, calses, options) {
95
91
  if (projConfig.wedaRoot) {
96
92
  projConfig.wedaRoot = (0, util_1.normalizeWedaRoot)(projConfig.wedaRoot);
97
93
  }
94
+ // # app.json, https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html
95
+ if (appConfig.tabBar) {
96
+ await parseTabConfig(appConfig.tabBar, path.posix.join(ctx.projDir, projConfig.miniprogramRoot || ''), path.posix.join('./', projConfig.wedaRoot || ''));
97
+ }
98
98
  /**
99
99
  * 基础配置合并完成
100
100
  * 开启特殊合并合并/覆盖逻辑
@@ -104,7 +104,7 @@ function generateMpConfig(ctx, weapps, calses, options) {
104
104
  .reduce((arr, lib) => {
105
105
  arr.push({
106
106
  type: 'file',
107
- value: path.posix.join(projConfig.wedaRoot || '', `materials/${lib.name}/meta.json`),
107
+ value: path.posix.join(projConfig.wedaRoot || '', `${config_1.materialsDirName}/${lib.name}/meta.json`),
108
108
  });
109
109
  return arr;
110
110
  }, []));
@@ -113,11 +113,11 @@ function generateMpConfig(ctx, weapps, calses, options) {
113
113
  */
114
114
  const { subpackages, pages = [] } = extractPages(weapps, pageConfigs, { wedaRoot: projConfig.wedaRoot });
115
115
  appConfig.pages = Array.from(new Set([...(appConfig.pages || []), ...pages]));
116
- appConfig.subpackages = mergeSubPackages(appConfig.subpackages, [
116
+ appConfig.subpackages = mergeSubPackages(((_e = (_d = appConfig.subpackages) === null || _d === void 0 ? void 0 : _d.filter) === null || _e === void 0 ? void 0 : _e.call(_d, (item) => item.name !== 'wd-sys-module' && item.name !== 'wd-sys-materials')) || [], [
117
117
  {
118
118
  root: path.posix.join(projConfig.wedaRoot || '', 'packages/$wd_system'),
119
119
  name: 'wd-sys-module',
120
- pages: ((_e = (_d = calses === null || calses === void 0 ? void 0 : calses[0]) === null || _d === void 0 ? void 0 : _d.extra) === null || _e === void 0 ? void 0 : _e.loginConfigVersion) ? ['pages/login/index'] : [],
120
+ pages: ((_g = (_f = calses === null || calses === void 0 ? void 0 : calses[0]) === null || _f === void 0 ? void 0 : _f.extra) === null || _g === void 0 ? void 0 : _g.loginConfigVersion) ? ['pages/login/index'] : [],
121
121
  },
122
122
  ]
123
123
  .concat(ctx.enableAsyncMaterials
@@ -171,9 +171,9 @@ function generateMpConfig(ctx, weapps, calses, options) {
171
171
  if (!projConfig.setting.packNpmRelationList) {
172
172
  projConfig.setting.packNpmRelationList = [];
173
173
  }
174
- projConfig.setting.packNpmRelationList = mergePackNpmRelationList(generateSystemPackNpmRelationList(path.posix.join('./', projConfig.miniprogramRoot || '/', projConfig.wedaRoot || '')), projConfig.setting.packNpmRelationList.filter((item) => {
174
+ projConfig.setting.packNpmRelationList = mergePackNpmRelationList(generateSystemPackNpmRelationList(path.posix.join('./', projConfig.miniprogramRoot || '/', projConfig.wedaRoot || '')), ((_j = (_h = projConfig.setting.packNpmRelationList) === null || _h === void 0 ? void 0 : _h.filter) === null || _j === void 0 ? void 0 : _j.call(_h, (item) => {
175
175
  return !/\/packages\/\$wd_system\/package.json/.test(item.packageJsonPath);
176
- }));
176
+ })) || []);
177
177
  if (process.env.IS_WEB_WORKER) {
178
178
  projConfig.setting.ignoreUploadUnusedFiles = true;
179
179
  }
@@ -214,7 +214,7 @@ function extractPages(weapps, pageConfigs, options) {
214
214
  }
215
215
  return { pages, subpackages };
216
216
  }
217
- function getAppPagesConfig(pages) {
217
+ function getAppPagesConfig(pages = []) {
218
218
  const pagesConfig = {};
219
219
  pages.map((page) => {
220
220
  const pageConfig = transformDynamicData(page.data);
@@ -233,27 +233,35 @@ function transformDynamicData(originData) {
233
233
  }
234
234
  return temp;
235
235
  }
236
- function parseTabConfig(tabBar, projDir) {
237
- tabBar.list.map((tab, index) => {
238
- const { iconPath, selectedIconPath } = tab;
239
- if (iconPath) {
240
- tab.iconPath = parseTabIcon(iconPath, index, 'icon');
241
- }
242
- if (selectedIconPath) {
243
- tab.selectedIconPath = parseTabIcon(selectedIconPath, index, 'selectedIcon');
244
- }
245
- });
246
- function parseTabIcon(iconUrl, index, filename) {
236
+ function parseTabConfig(tabBar, miniprogramRoot, wedaRoot) {
237
+ var _a, _b;
238
+ async function parseTabIcon(iconUrl, index, filename) {
247
239
  if (typeof iconUrl !== 'string') {
248
240
  console.error(chalk_1.default.red('App.json invalid tabbar icon path'), iconUrl);
249
241
  return;
250
242
  }
251
- const iconPath = `assets/tab${index}/${filename}${path.extname(iconUrl)}`;
252
- (0, net_1.downloadFile)(iconUrl, `${projDir}/${iconPath}`).catch((e) => {
243
+ const iconPath = path.posix.join('./', wedaRoot || '/', `assets/tab${index}/${filename}${path.extname(iconUrl)}`);
244
+ await (0, net_1.downloadFile)(iconUrl, `${miniprogramRoot}/${iconPath}`).catch((e) => {
253
245
  console.error(chalk_1.default.red(`Fail to download tabBar icon from ${iconUrl}`), e);
246
+ throw e;
254
247
  });
255
248
  return iconPath;
256
249
  }
250
+ return Promise.all(((_b = (_a = tabBar.list) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, async (tab, index) => {
251
+ const { iconPath, selectedIconPath } = tab;
252
+ if (iconPath && /^http(s):\/\//.test(iconPath)) {
253
+ try {
254
+ tab.iconPath = await parseTabIcon(iconPath, index, 'icon');
255
+ }
256
+ catch (e) { }
257
+ }
258
+ if (selectedIconPath && /^http(s):\/\//.test(selectedIconPath)) {
259
+ try {
260
+ tab.selectedIconPath = await parseTabIcon(selectedIconPath, index, 'selectedIcon');
261
+ }
262
+ catch (e) { }
263
+ }
264
+ })) || []);
257
265
  }
258
266
  function mergeSubPackages(base = [], extra = []) {
259
267
  const baseMap = base.reduce((map, item) => {
@@ -36,9 +36,12 @@ const config_1 = require("../config");
36
36
  const generateFiles_1 = require("../util/generateFiles");
37
37
  const junk_1 = require("../util/junk");
38
38
  async function downloadFile(url, filePath) {
39
+ if (fs_extra_1.default.existsSync(filePath)) {
40
+ return;
41
+ }
39
42
  await fs_extra_1.default.ensureDir(path.dirname(filePath));
40
- const res = await axios_1.default.get(url, { responseType: 'stream' });
41
- res.data.pipe(fs_extra_1.default.createWriteStream(filePath));
43
+ const res = await axios_1.default.get(url, { responseType: 'arraybuffer' });
44
+ fs_extra_1.default.writeFileSync(filePath, res.data);
42
45
  }
43
46
  exports.downloadFile = downloadFile;
44
47
  /**