@cloudbase/lowcode-builder 1.8.71 → 1.8.72

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.
@@ -14,6 +14,9 @@ interface IBaseAppProps {
14
14
  generateMpType?: GenerateMpType;
15
15
  plugins?: IPlugin[];
16
16
  domain: string;
17
+ /**
18
+ * @deprecated
19
+ */
17
20
  extraData?: IExtraData;
18
21
  }
19
22
  export interface BuildAppProps extends IBaseAppProps {
@@ -44,6 +47,10 @@ export interface IBuildWedaApp extends IBaseAppProps {
44
47
  account?: {
45
48
  uin?: string;
46
49
  };
50
+ mpConfig?: {
51
+ appJson?: Record<string, any>;
52
+ projectConfigJson?: Record<string, any>;
53
+ };
47
54
  }
48
55
  export declare function buildWedaConfig({ output, domain, isPrivateMode, endpointType, buildTypeList, }: {
49
56
  output: Required<IBuildWedaApp['output']>;
@@ -52,7 +59,7 @@ export declare function buildWedaConfig({ output, domain, isPrivateMode, endpoin
52
59
  endpointType?: IBuildWedaApp['endpointType'];
53
60
  buildTypeList?: IBuildWedaApp['buildTypeList'];
54
61
  }): Promise<void>;
55
- export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKey, runtime, ignoreInstall, buildTypeList, mode, devTool, deployOptions, generateMpType, plugins, extraData, resourceAppId, domain, output, isBrowserMpBuilder, cdnEndpoints, isPrivateMode, endpointType, enableExpiredTag, account, }: IBuildWedaApp, cb?: WebpackBuildCallBack): Promise<any>;
62
+ export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKey, runtime, ignoreInstall, buildTypeList, mode, devTool, deployOptions, generateMpType, plugins, extraData, resourceAppId, domain, output, isBrowserMpBuilder, cdnEndpoints, isPrivateMode, endpointType, enableExpiredTag, account, mpConfig, }: IBuildWedaApp, cb?: WebpackBuildCallBack): Promise<any>;
56
63
  export declare function cleanComponentDir(): Promise<void>;
57
64
  export declare const version: any;
58
65
  export { getFiles, fileToZip, strToBuf } from '../util/generateFiles';
@@ -61,7 +61,7 @@ exports.buildWedaConfig = buildWedaConfig;
61
61
  async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appKey = 'test', runtime = types_1.RUNTIME.NONE, ignoreInstall = false, buildTypeList = [common_1.BuildType.WEB], mode = common_1.WebpackModeType.PRODUCTION, devTool = 'webpack', deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW }, generateMpType = common_1.GenerateMpType.APP, plugins = [], extraData = {
62
62
  isComposite: false,
63
63
  compProps: {},
64
- }, resourceAppId = undefined, domain = '', output, isBrowserMpBuilder = false, cdnEndpoints, isPrivateMode = false, endpointType = undefined, enableExpiredTag = false, account = {}, }, cb) {
64
+ }, resourceAppId = undefined, domain = '', output, isBrowserMpBuilder = false, cdnEndpoints, isPrivateMode = false, endpointType = undefined, enableExpiredTag = false, account = {}, mpConfig = {}, }, cb) {
65
65
  var _a, _b, _c, _d, _e, _f;
66
66
  if (!cals) {
67
67
  console.error('无效的应用配置');
@@ -94,7 +94,7 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
94
94
  isProduction: mode === common_1.WebpackModeType.PRODUCTION,
95
95
  materialLibs: dependencies,
96
96
  debugMode: mode !== common_1.WebpackModeType.PRODUCTION && !!process.env.WEAPPS_DEBUG,
97
- isMixMode: generateMpType === common_1.GenerateMpType.SUBPACKAGE,
97
+ isMixMode: !!(subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.length),
98
98
  domain,
99
99
  isBrowserMpBuilder,
100
100
  isPrivateMode,
@@ -106,7 +106,7 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
106
106
  };
107
107
  console.log('domain', domain);
108
108
  console.log('应用名', appKey);
109
- console.log('生成模式', generateMpType);
109
+ console.log('生成模式', buildContext.isMixMode ? common_1.GenerateMpType.SUBPACKAGE : common_1.GenerateMpType.APP);
110
110
  console.log('生成路径', appBuildDir);
111
111
  try {
112
112
  const startTime = Date.now();
@@ -180,6 +180,7 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
180
180
  buildTypeList,
181
181
  ignoreInstall,
182
182
  cdnEndpoints: (0, config_1.generateCdnEndpoints)(cdnEndpoints),
183
+ mpConfig,
183
184
  });
