@cloudbase/lowcode-builder 1.8.73 → 1.8.75

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.
Files changed (48) hide show
  1. package/lib/builder/config/index.d.ts +2 -5
  2. package/lib/builder/config/index.js +3 -6
  3. package/lib/builder/core/index.d.ts +2 -1
  4. package/lib/builder/core/index.js +15 -24
  5. package/lib/builder/core/plugin.d.ts +1 -7
  6. package/lib/builder/core/plugin.js +0 -2
  7. package/lib/builder/mp/BuildContext.d.ts +8 -0
  8. package/lib/builder/mp/index.d.ts +2 -2
  9. package/lib/builder/mp/index.js +179 -124
  10. package/lib/builder/mp/materials.d.ts +1 -1
  11. package/lib/builder/mp/materials.js +11 -19
  12. package/lib/builder/mp/mixMode.d.ts +9 -3
  13. package/lib/builder/mp/mixMode.js +70 -137
  14. package/lib/builder/mp/mp_config.d.ts +1 -1
  15. package/lib/builder/mp/mp_config.js +28 -20
  16. package/lib/builder/mp/wxml.js +19 -2
  17. package/lib/builder/service/webpack.js +1 -1
  18. package/lib/builder/util/common.d.ts +1 -0
  19. package/lib/builder/util/common.js +8 -1
  20. package/lib/builder/util/net.d.ts +10 -1
  21. package/lib/builder/util/net.js +47 -8
  22. package/lib/builder.web.js +13 -13
  23. package/package.json +6 -5
  24. package/template/html/index.html.ejs +2 -2
  25. package/template/mp/app/weapps-api.js +19 -1
  26. package/template/mp/app.js +3 -120
  27. package/template/mp/common/info/index.js +5 -4
  28. package/template/mp/common/info/index.wxml +2 -2
  29. package/template/mp/common/privacyModal/index.js +3 -2
  30. package/template/mp/common/util.js +24 -12
  31. package/template/mp/common/weapp-page.js +24 -9
  32. package/template/mp/component/index.wxss +2 -0
  33. package/template/mp/datasources/index.js.tpl +122 -2
  34. package/template/mp/package.json +2 -2
  35. package/template/mp/packages/$wd_system/pages/login/components/input/index.js +40 -0
  36. package/template/mp/packages/$wd_system/pages/login/components/input/index.json +4 -0
  37. package/template/mp/packages/$wd_system/pages/login/components/input/index.wxml +11 -0
  38. package/template/mp/packages/$wd_system/pages/login/index.js +161 -0
  39. package/template/mp/packages/$wd_system/pages/login/index.json +16 -0
  40. package/template/mp/packages/$wd_system/pages/login/index.wxml +60 -0
  41. package/template/mp/packages/$wd_system/pages/login/index.wxss +60 -0
  42. package/template/mp/packages/$wd_system/pages/login/methods/loginByPassword.js +55 -0
  43. package/template/mp/packages/$wd_system/pages/login/methods/loginByWXPhone.js +68 -0
  44. package/template/mp/packages/$wd_system/pages/login/methods/loginSuccessCallBack.js +20 -0
  45. package/template/mp/page/api.js +5 -6
  46. package/template/mp/page/index.js +4 -1
  47. package/template/package.json +6 -5
  48. package/template/webpack/web.dev.js +21 -0
@@ -41,8 +41,6 @@ const util_2 = require("./util");
41
41
  const wxml_1 = require("./wxml");
42
42
  const lowcode_1 = require("./lowcode");
43
43
  const mp_config_1 = require("./mp_config");
44
- const plugin_1 = require("./plugin");
45
- const plugin_2 = require("../core/plugin");
46
44
  const util_3 = require("../util");
47
45
  const lowcode_generator_1 = require("@cloudbase/lowcode-generator");
48
46
  const types_1 = require("../../types");
@@ -54,6 +52,7 @@ const cals_1 = require("@cloudbase/cals");
54
52
  const core_1 = require("../core");
55
53
  const theme_1 = require("../../utils/theme");
56
54
  const index_1 = require("../config/index");
55
+ const mixMode_1 = require("./mixMode");
57
56
  const templateDir = `${config_1.appTemplateDir}/mp/`;
58
57
  const em = chalk_1.default.blue.bold;
59
58
  const error = chalk_1.default.redBright;
@@ -70,24 +69,26 @@ function patchBuildContext(ctx, calses) {
70
69
  ctx.miniprogramPlugins = (mainAppData.miniprogramPlugins || []).filter((plugin) => used.component[plugin.name] || used.action[plugin.name]);
71
70
  return { used: used };
72
71
  }