184
185
  // 如果是混合模式,则将特定的目录复制到工程下
185
186
  // 针对 app.json / package.json 则采用 merge 的操作
@@ -4,7 +4,7 @@ import { IBuildContext } from './BuildContext';
4
4
  import { BuildType } from '../types/common';
5
5
  import { IPlatformApp } from '@cloudbase/cals';
6
6
  import { IBuildWedaApp } from '../core';
7
- export declare function generateWxMp({ buildContext, weapps, calses, plugins, deployOptions, options, buildTypeList, ignoreInstall, cdnEndpoints, }: {
7
+ export declare function generateWxMp({ buildContext, weapps, calses, plugins, deployOptions, options, buildTypeList, ignoreInstall, cdnEndpoints, mpConfig, }: {
8
8
  buildContext: IBuildContext;
9
9
  weapps: IWeAppData[];
10
10
  calses: IPlatformApp[];
@@ -18,6 +18,7 @@ export declare function generateWxMp({ buildContext, weapps, calses, plugins, de
18
18
  buildTypeList: BuildType[];
19
19
  ignoreInstall: boolean;
20
20
  cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
21
+ mpConfig?: IBuildWedaApp['mpConfig'];
21
22
  }): Promise<{
22
23
  miniprogramRoot: string;
23
24
  }>;
@@ -70,7 +70,7 @@ function patchBuildContext(ctx, calses) {
70
70
  ctx.miniprogramPlugins = (mainAppData.miniprogramPlugins || []).filter((plugin) => used.component[plugin.name] || used.action[plugin.name]);
71
71
  return { used: used };
72
72
  }
73
- async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptions, options, buildTypeList, ignoreInstall = false, cdnEndpoints = {}, }) {
73
+ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptions, options, buildTypeList, ignoreInstall = false, cdnEndpoints = {}, mpConfig = {}, }) {
74
74
  var _a, _b, _c, _d;
75
75
  const operationLabel = em('Wexin MiniProgram Generated');
76
76
  console.time(operationLabel);
@@ -84,7 +84,10 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
84
84
  // 安装依赖库,生成 materials 目录
85
85
  await (0, materials_1.installMaterials)(buildContext, projDir, used, weapps);
86
86
  const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
87
- const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(buildContext, weapps, { mpAppId: options.mpAppId });
87
+ const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(buildContext, weapps, {
88
+ mpAppId: options.mpAppId,
89
+ mpConfig,
90
+ });
88
91
  const hasLowcodePkg = weapps.find((item) => !item.mpPkgUrl);
89
92
  // #1 generate project files
90
93
  if (!mainAppData.mpPkgUrl) {
@@ -1,5 +1,6 @@
1
1
  import { IWeAppData } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  import { IBuildContext } from './BuildContext';
3
+ import { IBuildWedaApp } from '../core';
3
4
  /**
4
5
  * generate app.json & page.json for mp
5
6
  *
@@ -8,6 +9,7 @@ import { IBuildContext } from './BuildContext';
8
9
  */
9
10
  export declare function generateMpConfig(ctx: IBuildContext, weapps: IWeAppData[], options: {
10
11
  mpAppId?: string;
12
+ mpConfig?: IBuildWedaApp['mpConfig'];
11
13
  }): {
12
14
  appConfig: any;
13
15
  projConfig: any;
@@ -64,29 +64,40 @@ function generateMpConfig(ctx, weapps, options) {
64
64
  return pageConfig;
65
65
  });
66
66
  const kbConfig = (_a = weapps[0].lowCodes) === null || _a === void 0 ? void 0 : _a.find((m) => m.name === config_1.MP_CONFIG_MODULE_NAME);
67
- if (kbConfig) {
68
- const { projectConfigJson = {}, appJson = {} } = eval(`(${kbConfig.code.replace(/export\s+default/, '')})`);
69
- // # project.config.json, https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html
70
- (0, lodash_1.merge)(projConfig, projectConfigJson);
71
- // # app.json, https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html
72
- if (appJson.tabBar) {
73
- parseTabConfig(appJson.tabBar, ctx.projDir);
67
+ const { tradingCapability, ...mainAppConfig } = weapps[0].appConfig || {};
68
+ // keep main app config only, ignore subapp config
69
+ const { subpackages, ...extra } = extractPages(weapps, pageConfigs);
70
+ const configs = (kbConfig ? [eval(`(${kbConfig.code.replace(/export\s+default/, '')})`)] : []).concat([
71
+ { appJson: (0, lodash_1.merge)({}, mainAppConfig, extra) },
72
+ options.mpConfig,
73
+ ]);
74
+ configs.forEach((config) => {
75
+ if (config) {
76
+ const { projectConfigJson = {}, appJson = {} } = config;
77
+ // # project.config.json, https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html
78
+ (0, lodash_1.merge)(projConfig, projectConfigJson);
79
+ // # app.json, https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html
80
+ if (appJson.tabBar) {
81
+ parseTabConfig(appJson.tabBar, ctx.projDir);
82
+ }
83
+ (0, lodash_1.merge)(appConfig, appJson);
84
+ // # page.json
85
+ // merge(pageConfigs, pagesConfigJson)
74
86
  }
75
- (0, lodash_1.merge)(appConfig, appJson);
76
- // # page.json
77
- // merge(pageConfigs, pagesConfigJson)
78
- }
79
- const matertialMetaIgnores = ctx.materialLibs
87
+ });
88
+ /**
89
+ * 基础配置合并完成
90
+ * 开启特殊合并合并/覆盖逻辑
91
+ */
92
+ projConfig.packOptions.ignore.push(...ctx.materialLibs
80
93
  .filter((lib) => !lib.isComposite)
81
94
  .reduce((arr, lib) => {
82
95
  arr.push({ type: 'file', value: `materials/${lib.name}/meta.json` });
83
96
  return arr;
84
- }, []);
85
- projConfig.packOptions.ignore.push(...matertialMetaIgnores);
86
- const { tradingCapability, ...mainAppConfig } = weapps[0].appConfig || {};
87
- // keep main app config only, ignore subapp config
88
- const { subpackages, ...extra } = extractPages(weapps, pageConfigs);
89
- (0, lodash_1.merge)(appConfig, mainAppConfig, extra);
97
+ }, []));
98
+ /**
99
+ * 合并追加系统子包
100
+ */
90
101
  appConfig.subpackages = mergeSubPackages(appConfig.subpackages, [
91
102
  {
92
103
  root: 'packages/$wd_system',
@@ -104,6 +115,9 @@ function generateMpConfig(ctx, weapps, options) {
104
115
  ]
105
116
  : [])
106
117
  .concat(subpackages));
118
+ /**
119
+ * 补全交易插件
120
+ */
107
121
  if (tradingCapability) {
108
122
  const tradePluginKey = `weda-mini-shop-plugin`;
109
123
  const pluginMeta = {
@@ -136,7 +150,7 @@ function generateMpConfig(ctx, weapps, options) {
136
150
  if (!projConfig.setting) {
137
151
  projConfig.setting = {};
138
152
  }
139
- projConfig.setting.compileHotReLoad = false;
153
+ // projConfig.setting.compileHotReLoad = false;
140
154
  projConfig.setting.bigPackageSizeSupport = true;
141
155
  projConfig.setting.packNpmManually = true;
142
156
  projConfig.setting.packNpmRelationList = [
@@ -195,6 +195,16 @@ async function downloadAndInstallDependencies(dependencies = [], materialsDir, i
195
195
  await downloadDependencies(targetDir, srcZipUrl);
196
196
  }
197
197
  }
198
+ // 同步依赖
199
+ // const packageJson = await fs.readJson(
200
+ // path.join(targetDir, 'package.json')
201
+ // );
202
+ // item.dependencies = packageJson.dependencies || {};
203
+ }));
204
+ await Promise.all(dependencies.map(async (item) => {
205
+ const { name, version, srcZipUrl } = item;
206
+ const materialNameVersion = `${name}@${version}`;
207
+ const targetDir = path_1.default.join(materialsDir, materialNameVersion);
198
208
  console.log(`处理${name}@${version}依赖 ...`);
199
209
  await installDependencies(targetDir, {
200
210
  ...installOptions,
@@ -206,11 +216,6 @@ async function downloadAndInstallDependencies(dependencies = [], materialsDir, i
206
216
  downloadUrl: srcZipUrl,
207
217
  },
208
218
  });
209
- // 同步依赖
210
- // const packageJson = await fs.readJson(
211
- // path.join(targetDir, 'package.json')
212
- // );
213
- // item.dependencies = packageJson.dependencies || {};
214
219
  }));
215
220
  }
216
221
  exports.downloadAndInstallDependencies = downloadAndInstallDependencies;