73
- async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptions, options, buildTypeList, ignoreInstall = false, cdnEndpoints = {}, mpConfig = {}, }) {
72
+ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deployOptions, options, buildTypeList, ignoreInstall = false, cdnEndpoints = {}, mpConfig = {}, }) {
74
73
  var _a, _b, _c, _d;
75
74
  const operationLabel = em('Wexin MiniProgram Generated');
76
75
  console.time(operationLabel);
77
- console.log(`Generating ${em('Wexin MiniProgram')} to ${buildContext.projDir}`);
76
+ console.log(`Generating ${em('Wexin MiniProgram')} to ${_buildContext.projDir}`);
78
77
  /**
79
78
  * 此函数具有副作用,用于补充修正小程序特殊的buildContext
80
79
  * 注意一定在入口进行处理,应当尽可能提前,后续逻辑不应该更新buildContext
81
80
  */
82
- const { used } = patchBuildContext(buildContext, calses);
83
- const { uin = '', appId, projDir, materialLibs: materials, isProduction, mainAppData, domain, isPrivateMode = false, endpointType = '', isBrowserMpBuilder = false, } = buildContext;
84
- // 安装依赖库,生成 materials 目录
85
- await (0, materials_1.installMaterials)(buildContext, projDir, used, weapps);
86
- const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
87
- const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(buildContext, weapps, {
81
+ const { used } = patchBuildContext(_buildContext, calses);
82
+ /**
83
+ * 依据所有应用的低码配置生成默认项目json
84
+ * 次高优先级,生成整个小程序的配置信息
85
+ */
86
+ const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(_buildContext, weapps, {
88
87
  mpAppId: options.mpAppId,
89
88
  mpConfig,
90
89
  });
90
+ const { uin = '', appId, projDir, materialLibs: materials, isProduction, mainAppData, domain, isPrivateMode = false, endpointType = '', isBrowserMpBuilder = false, } = _buildContext;
91
+ const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
91
92
  const hasLowcodePkg = weapps.find((item) => !item.mpPkgUrl);
92
93
  // #1 generate project files
93
94
  if (!mainAppData.mpPkgUrl) {
@@ -97,27 +98,36 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
97
98
  console.log(`Generating ${em('project')} files`);
98
99
  await (0, generateFiles_1.default)(projectFileData, templateDir, projDir);
99
100
  }
100
- // #2 生成主包
101
- await generatePkg({ ...buildContext, rootPath: mainAppData.rootPath }, { cals: calses[0], weapp: mainAppData }, path_1.default.join(projDir, '/'), pageConfigs[0]);
102
- const projectConfigJsonPath = path_1.default.join(projDir, mainAppData.rootPath || '', 'project.config.json');
101
+ else {
102
+ /**
103
+ * 若主包为代码包,则下载了基础项目代码,包涵项目 projectConfigJson
104
+ */
105
+ await generatePkg({ ..._buildContext, rootPath: mainAppData.rootPath }, { cals: calses[0], weapp: mainAppData }, path_1.default.join(projDir, '/'), pageConfigs[0]);
106
+ }
107
+ const projectConfigJsonPath = path_1.default.join(projDir, 'project.config.json');
103
108
  let projectConfigJson = await fs.readJSON(projectConfigJsonPath);
104
109
  const miniprogramRoot = path_1.default.join(projDir, projectConfigJson.miniprogramRoot || '/');
105
- await generateFramework(buildContext, mainAppData, miniprogramRoot, { deployOptions });
106
- // #3 生成主包根路径文件
107
- let appFileData = {};
110
+ const localWedaRoot = path_1.default.join(miniprogramRoot, projectConfigJson.wedaRoot || '/');
111
+ const buildContext = {
112
+ ..._buildContext,
113
+ wedaRoot: (0, util_3.normalizeWedaRoot)(projectConfigJson.wedaRoot),
114
+ };
115
+ // #2 生成主包, 若主包为代码包,则下载了基础项目代码,包涵项目 projectConfigJson
116
+ if (mainAppData.mpPkgUrl) {
117
+ }
118
+ else {
119
+ await generatePkg({ ...buildContext, rootPath: mainAppData.rootPath }, { cals: calses[0], weapp: mainAppData }, localWedaRoot, pageConfigs[0]);
120
+ }
121
+ // #3 生成 wedaRoot 文件
108
122
  if (hasLowcodePkg) {
109
- await generateFramework(buildContext, mainAppData, miniprogramRoot, { deployOptions });
110
- // 有了 framework app 之后,并且是源码的方式,追加 app 引用
111
- if (mainAppData.mpPkgUrl) {
112
- let appJsPath = path_1.default.join(miniprogramRoot, 'app.js');
113
- let appJsContent = await fs.readFile(appJsPath);
114
- await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './app/weapps-api'\n${appJsContent}`);
115
- }
123
+ await generateFramework(buildContext, { cals: calses[0], weapp: mainAppData }, localWedaRoot, { deployOptions });
124
+ // 安装依赖库,生成 materials 目录
125
+ await (0, materials_1.installMaterials)(buildContext, localWedaRoot, used, weapps);
116
126
  await generateConfig({
117
127
  domain,
118
128
  isPrivateMode,
119
129
  endpointType,
120
- }, miniprogramRoot);
130
+ }, localWedaRoot);
121
131
  const expirationStartTimesnap = buildContext.enableExpiredTag ? Date.now() : 0;
122
132
  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'))
123
133
  .map(([key, _value]) => {
@@ -128,8 +138,7 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
128
138
  map[key] = value;
129
139
  return map;
130
140
  }, {}) || {};
131
- appFileData = {
132
- ...appFileData,
141
+ const wedaRootFileData = {
133
142
  'common/style.js': {},
134
143
  'common/util.js': {
135
144
  skipCheckAuth: process.env.SKIP_CHECK_AUTH,
@@ -157,6 +166,7 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
157
166
  'common/query.js': {},
158
167
  'common/flow.js': {},
159
168
  'common/info': {},
169
+ 'common/placeholder': {},
160
170
  /**
161
171
  * 使用微信的 modal
162
172
  * 暂时保留内部实现待之后使用
@@ -167,56 +177,6 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
167
177
  * 调试用
168
178
  */
169
179
  // 'common/behaviors.js': {},
170
- };
171
- if (buildContext.enableAsyncMaterials && !appFileData['common/placeholder']) {
172
- appFileData['common/placeholder'] = {};
173
- }
174
- }
175
- if (mainAppData.mpPkgUrl) {
176
- // 合并 project 和 app json,复写 appId
177
- projectConfigJson.appId = projConfig.appId;
178
- projectConfigJson.setting = {
179
- ...projectConfigJson.setting,
180
- ...projConfig.setting,
181
- };
182
- const projectMpRoot = projectConfigJson.miniprogramRoot || '/';
183
- if (!projectConfigJson.setting.packNpmManually) {
184
- projectConfigJson.setting.packNpmManually = true;
185
- }
186
- if (!projectConfigJson.setting.packNpmRelationList) {
187
- projectConfigJson.setting.packNpmRelationList = [];
188
- }
189
- projectConfigJson.setting.packNpmRelationList = [
190
- ...projectConfigJson.setting.packNpmRelationList.filter((item) => item.packageJsonPath === './package.json' || item.packageJsonPath === './packages/$wd_system/package.json'),
191
- {
192
- packageJsonPath: path_1.default.posix.join(projectMpRoot, 'package.json'),
193
- miniprogramNpmDistDir: projectMpRoot,
194
- },
195
- {
196
- packageJsonPath: path_1.default.posix.join(projectMpRoot, 'packages', '$wd_system', 'package.json'),
197
- miniprogramNpmDistDir: path_1.default.posix.join(projectMpRoot, 'packages', '$wd_system'),
198
- },
199
- ];
200
- await (0, generateFiles_1.writeFile)(projectConfigJsonPath, JSON.stringify(projectConfigJson, undefined, 2));
201
- let appJsonPath = path_1.default.join(miniprogramRoot, 'app.json');
202
- let appJson = await fs.readJson(appJsonPath);
203
- appJson.subpackages = (0, mp_config_1.mergeSubPackages)(appJson.subpackages, appConfig.subpackages);
204
- await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
205
- }
206
- else {
207
- const importor = (0, util_3.generateLowcodeImportor)(mainAppData.lowCodes || []);
208
- appFileData = {
209
- ...appFileData,
210
- 'app.js': { appConfig, importor, materialSubPackagePath: config_1.materialsDirName },
211
- 'app.json': { content: appConfig },
212
- 'app.wxss': {
213
- importStyles: materials
214
- .reduce((styles, lib) => {
215
- styles = styles.concat((lib.styles || []).map((stylePath) => stylePath && !stylePath.startsWith('/') ? `/${config_1.materialsDirName}/${lib.name}/${stylePath}` : stylePath) || []);
216
- return styles;
217
- }, [])
218
- .concat(importor.styles.map((mod) => path_1.default.posix.join('lowcode', (0, weapps_core_1.getCodeModuleFilePath)('global', mod, { style: '.wxss' })))),
219
- },
220
180
  'package.json': {
221
181
  appId,
222
182
  importJSSDK: endpointType === 'tcb-api',
@@ -224,16 +184,9 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
224
184
  cdnEndpoints,
225
185
  },
226
186
  };
227
- }
228
- console.log(`Generating ${em('miniprogramRoot')} files`);
229
- await (0, generateFiles_1.default)(appFileData, templateDir, miniprogramRoot);
230
- // 若项目目录与小程序根目录不同,则拷贝素材到小程序根目录
231
- if (miniprogramRoot !== path_1.default.join(projDir, '/') && fs.existsSync(path_1.default.join(projDir, config_1.materialsDirName))) {
232
- console.log(`Move ${em(config_1.materialsDirName)} from` + `${projDir} to ${miniprogramRoot}`);
233
- await fs.move(path_1.default.join(projDir, config_1.materialsDirName), path_1.default.join(miniprogramRoot, config_1.materialsDirName));
234
- }
235
- // 生成数据源
236
- if (hasLowcodePkg) {
187
+ console.log(`Generating ${em('weda root')} files`);
188
+ await (0, generateFiles_1.default)(wedaRootFileData, templateDir, localWedaRoot);
189
+ // 生成数据源
237
190
  const officialLib = materials.find((item) => item.name === cals_1.OFFICIAL_LIB_KEY);
238
191
  const datasourceFileData = {
239
192
  'datasources/index.js.tpl': {
@@ -256,35 +209,120 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
256
209
  datasourceProfiles: (0, util_3.JsonToStringWithVariableName)([], { EOL: false }),
257
210
  },
258
211
  'datasources/dataset-profiles.js.tpl': {
259
- datasetProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasetProfiles)(mainAppData, weapps), { EOL: true }),
212
+ datasetProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasetProfiles)(mainAppData, /* 页面的dataset由各页面本身按需注册,不再提前注册 */ []), {
213
+ EOL: true,
214
+ }),
260
215
  },
261
216
  };
262
217
  console.log(`Generating ${em('datasources')} files`);
263
- await (0, generateFiles_1.default)(datasourceFileData, templateDir, miniprogramRoot);
264
- }
265
- // 生成上报 & 系统子包模块模块
266
- if (hasLowcodePkg) {
267
- const subpackageRootPath = path_1.default.join(miniprogramRoot, 'packages', '$wd_system');
218
+ await (0, generateFiles_1.default)(datasourceFileData, templateDir, localWedaRoot);
219
+ // 生成上报 & 系统子包模块模块
220
+ const subpackageRootPath = path_1.default.join(localWedaRoot, 'packages', '$wd_system');
268
221
  const sysSubpackageFileData = {
269
222
  'package.json': { cdnEndpoints },
270
223
  'index.js.tpl': { cdnEndpoints },
271
224
  };
272
225
  console.log(`Generating ${em('system subpackage')} files`);
226
+ await (0, generateFiles_1.copyRecursiveSync)(path_1.default.join(templateDir, 'packages/$wd_system/pages'), path_1.default.join(subpackageRootPath, 'pages'), {
227
+ filter: (src) => {
228
+ if (/.tpl$/.test(src)) {
229
+ return false;
230
+ }
231
+ return true;
232
+ },
233
+ });
273
234
  await (0, generateFiles_1.default)(sysSubpackageFileData, path_1.default.join(templateDir, 'packages/$wd_system'), subpackageRootPath);
274
235
  }
236
+ // #4 生成 miniprogramRoot 文件
237
+ if (mainAppData.mpPkgUrl) {
238
+ // 合并 project 和 app json,复写 appId
239
+ projectConfigJson.appId = projConfig.appId;
240
+ projectConfigJson.setting = {
241
+ ...projectConfigJson.setting,
242
+ ...projConfig.setting,
243
+ };
244
+ const wedaRoot = path_1.default.posix.join('./', projectConfigJson.miniprogramRoot || '/', projectConfigJson.wedaRoot || '');
245
+ if (!projectConfigJson.setting.packNpmManually) {
246
+ projectConfigJson.setting.packNpmManually = true;
247
+ }
248
+ if (!projectConfigJson.setting.packNpmRelationList) {
249
+ projectConfigJson.setting.packNpmRelationList = [];
250
+ }
251
+ projectConfigJson.setting.packNpmRelationList = [
252
+ ...projectConfigJson.setting.packNpmRelationList.filter((item) => [
253
+ './package.json',
254
+ '/package.json',
255
+ './packages/$wd_system/package.json',
256
+ '/packages/$wd_system/package.json',
257
+ ].includes(item.packageJsonPath)),
258
+ {
259
+ packageJsonPath: `./${path_1.default.posix.join(wedaRoot, 'package.json')}`,
260
+ miniprogramNpmDistDir: `./${wedaRoot}`,
261
+ },
262
+ {
263
+ packageJsonPath: `./${path_1.default.posix.join(wedaRoot, 'packages', '$wd_system', 'package.json')}`,
264
+ miniprogramNpmDistDir: `./${path_1.default.posix.join(wedaRoot, 'packages', '$wd_system')}`,
265
+ },
266
+ ];
267
+ await (0, generateFiles_1.writeFile)(projectConfigJsonPath, JSON.stringify(projectConfigJson, undefined, 2));
268
+ // 有了 framework app 之后,并且是源码的方式,追加 app 引用
269
+ if (hasLowcodePkg) {
270
+ let appJsPath = path_1.default.join(miniprogramRoot, 'app.js');
271
+ let appJsContent = await fs.readFile(appJsPath);
272
+ await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './${path_1.default.posix.join('./', projectConfigJson.wedaRoot, 'app/weapps-api')}'\n${appJsContent}`);
273
+ }
274
+ let appJsonPath = path_1.default.join(miniprogramRoot, 'app.json');
275
+ let appJson = await fs.readJson(appJsonPath);
276
+ appJson.subpackages = (0, mp_config_1.mergeSubPackages)(appJson.subpackages, appConfig.subpackages);
277
+ await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
278
+ }
279
+ else {
280
+ const importor = (0, util_3.generateLowcodeImportor)(mainAppData.lowCodes || []);
281
+ let appFileData = {
282
+ 'app.js': {
283
+ appConfig,
284
+ importor,
285
+ materialSubPackagePath: path_1.default.posix.join(buildContext.wedaRoot || '', config_1.materialsDirName),
286
+ wedaRootRelativePath: `.${path_1.default.posix.join('/', buildContext.wedaRoot || '', '/')}`,
287
+ },
288
+ 'app.json': { content: appConfig },
289
+ 'app.wxss': {
290
+ importStyles: materials
291
+ .reduce((styles, lib) => {
292
+ styles = styles.concat((lib.styles || []).map((stylePath) => stylePath && !stylePath.startsWith('/')
293
+ ? path_1.default.posix.join('./', buildContext.wedaRoot || '', config_1.materialsDirName, lib.name, stylePath)
294
+ : stylePath) || []);
295
+ return styles;
296
+ }, [])
297
+ .concat(importor.styles.map((mod) => path_1.default.posix.join('./', buildContext.wedaRoot || '', 'lowcode', (0, weapps_core_1.getCodeModuleFilePath)('global', mod, { style: '.wxss' })))),
298
+ },
299
+ };
300
+ console.log(`Generating ${em('miniprogramRoot')} files`);
301
+ await (0, generateFiles_1.default)(appFileData, templateDir, miniprogramRoot);
302
+ }
303
+ // 若项目目录与小程序根目录不同,则拷贝素材到小程序根目录
304
+ // if (miniprogramRoot !== path.join(projDir, '/') && fs.existsSync(path.join(projDir, materialsDirName))) {
305
+ // console.log(`Move ${em(materialsDirName)} from` + `${projDir} to ${miniprogramRoot}`);
306
+ // await fs.move(
307
+ // path.join(projDir, materialsDirName),
308
+ // path.join(miniprogramRoot, buildContext.wedaRoot || '', materialsDirName),
309
+ // );
310
+ // }
275
311
  // 生成子包
276
312
  await Promise.all(weapps.map(async (app, index) => {
277
313
  if (index == 0) {
278
314
  return;
279
315
  }
280
316
  else {
281
- const subpackageRootPath = path_1.default.join(miniprogramRoot, 'packages', app.rootPath || '/');
317
+ const subpackageRootPath = path_1.default.join(localWedaRoot, 'packages', app.rootPath || '/');
282
318
  let subpackageBuildCtx = {
283
319
  ...buildContext,
284
320
  rootPath: app.rootPath,
285
321
  };
286
322
  await generatePkg(subpackageBuildCtx, { cals: calses[index], weapp: app }, subpackageRootPath, pageConfigs[index]);
287
- await generateFramework(subpackageBuildCtx, app, subpackageRootPath, { deployOptions });
323
+ await generateFramework(subpackageBuildCtx, { cals: calses[index], weapp: app }, subpackageRootPath, {
324
+ deployOptions,
325
+ });
288
326
  // 生成package.json
289
327
  let packageJsonPath = path_1.default.join(subpackageRootPath, 'package.json');
290
328
  if (!fs.existsSync(packageJsonPath)) {
@@ -299,34 +337,46 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
299
337
  }
300
338
  }
301
339
  }));
302
- if (!isBrowserMpBuilder) {
303
- if (fs.existsSync(path_1.default.join(miniprogramRoot, 'package.json'))) {
304
- await (0, webpack_1.installDependencies)(miniprogramRoot, {
305
- ignoreInstall,
306
- fixNodeModulesMap: { '@cloudbase/js-sdk': endpointType !== 'tcb-api', mobx: true },
307
- });
308
- }
309
- const wdSystemSubRoot = path_1.default.join(miniprogramRoot, 'packages', '$wd_system');
310
- if (fs.existsSync(path_1.default.join(wdSystemSubRoot, 'package.json'))) {
311
- await (0, webpack_1.installDependencies)(wdSystemSubRoot, {
312
- ignoreInstall,
313
- });
340
+ // 将子包中 app.json / package.json merge 进主包中
341
+ if (weapps.length > 1) {
342
+ console.log(chalk_1.default.green('【混合模式】'), miniprogramRoot);
343
+ await (0, mixMode_1.handleSubApps)({
344
+ buildContext,
345
+ apps: weapps,
346
+ miniprogramRoot,
347
+ wedaRoot: localWedaRoot,
348
+ });
349
+ }
350
+ const roots = (path_1.default.posix.join('/', projectConfigJson.wedaRoot || '') === '/'
351
+ ? []
352
+ : [{ type: 'miniprogramRoot', path: miniprogramRoot }]).concat([
353
+ { type: 'wedaRoot', path: localWedaRoot },
354
+ { type: '$weda_system', path: path_1.default.join(localWedaRoot, 'packages', '$wd_system') },
355
+ ]);
356
+ for (let meta of roots) {
357
+ if (fs.existsSync(path_1.default.join(meta.path, 'package.json'))) {
358
+ if (isBrowserMpBuilder) {
359
+ await (0, net_1.installBrowserDependencies)({
360
+ type: meta.type,
361
+ path: meta.path,
362
+ runtimeEndpointType: endpointType || undefined,
363
+ });
364
+ }
365
+ else {
366
+ await (0, webpack_1.installDependencies)(meta.path, {
367
+ ignoreInstall,
368
+ fixNodeModulesMap: { '@cloudbase/js-sdk': endpointType !== 'tcb-api', mobx: true },
369
+ });
370
+ }
314
371
  }
315
372
  }
316
- await handleMpPlugins();
317
373
  console.timeEnd(operationLabel);
318
374
  // web端的builder不需要清除
319
375
  if (!isBrowserMpBuilder) {
320
- cleanProj(weapps, miniprogramRoot);
321
- cleanMaterils(path_1.default.join(miniprogramRoot, config_1.materialsDirName), used);
376
+ cleanProj(weapps, localWedaRoot);
377
+ cleanMaterils(path_1.default.join(localWedaRoot, config_1.materialsDirName), used);
322
378
  }
323
379
  return { miniprogramRoot };
324
- // SDK 插件
325
- async function handleMpPlugins() {
326
- // 编译后置原生小程序类的安装
327
- const mpPlugins = (await (0, plugin_1.getPluginType)(miniprogramRoot, plugins)).filter((item) => item.type === 'mp');
328
- await (0, plugin_2.runHandleMpPlugin)(miniprogramRoot, mpPlugins);
329
- }
330
380
  }
331
381
  exports.generateWxMp = generateWxMp;
332
382
  function resolveNpmDeps(weapps, materials, extra = {}) {
@@ -474,6 +524,7 @@ async function generatePkg(ctx, { cals, weapp }, appRoot, pageConfigs) {
474
524
  subLevelPath,
475
525
  importor,
476
526
  query: (0, util_2.createTemplateQuery)(ctx, (_f = page.dataset) === null || _f === void 0 ? void 0 : _f.query),
527
+ datasetProfile: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.generateDynamicDataset)(page.dataset), { EOL: true }),
477
528
  eventFlows: (0, util_2.createTemplateEventFlows)(ctx, page.eventFlows),
478
529
  resetShare: ((_j = (_h = (_g = page === null || page === void 0 ? void 0 : page.data) === null || _g === void 0 ? void 0 : _g.appShareMessage) === null || _h === void 0 ? void 0 : _h.value) === null || _j === void 0 ? void 0 : _j.enable) ||
479
530
  ((_k = allAppUsedComps === null || allAppUsedComps === void 0 ? void 0 : allAppUsedComps[cals_1.OFFICIAL_LIB_KEY]) === null || _k === void 0 ? void 0 : _k.has('Share')) ||
@@ -510,10 +561,14 @@ async function generatePkg(ctx, { cals, weapp }, appRoot, pageConfigs) {
510
561
  await writeLowCodeFiles(ctx, weapp, appRoot);
511
562
  }
512
563
  }
513
- async function generateFramework(ctx, appData, outDir, options) {
514
- var _a, _b;
564
+ async function generateFramework(ctx, { cals, weapp: appData }, outDir, options) {
565
+ var _a, _b, _c;
515
566
  let fileData = {};
516
567
  if (appData.mpPkgUrl) {
568
+ /**
569
+ * 当前包为代码包 + 主包
570
+ * framework 基础兜底
571
+ */
517
572
  if (!appData.rootPath) {
518
573
  fileData = {
519
574
  ...fileData,
@@ -562,6 +617,8 @@ async function generateFramework(ctx, appData, outDir, options) {
562
617
  version: (_a = options === null || options === void 0 ? void 0 : options.deployOptions) === null || _a === void 0 ? void 0 : _a.version,
563
618
  envId: appData.envId,
564
619
  envVersion: (ctx === null || ctx === void 0 ? void 0 : ctx.isProduction) ? 'production' : 'preview',
620
+ loginConfigVersion: (_b = cals.extra) === null || _b === void 0 ? void 0 : _b.loginConfigVersion,
621
+ basename: ctx.wedaRoot,
565
622
  pages: appData.pageInstanceList
566
623
  .sort((item) => (item.isHome ? -1 : 1))
567
624
  .map((item) => {
@@ -576,7 +633,7 @@ async function generateFramework(ctx, appData, outDir, options) {
576
633
  });
577
634
  }),
578
635
  }),
579
- appQuery: (0, util_2.createTemplateQuery)(ctx, (_b = appData.dataset) === null || _b === void 0 ? void 0 : _b.query),
636
+ appQuery: (0, util_2.createTemplateQuery)(ctx, (_c = appData.dataset) === null || _c === void 0 ? void 0 : _c.query),
580
637
  /**
581
638
  * @deprecated
582
639
  */
@@ -635,17 +692,15 @@ function getAppendableJson(json = {}) {
635
692
  return '';
636
693
  }
637
694
  // 处理使用到的组件
638
- async function cleanProj(weapps, miniprogramRoot) {
639
- weapps.map((pkg) => cleanPkg(pkg, miniprogramRoot));
695
+ async function cleanProj(weapps, wedaRoot) {
696
+ weapps.map((pkg) => cleanPkg(pkg, wedaRoot));
640
697
  }
641
- async function cleanPkg(pkg, miniprogramRoot) {
698
+ async function cleanPkg(pkg, wedaRoot) {
642
699
  // zip 模式跳过clean
643
700
  if (pkg.mpPkgUrl) {
644
701
  return;
645
702
  }
646
- const pkgDir = [miniprogramRoot, pkg.rootPath ? `packages${path_1.default.sep}${pkg.rootPath}` : '']
647
- .filter((p) => !!p)
648
- .join(path_1.default.sep);
703
+ const pkgDir = [wedaRoot, pkg.rootPath ? `packages${path_1.default.sep}${pkg.rootPath}` : ''].filter((p) => !!p).join(path_1.default.sep);
649
704
  const pagesDir = path_1.default.join(pkgDir, 'pages');
650
705
  const lowcodesDir = path_1.default.join(pkgDir, 'lowcode');
651
706
  const existedPages = await fs.readdir(pagesDir);
@@ -2,7 +2,7 @@ import { IWeAppComponentInstance, IWeAppData } from '@cloudbase/lowcode-generato
2
2
  import { IBuildContext } from './BuildContext';
3
3
  import NameMangler from '@cloudbase/lowcode-generator/lib/generator/util/name-mangler';
4
4
  import { IUsedComps } from '../types/common';
5
- export declare function installMaterials(ctx: IBuildContext, projDir: string, usedMeta: {
5
+ export declare function installMaterials(ctx: IBuildContext, outDir: string, usedMeta: {
6
6
  component: IUsedComps;
7
7
  action: IUsedComps;
8
8
  }, weapps: IWeAppData[]): Promise<void>;
@@ -43,7 +43,7 @@ const name_mangler_1 = __importDefault(require("@cloudbase/lowcode-generator/lib
43
43
  const junk = __importStar(require("../util/junk"));
44
44
  const cals_1 = require("@cloudbase/cals");
45
45
  const templateDir = `${config_1.appTemplateDir}/mp/`;
46
- async function installMaterials(ctx, projDir, usedMeta, weapps) {
46
+ async function installMaterials(ctx, outDir, usedMeta, weapps) {
47
47
  let { materialLibs: _materialLibs, isBrowserMpBuilder } = ctx;
48
48
  const weappsList = ctx.isMixMode ? weapps : weapps.filter((item) => !item.rootPath);
49
49
  let materialLibs = _materialLibs.filter((lib) => usedMeta.component[lib.name] || usedMeta.action[lib.name]);
@@ -78,10 +78,7 @@ async function installMaterials(ctx, projDir, usedMeta, weapps) {
78
78
  // 混合模式下,各个子包获取自己使用过的组件和复合组件(会出现冗余)
79
79
  // 统一都放在根目录下,可以减少冗余
80
80
  await Promise.all(weappsList.map(async (app) => {
81
- const targetDir = path.join(projDir,
82
- // 统一放在根目录下引用
83
- // app.rootPath || '',
84
- config_1.materialsDirName, name);
81
+ const targetDir = path.join(outDir, config_1.materialsDirName, name);
85
82
  if (usingMaterialMap[targetDir]) {
86
83
  return;
87
84
  }
@@ -177,7 +174,7 @@ async function installMaterials(ctx, projDir, usedMeta, weapps) {
177
174
  // #2 Generate composited libs
178
175
  await Promise.all(compositedLibs.map(async (lib) => {
179
176
  console.log(`Generate composited library ${lib.name}`);
180
- await (0, util_2.writeLibCommonRes2file)(lib, path.join(ctx.projDir, config_1.materialsDirName, lib.name, 'libCommonRes'));
177
+ await (0, util_2.writeLibCommonRes2file)(lib, path.join(outDir, config_1.materialsDirName, lib.name, 'libCommonRes'));
181
178
  await Promise.all(lib.components.map(async (cmp) => {
182
179
  return generateCompositeComponent({
183
180
  ...ctx,
@@ -188,7 +185,7 @@ async function installMaterials(ctx, projDir, usedMeta, weapps) {
188
185
  processCssUnit: lib.name !== '$template' ? 'rpx' : ctx.processCssUnit,
189
186
  // 只生成在主目录中,减少冗余
190
187
  // rootPath: app.rootPath || '', // 主包是没有 rootPath 的
191
- }, cmp, lib.compLibCommonResource);
188
+ }, cmp, path.join(outDir, config_1.materialsDirName), lib.compLibCommonResource);
192
189
  }));
193
190
  }));
194
191
  }
@@ -209,18 +206,16 @@ async function downloadMaterial(zipUrl, dstFolder, isBrowser = false, noCache =
209
206
  return;
210
207
  await (0, net_1.downloadZip)(zipUrl, dstFolder, isBrowser, noCache);
211
208
  }
212
- async function generateCompositeComponent(ctx, compositedComp, compLibCommonResource) {
209
+ async function generateCompositeComponent(ctx, compositedComp, outDir, compLibCommonResource) {
213
210
  const compositeCtx = {
214
211
  ...ctx,
215
212
  isPage: false,
216
213
  enableLoading: false,
217
214
  };
218
215
  const { materialName } = compositedComp;
219
- const outDir = path.join(compositeCtx.projDir,
220
- // compositeCtx.rootPath || '', // 所有组件统一生成到根目录
221
- config_1.materialsDirName, materialName, compositedComp.name);
216
+ const componentDir = path.join(outDir, materialName, compositedComp.name);
222
217
  const LOWCODE_DIR_NAME = 'lowcode';
223
- console.log(`Generating composited component ${materialName}:${compositedComp.name} to ${outDir}`);
218
+ console.log(`Generating composited component ${materialName}:${compositedComp.name} to ${componentDir}`);
224
219
  const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!compositeCtx.isProduction);
225
220
  // # Generating page
226
221
  const usingComponents = {};
@@ -288,10 +283,11 @@ async function generateCompositeComponent(ctx, compositedComp, compLibCommonReso
288
283
  },
289
284
  'index.wxss': {
290
285
  importStyles: importor.styles.map((mod) => path.posix.join(LOWCODE_DIR_NAME, (0, weapps_core_1.getCodeModuleFilePath)('global', mod, { style: '.wxss' }))),
286
+ content: (0, util_3.generateScopedStyleText)(componentInstances),
291
287
  },
292
288
  };
293
289
  // Generating file by template and data
294
- await (0, generateFiles_1.default)(pageFileData, `${templateDir}/component`, outDir);
290
+ await (0, generateFiles_1.default)(pageFileData, `${templateDir}/component`, componentDir);
295
291
  // #3 writing lowcode files
296
292
  /**
297
293
  * 低码没有开放 index 类别,直接去掉
@@ -319,7 +315,7 @@ async function generateCompositeComponent(ctx, compositedComp, compLibCommonReso
319
315
  if (mod.name === 'index') {
320
316
  return;
321
317
  }
322
- return (0, lowcode_1.writeCode2file)(compositeCtx, mod, path.join(outDir, LOWCODE_DIR_NAME), { comp: compositedComp }, themeCode);
318
+ return (0, lowcode_1.writeCode2file)(compositeCtx, mod, path.join(componentDir, LOWCODE_DIR_NAME), { comp: compositedComp }, themeCode);
323
319
  });
324
320
  // await writeLowCodeFiles(weapp, appRoot)
325
321
  // await generateFramework(weapp, appRoot)
@@ -354,14 +350,10 @@ function getWxmlTag(ctx, cmp, nameMangler) {
354
350
  tagName = (_f = cmpMeta === null || cmpMeta === void 0 ? void 0 : cmpMeta.platforms) === null || _f === void 0 ? void 0 : _f.mp.tagName;
355
351
  }
356
352
  if (compPath) {
357
- // 小程序混合模式时,组件库会存在子包内
358
- // 组件库永远都在根目录下,这样才能减少冗余 - royhyang
359
- const rootPath = ctx.rootPath || '';
360
353
  compPath =
361
354
  compPath.startsWith('/') || compPath.indexOf('://') > 0
362
355
  ? compPath
363
- : path.posix.join(
364
- /* ctx.isMixMode ? '/' + rootPath : */ '', `/${config_1.materialsDirName}/${cmp.moduleName}`, compPath);
356
+ : path.posix.join('/', ctx.wedaRoot || '', `${config_1.materialsDirName}/${cmp.moduleName}`, compPath);
365
357
  tagName = `${/^\$/.test(moduleName) ? NAME_MANAGER.mangle(moduleName) : moduleName}-${name}`;
366
358
  if (nameMangler) {
367
359
  tagName = nameMangler.mangle(tagName);
@@ -1,9 +1,15 @@
1
- import { IWeAppData, IPlugin } from '@cloudbase/lowcode-generator/lib/weapps-core';
1
+ import { IWeAppData } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  import { IBuildContext } from '../mp/BuildContext';
3
- export declare function handleMixMode({ buildContext, apps, miniprogramRoot, plugins, ignoreInstall, }: {
3
+ export declare function handleMixMode({ buildContext, apps, miniprogramRoot, wedaRoot, }: {
4
4
  buildContext: IBuildContext;
5
5
  apps: IWeAppData[];
6
6
  miniprogramRoot: string;
7
- plugins: IPlugin[];
7
+ wedaRoot: string;
8
8
  ignoreInstall: boolean;
9
9
  }): Promise<void>;
10
+ export declare function handleSubApps({ buildContext, apps, miniprogramRoot, wedaRoot, }: {
11
+ buildContext: IBuildContext;
12
+ apps: IWeAppData[];
13
+ miniprogramRoot: string;
14
+ wedaRoot: string;
15
+ }): Promise<void>;