@cloudbase/lowcode-builder 1.8.45 → 1.8.47

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.
@@ -6,7 +6,7 @@ export declare const materialsDirName = "materials";
6
6
  * src/template的代码,在IDE编辑器插件中构建builder
7
7
  * 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488&region=ap-shanghai&path=%252Flcap-builder%252F
8
8
  */
9
- export declare const builderTemplateURL = "https://comp-public-1303824488.file.myqcloud.com/lcap-builder/template.1.8.45.zip";
9
+ export declare const builderTemplateURL = "https://comp-public-1303824488.file.myqcloud.com/lcap-builder/template.1.8.47.zip";
10
10
  /**
11
11
  * miniprogram的代码,IDE插件后续会提供端功能
12
12
  * 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488&region=ap-shanghai&path=%252Flcap-builder%252F
@@ -45,7 +45,7 @@ exports.materialsDirName = 'materials'; // materials diretory of current project
45
45
  * src/template的代码,在IDE编辑器插件中构建builder
46
46
  * 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488&region=ap-shanghai&path=%252Flcap-builder%252F
47
47
  */
48
- exports.builderTemplateURL = 'https://comp-public-1303824488.file.myqcloud.com/lcap-builder/template.1.8.45.zip';
48
+ exports.builderTemplateURL = 'https://comp-public-1303824488.file.myqcloud.com/lcap-builder/template.1.8.47.zip';
49
49
  /**
50
50
  * miniprogram的代码,IDE插件后续会提供端功能
51
51
  * 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488&region=ap-shanghai&path=%252Flcap-builder%252F
@@ -69,6 +69,15 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
69
69
  if (!deployOptions.mode) {
70
70
  deployOptions.mode = types_1.DEPLOY_MODE.PREVIEW;
71
71
  }
72
+ /**
73
+ * 刷新正规化 packageName
74
+ */
75
+ [cals, ...subAppCalsList].forEach((app) => {
76
+ if (!app.extra) {
77
+ app.extra = {};
78
+ }
79
+ app.extra.rootPath = (0, util_1.normalizePackageName)(app.extra.rootPath);
80
+ });
72
81
  let appBuildDir = (output === null || output === void 0 ? void 0 : output.path) || (runtime === types_1.RUNTIME.CI ? (_a = (0, util_1.getCompileDirs)('app')) === null || _a === void 0 ? void 0 : _a.appBuildDir : (_b = (0, util_1.getCompileDirs)(appKey)) === null || _b === void 0 ? void 0 : _b.appBuildDir);
73
82
  const buildContext = {
74
83
  projDir: appBuildDir,
@@ -45,7 +45,11 @@ const config_1 = require("../config");
45
45
  const fs_extra_1 = __importDefault(require("fs-extra"));
46
46
  const junk = __importStar(require("../util/junk"));
47
47
  const url_1 = require("url");
48
- const transform_1 = require("../../utils/transform");
48
+ let BabelTransform = (code, options) => code;
49
+ if (!process.env.IS_WEB_WORKER) {
50
+ let transform = require('../../utils/transform');
51
+ BabelTransform = transform.BabelTransform;
52
+ }
49
53
  async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, buildTypeList = [common_1.BuildType.WEB], subAppCalsList, mode, devTool, runtime = types_1.RUNTIME.NONE, deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW }, ignoreInstall = false, cdnEndpoints, }) {
50
54
  var _a, _b, _c;
51
55
  const { projDir: buildDir, domain, materialLibs: dependencies, appId: appKey, isPrivateMode, enableExpiredTag, } = buildContext;
@@ -88,8 +92,6 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, bu
88
92
  assets,
89
93
  });
90
94
  await (0, copy_1.runCopy)(h5BuildDir, mainAppData, i18nConfig);
91
- // 构建 APP 需要的配置文件
92
- const appConfig = await (0, webpack_2.generateAppConfig)(mainAppData, subAppDataList, h5BuildDir);
93
95
  // // 素材库
94
96
  const runHandleMaterialTag = '🚥 buildWebApp-runHandleMaterial';
95
97
  console.time(runHandleMaterialTag);
@@ -144,7 +146,6 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, bu
144
146
  appBuildDir: h5BuildDir,
145
147
  assets: jsAssets,
146
148
  buildTypeList,
147
- mpConfig: appConfig,
148
149
  mode,
149
150
  devTool,
150
151
  publicPath,
@@ -246,7 +247,7 @@ function _BabelTransformCalsExpression(key, value) {
246
247
  value = value.replace(FOR_IN_REG, '');
247
248
  }
248
249
  }
249
- value = (0, transform_1.BabelTransform)(value, { IIFE: true });
250
+ value = BabelTransform(value, { IIFE: true });
250
251
  if (forPrefix) {
251
252
  value = `${forPrefix}${value}`;
252
253
  }
@@ -5,11 +5,10 @@ import { ICDN_ENDPOINTS_COFIG } from '../config';
5
5
  interface IWebpackCoreProps extends BuildAppProps {
6
6
  cals: IPlatformApp;
7
7
  appBuildDir: string;
8
- mpConfig: any;
9
8
  mainAppData: IWebRuntimeAppData;
10
9
  subAppDataList: IWebRuntimeAppData[];
11
10
  assets: string[];
12
11
  cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
13
12
  }
14
- export declare function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode, appKey, buildTypeList, mpConfig, assets, devTool, generateMpType, cdnEndpoints, }: IWebpackCoreProps): Promise<string>;
13
+ export declare function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode, appKey, buildTypeList, assets, devTool, generateMpType, cdnEndpoints, }: IWebpackCoreProps): Promise<string>;
15
14
  export {};
@@ -5,7 +5,7 @@ const common_1 = require("../types/common");
5
5
  const webpack_1 = require("../service/webpack");
6
6
  const generate_1 = require("./generate");
7
7
  const cals_1 = require("@cloudbase/cals");
8
- async function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode = common_1.WebpackModeType.NONE, appKey, buildTypeList = [common_1.BuildType.WEB], mpConfig, assets = [], devTool = 'vite', generateMpType = common_1.GenerateMpType.APP, cdnEndpoints, }) {
8
+ async function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode = common_1.WebpackModeType.NONE, appKey, buildTypeList = [common_1.BuildType.WEB], assets = [], devTool = 'vite', generateMpType = common_1.GenerateMpType.APP, cdnEndpoints, }) {
9
9
  var _a;
10
10
  console.time('runWebpackCore');
11
11
  console.time('webpackGenerate');
@@ -20,13 +20,6 @@ async function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir,
20
20
  assets,
21
21
  });
22
22
  console.timeEnd('webpackGenerate');
23
- // compile
24
- console.time('generateMpJsonConfigFile');
25
- await (0, webpack_1.generateMpJsonConfigFile)(allAppDataList, mpConfig, appBuildDir, {
26
- appKey,
27
- generateMpType,
28
- });
29
- console.timeEnd('generateMpJsonConfigFile');
30
23
  await (0, generate_1.generateHTML)({
31
24
  appId: mainAppData.id || appKey,
32
25
  envId: mainAppData.envId || '',
@@ -137,8 +137,12 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
137
137
  'common/query.js': {},
138
138
  'common/flow.js': {},
139
139
  'common/info': {},
140
- 'common/privacyModal': {},
141
- 'common/modal': {},
140
+ /**
141
+ * 使用微信的 modal
142
+ * 暂时保留内部实现待之后使用
143
+ */
144
+ // 'common/privacyModal': {},
145
+ // 'common/modal': {},
142
146
  /**
143
147
  * 调试用
144
148
  */
@@ -218,7 +222,7 @@ async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptio
218
222
  return;
219
223
  }
220
224
  else {
221
- const subpackageRootPath = path_1.default.join(miniprogramRoot, app.rootPath || '/');
225
+ const subpackageRootPath = path_1.default.join(miniprogramRoot, 'packages', app.rootPath || '/');
222
226
  let subpackageBuildCtx = {
223
227
  ...buildContext,
224
228
  rootPath: app.rootPath,
@@ -341,12 +345,13 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
341
345
  },
342
346
  ],
343
347
  });
344
- const wxml = (0, wxml_1.generateWxml)({ ...ctx, rootPath, isPage: true }, componentInstances, `Page ${rootPath ? path_1.default.join(rootPath, 'pages') : ''}/${page.id}`, wxmlDataPrefix, usingComponents, componentGenerics);
348
+ const wxml = (0, wxml_1.generateWxml)({ ...ctx, rootPath, isPage: true }, componentInstances, `Page ${rootPath ? path_1.default.join('packages', rootPath, 'pages') : ''}/${page.id}`, wxmlDataPrefix, usingComponents, componentGenerics);
345
349
  const importor = (0, util_3.generateLowcodeImportor)(page.lowCodes);
346
350
  const pageFileName = (0, lodash_1.get)(pageConfigs, `${page.id}.pageFileName`, 'index');
351
+ const subLevelPath = rootPath ? `${path_1.default.posix.relative(`packages/${rootPath}`, '')}/` : '';
347
352
  const pageFileData = {
348
353
  [`api.js|api.js`]: {
349
- subLevelPath: rootPath ? `${path_1.default.posix.relative(rootPath, '')}/` : '',
354
+ subLevelPath,
350
355
  uuid: rootPath ? `${rootPath}/${page.id}` : page.id,
351
356
  label: ((_b = (_a = page === null || page === void 0 ? void 0 : page.data) === null || _a === void 0 ? void 0 : _a.navigationBarTitleText) === null || _b === void 0 ? void 0 : _b.value) || ((_d = (_c = page === null || page === void 0 ? void 0 : page.data) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.value),
352
357
  },
@@ -365,7 +370,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
365
370
  },
366
371
  debug: ctx.debugMode,
367
372
  stringifyObj: util_1.inspect,
368
- subLevelPath: rootPath ? `${path_1.default.posix.relative(rootPath, '')}/` : '',
373
+ subLevelPath,
369
374
  importor,
370
375
  query: (0, util_2.createTemplateQuery)(ctx, (_f = page.dataset) === null || _f === void 0 ? void 0 : _f.query),
371
376
  eventFlows: (0, util_2.createTemplateEventFlows)(ctx, page.eventFlows),
@@ -385,7 +390,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
385
390
  },
386
391
  [`index.wxss|${pageFileName}.wxss`]: {
387
392
  subWxss: rootPath && !((_l = ctx.mainAppData) === null || _l === void 0 ? void 0 : _l.mpPkgUrl)
388
- ? `@import "${path_1.default.posix.relative(`/${rootPath}/pages/${page.id}`, '/lowcode')}/style.wxss";`
393
+ ? `@import "${path_1.default.posix.relative(`/packages/${rootPath}/pages/${page.id}`, '/lowcode')}/style.wxss";`
389
394
  : '',
390
395
  content: (0, weapps_core_1.toCssText)((0, cals_1.processCommonStyle2CSSProperties)(page.commonStyle, {
391
396
  defaultUnit: processCssUnit,
@@ -440,7 +445,7 @@ async function generateFramework(ctx, appData, outDir, options) {
440
445
  ...fileData,
441
446
  'app/app-global.js': {},
442
447
  'app/weapps-api.js': {
443
- subLevelPath: appData.rootPath ? `${path_1.default.posix.relative(`${appData.rootPath}`, '')}/` : '',
448
+ subLevelPath: appData.rootPath ? `${path_1.default.posix.relative(`packages/${appData.rootPath}`, '')}/` : '',
444
449
  subPackageName: appData.rootPath || '',
445
450
  importor,
446
451
  appConfig: (0, util_3.JsonToStringWithVariableName)({
@@ -555,7 +560,9 @@ async function cleanPkg(pkg, miniprogramRoot) {
555
560
  if (pkg.mpPkgUrl) {
556
561
  return;
557
562
  }
558
- const pkgDir = [miniprogramRoot, pkg.rootPath].filter((p) => !!p).join(path_1.default.sep);
563
+ const pkgDir = [miniprogramRoot, pkg.rootPath ? `packages${path_1.default.sep}${pkg.rootPath}` : '']
564
+ .filter((p) => !!p)
565
+ .join(path_1.default.sep);
559
566
  const pagesDir = path_1.default.join(pkgDir, 'pages');
560
567
  const lowcodesDir = path_1.default.join(pkgDir, 'lowcode');
561
568
  const existedPages = await fs.readdir(pagesDir);
@@ -18,7 +18,7 @@ async function writeCode2file(ctx, mod, lowcodeRootDir, opts = {}, themeCode) {
18
18
  // Generate app lowcode
19
19
  const baseDir = path_1.default.relative(path_1.default.dirname(file), appDir).replace(/\\/g, '/');
20
20
  // 子包混合模式需要添加相对索引到根目录
21
- const relativeRoot = (ctx === null || ctx === void 0 ? void 0 : ctx.isMixMode) && ctx.rootPath ? `${path_1.default.relative(ctx.rootPath, '')}/` : '';
21
+ const relativeRoot = (ctx === null || ctx === void 0 ? void 0 : ctx.isMixMode) && ctx.rootPath ? `${path_1.default.relative(`packages/${ctx.rootPath}`, '')}/` : '';
22
22
  let weappsApiPrefix = [
23
23
  `import { app, $app${pageId !== 'global' ? '' : ', $w'} } from '${relativeRoot}${baseDir}/app/weapps-api';`,
24
24
  ]; // windows compatibility
@@ -246,7 +246,8 @@ async function generateCompositeComponent(ctx, compositedComp, compLibCommonReso
246
246
  enableLoading: false,
247
247
  };
248
248
  const { materialName } = compositedComp;
249
- const outDir = path.join(compositeCtx.projDir, compositeCtx.rootPath || '', // 混合模式下,可能会有 rootPath
249
+ const outDir = path.join(compositeCtx.projDir,
250
+ // compositeCtx.rootPath || '', // 所有组件统一生成到根目录
250
251
  config_1.materialsDirName, materialName, compositedComp.name);
251
252
  const LOWCODE_DIR_NAME = 'lowcode';
252
253
  console.log(`Generating composited component ${materialName}:${compositedComp.name} to ${outDir}`);
@@ -96,7 +96,7 @@ async function handleMixMode({ buildContext, apps = [], miniprogramRoot, plugins
96
96
  await Promise.all(apps
97
97
  .filter((app) => app.rootPath)
98
98
  .map(async (app) => {
99
- const subAppPath = path_1.default.join(miniprogramRoot, app.rootPath || '');
99
+ const subAppPath = path_1.default.join(miniprogramRoot, ...(app.rootPath ? ['packages', app.rootPath] : ['']));
100
100
  // 复制整个子包
101
101
  // 新模式下已经生成,感觉无需进行复制 @royhyang
102
102
  // const distDir = path.join(generateMpPath, app.rootPath || '')
@@ -106,7 +106,7 @@ async function handleMixMode({ buildContext, apps = [], miniprogramRoot, plugins
106
106
  let appJson = await fs_extra_1.default.readJson(appJsonPath);
107
107
  if (appJson) {
108
108
  let { subpackages = [] } = rootAppJosn;
109
- const find = subpackages.find((item) => item.root == app.rootPath);
109
+ const find = subpackages.find((item) => item.root === `packages/${app.rootPath}`);
110
110
  if (find) {
111
111
  find.pages = appJson.pages;
112
112
  }
@@ -115,7 +115,7 @@ async function handleMixMode({ buildContext, apps = [], miniprogramRoot, plugins
115
115
  rootAppJosn.subpackages = [];
116
116
  }
117
117
  rootAppJosn.subpackages.push({
118
- root: app.rootPath,
118
+ root: `packages/${app.rootPath}`,
119
119
  pages: appJson.pages,
120
120
  });
121
121
  }
@@ -121,6 +121,9 @@ function generateMpConfig(ctx, weapps, options) {
121
121
  projConfig.setting = {};
122
122
  }
123
123
  projConfig.setting.bigPackageSizeSupport = true;
124
+ if (process.env.IS_WEB_WORKER) {
125
+ projConfig.setting.ignoreUploadUnusedFiles = true;
126
+ }
124
127
  if (options.mpAppId) {
125
128
  projConfig.appId = options.mpAppId;
126
129
  }
@@ -135,7 +138,7 @@ function extractPages(weapps, pageConfigs) {
135
138
  let homePageId = '';
136
139
  weapps.forEach((weapp, index) => {
137
140
  const { rootPath } = weapp;
138
- const subPackage = { root: rootPath, pages: [] };
141
+ const subPackage = { root: rootPath ? `packages/${rootPath}` : '', pages: [] };
139
142
  if (rootPath) {
140
143
  subpackages.push(subPackage);
141
144
  }
@@ -22,18 +22,18 @@ function generateWxml(ctx, widgets, docTag, wxmlDataPrefix, usingComponents, com
22
22
  if (ctx.isPage) {
23
23
  const { enablePageRoot } = ctx;
24
24
  const originElements = xmlJson.elements;
25
- usingComponents['wd-privacy'] = '/common/privacyModal/index';
25
+ // usingComponents['wd-privacy'] = '/common/privacyModal/index';
26
26
  usingComponents['wd-info'] = '/common/info/index';
27
27
  // 登录校验: 向其最外层包裹一层block
28
28
  xmlJson.elements = [
29
- {
30
- type: 'element',
31
- name: 'wd-privacy',
32
- attributes: {},
33
- elements: [],
34
- _order: -Infinity,
35
- _parent: null,
36
- },
29
+ // {
30
+ // type: 'element',
31
+ // name: 'wd-privacy',
32
+ // attributes: {},
33
+ // elements: [],
34
+ // _order: -Infinity,
35
+ // _parent: null,
36
+ // },
37
37
  {
38
38
  type: 'element',
39
39
  name: enablePageRoot ? 'view' : 'block',
@@ -44,19 +44,12 @@ export interface IGenerateMpJsonConfigFileOpts {
44
44
  appKey?: string;
45
45
  generateMpType?: 'app' | 'subpackage';
46
46
  }
47
- export declare function generateAppConfig(mainAppData: IWebRuntimeAppData, subAppDataList: IWebRuntimeAppData[], appBuildDir: string): Promise<{}>;
48
47
  export declare function generateKboneTabBarConfig(mpConfig: Record<string, any>, appBuildDir: any): Promise<void>;
49
48
  export declare function downloadAndWriteTabBarIcon(iconPath: any, pagePath: any, appBuildDir: string, fileName: string): Promise<unknown>;
50
- export declare function generateKbonePageConfig(mpConfig: Record<string, any>, mainAppData: IWebRuntimeAppData, subAppDataList?: IWebRuntimeAppData[]): Record<string, any>;
51
- export declare function generateKboneAppConfig(mpConfig: Record<string, any>, mainAppData: IWebRuntimeAppData): void;
52
- export declare function generateMpJsonConfigFile(allAppDataList: IWebRuntimeAppData[], userConfig: any, appBuildDir: string, options: IGenerateMpJsonConfigFileOpts): Promise<void>;
53
49
  export declare function getMainAppDataByList(allAppDataList: IWebRuntimeAppData[]): IWebRuntimeAppData | undefined;
54
50
  export declare function getHomePageInstance(pageInstanceList: any): any;
55
51
  export declare function getPageName(name: string): string;
56
- export declare function getMpAllRouterConfig(allAppDataList: IWebRuntimeAppData[], getHome?: boolean): any;
57
52
  export declare function getWebpackWebBuildParams(appId: string, appBuildDir: string, publicPath?: string, mode?: WebpackModeType, buildTypeList?: BuildType[], extraDefine?: {}, assets?: string[]): any;
58
- export declare function getWebpackMpBuildParams(appBuildDir: string, materialsDir: string, dependencies: IMaterialItem[] | undefined, nodeModulesPath: string, allAppDataList: IWebRuntimeAppData[], mode: string, watch: boolean, options: IGenerateMpJsonConfigFileOpts): any;
59
- export declare function getAllPageMpEntryPath(allAppDataList: IWebRuntimeAppData[], appBuildDir: string): Record<string, any>;
60
53
  export declare function downloadAndInstallDependencies(dependencies: IMaterialItem[] | undefined, materialsDir: string, installOptions?: IInstallOpts): Promise<void>;
61
54
  export declare function downloadDependencies(targetDir: string, srcZipUrl: string): Promise<void>;
62
55
  /**
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.downloadAssets = exports.generateWebpackWebDevServerFile = exports.getMaterialNodeModulesPathList = exports.installDependencies = exports.downloadDependencies = exports.downloadAndInstallDependencies = exports.getAllPageMpEntryPath = exports.getWebpackMpBuildParams = exports.getWebpackWebBuildParams = exports.getMpAllRouterConfig = exports.getPageName = exports.getHomePageInstance = exports.getMainAppDataByList = exports.generateMpJsonConfigFile = exports.generateKboneAppConfig = exports.generateKbonePageConfig = exports.downloadAndWriteTabBarIcon = exports.generateKboneTabBarConfig = exports.generateAppConfig = exports.generateWebpackWebBuildParamsFile = exports.fixAppJson = exports.OUTPUT_DIR = exports.PERSISTENT_DEPENDIENCES_MAP = void 0;
6
+ exports.downloadAssets = exports.generateWebpackWebDevServerFile = exports.getMaterialNodeModulesPathList = exports.installDependencies = exports.downloadDependencies = exports.downloadAndInstallDependencies = exports.getWebpackWebBuildParams = exports.getPageName = exports.getHomePageInstance = exports.getMainAppDataByList = exports.downloadAndWriteTabBarIcon = exports.generateKboneTabBarConfig = exports.generateWebpackWebBuildParamsFile = exports.fixAppJson = exports.OUTPUT_DIR = exports.PERSISTENT_DEPENDIENCES_MAP = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const lodash_1 = require("lodash");
@@ -52,28 +52,6 @@ async function generateWebpackWebBuildParamsFile({ appId, allAppDataList, appBui
52
52
  return webpackConfigPath;
53
53
  }
54
54
  exports.generateWebpackWebBuildParamsFile = generateWebpackWebBuildParamsFile;
55
- async function generateAppConfig(mainAppData, subAppDataList, appBuildDir) {
56
- let originMpConfig = {};
57
- // 如果有 mp_config 则读取内容合并。
58
- const configMod = mainAppData.codeModules.find((p) => p.name === config_1.MP_CONFIG_MODULE_NAME);
59
- if (configMod) {
60
- const code = configMod.code.replace(/export\s+default/, '');
61
- try {
62
- originMpConfig = eval(`(${code})`);
63
- }
64
- catch (e) {
65
- console.error('Kbone config file error', e);
66
- }
67
- }
68
- // app 配置
69
- generateKboneAppConfig(originMpConfig, mainAppData);
70
- // 页面配置
71
- originMpConfig = generateKbonePageConfig(originMpConfig, mainAppData, subAppDataList);
72
- // tabbar 配置
73
- await generateKboneTabBarConfig(originMpConfig, appBuildDir);
74
- return originMpConfig;
75
- }
76
- exports.generateAppConfig = generateAppConfig;
77
55
  async function generateKboneTabBarConfig(mpConfig, appBuildDir) {
78
56
  mpConfig.appExtraConfig = mpConfig.appExtraConfig || {};
79
57
  if (mpConfig.appExtraConfig.tabBar) {
@@ -120,109 +98,6 @@ async function downloadAndWriteTabBarIcon(iconPath, pagePath, appBuildDir, fileN
120
98
  });
121
99
  }
122
100
  exports.downloadAndWriteTabBarIcon = downloadAndWriteTabBarIcon;
123
- // 将 weapps 配置的 page-data 转换到 mp_config
124
- function generateKbonePageConfig(mpConfig, mainAppData, subAppDataList = []) {
125
- mpConfig.pages = mpConfig.pages || {};
126
- const allAppDataList = subAppDataList.concat(mainAppData);
127
- allAppDataList.map((appData) => {
128
- appData.pageInstanceList.forEach((item) => {
129
- const pageId = [appData.rootPath, item.id].filter((i) => i).join('_');
130
- if (!mpConfig.pages[pageId]) {
131
- mpConfig.pages[pageId] = {};
132
- }
133
- const navigationBarTitleText = item.data.navigationBarTitleText || item.data.title;
134
- // 去除部分 mp 不认的属性
135
- delete item.data.title;
136
- delete item.data.params;
137
- delete item.data.scene;
138
- // page 配置
139
- config_1.KBONE_PAGE_KEYS.forEach((key) => {
140
- if (item.data[key]) {
141
- mpConfig.pages[pageId][key] = item.data[key];
142
- }
143
- });
144
- // extra 配置
145
- mpConfig.pages[pageId].extra = {
146
- ...item.data,
147
- navigationBarTitleText,
148
- };
149
- });
150
- });
151
- return mpConfig;
152
- }
153
- exports.generateKbonePageConfig = generateKbonePageConfig;
154
- function generateKboneAppConfig(mpConfig, mainAppData) {
155
- if (mainAppData === null || mainAppData === void 0 ? void 0 : mainAppData.appConfig) {
156
- if (mainAppData.appConfig.window) {
157
- mpConfig.app = mpConfig.app || {};
158
- mpConfig.app = {
159
- ...mainAppData.appConfig.window,
160
- ...mpConfig.app,
161
- };
162
- }
163
- }
164
- }
165
- exports.generateKboneAppConfig = generateKboneAppConfig;
166
- // 生成 kbone mp 配置文件
167
- async function generateMpJsonConfigFile(allAppDataList, userConfig, appBuildDir, options) {
168
- const mainAppData = getMainAppDataByList(allAppDataList);
169
- const subAppDataList = allAppDataList.filter((i) => i.rootPath);
170
- const homeId = getHomePageInstance(mainAppData.pageInstanceList).id;
171
- userConfig = userConfig || {};
172
- const kbConfig = {
173
- origin: 'https://weapps.tencent.com',
174
- entry: `/${homeId}`,
175
- redirect: {
176
- notFound: `${homeId}`,
177
- accessDenied: `${homeId}`,
178
- },
179
- generate: {
180
- autoBuildNpm: true,
181
- appEntry: 'miniprogram-app',
182
- appWxss: 'display',
183
- subpackages: {},
184
- globalVars: [['__injectProxy', '(window.Proxy = Proxy)']],
185
- },
186
- app: {
187
- navigationBarTitleText: `WeApps-${options.appKey}`,
188
- },
189
- projectConfig: {
190
- appid: 'touristappid',
191
- projectname: `WeApps-${options.appKey}`,
192
- },
193
- packageConfig: {
194
- author: 'weapps',
195
- },
196
- ...userConfig,
197
- global: {
198
- ...userConfig.global,
199
- rem: true, // rem 必须为 true
200
- },
201
- router: getMpAllRouterConfig(allAppDataList),
202
- __homePath__: getMpAllRouterConfig(allAppDataList, true),
203
- };
204
- if (subAppDataList === null || subAppDataList === void 0 ? void 0 : subAppDataList.length) {
205
- const subpackages = {};
206
- subAppDataList.map((appData) => {
207
- const { rootPath } = appData;
208
- subpackages[rootPath] = Object.keys(getMpAllRouterConfig([appData]));
209
- });
210
- kbConfig.generate = {
211
- ...kbConfig.generate,
212
- subpackages,
213
- };
214
- }
215
- // kbone 生成子包模式
216
- if (options.generateMpType === 'subpackage') {
217
- kbConfig.generate = {
218
- ...kbConfig.generate,
219
- app: 'noemit',
220
- };
221
- }
222
- const templateStr = JSON.stringify(kbConfig, null, 2);
223
- await fs_extra_1.default.writeFile(path_1.default.resolve(appBuildDir, 'webpack/miniprogram.config.js'), `export default = ${templateStr}`);
224
- }
225
- exports.generateMpJsonConfigFile = generateMpJsonConfigFile;
226
101
  function getMainAppDataByList(allAppDataList) {
227
102
  return allAppDataList.find((item) => !item.rootPath);
228
103
  }
@@ -244,29 +119,6 @@ function getPageName(name) {
244
119
  return `${name}`;
245
120
  }
246
121
  exports.getPageName = getPageName;
247
- function getMpAllRouterConfig(allAppDataList, getHome = false) {
248
- const router = {};
249
- let homePath = '';
250
- allAppDataList.map((appData) => {
251
- const { pageInstanceList, rootPath = '' } = appData;
252
- (0, weapps_core_1.loopDealWithFn)(pageInstanceList, (pageInstance) => {
253
- const name = [rootPath, pageInstance.id].filter((i) => i).join('_');
254
- const path = `/${name}`;
255
- if (!homePath) {
256
- homePath = name;
257
- }
258
- if (pageInstance.isHome && !rootPath) {
259
- homePath = name;
260
- }
261
- router[name] = [path];
262
- });
263
- });
264
- if (getHome) {
265
- return homePath;
266
- }
267
- return router;
268
- }
269
- exports.getMpAllRouterConfig = getMpAllRouterConfig;
270
122
  function getWebpackWebBuildParams(appId, appBuildDir, publicPath = '/', mode = common_1.WebpackModeType.NONE, buildTypeList = [common_1.BuildType.WEB], extraDefine = {}, assets = []) {
271
123
  return {
272
124
  context: appBuildDir,
@@ -306,48 +158,6 @@ function getWebpackWebBuildParams(appId, appBuildDir, publicPath = '/', mode = c
306
158
  };
307
159
  }
308
160
  exports.getWebpackWebBuildParams = getWebpackWebBuildParams;
309
- function getWebpackMpBuildParams(appBuildDir, materialsDir, dependencies = [], nodeModulesPath, allAppDataList, mode, watch, options) {
310
- return {
311
- context: appBuildDir,
312
- mode,
313
- watch,
314
- entry: getAllPageMpEntryPath(allAppDataList, appBuildDir),
315
- outputPath: path_1.default.resolve(appBuildDir, 'dist/mp/common'),
316
- resolveModules: [
317
- appBuildDir,
318
- path_1.default.resolve(appBuildDir, 'node_modules'),
319
- path_1.default.resolve(appBuildDir, 'src'),
320
- ...getMaterialNodeModulesPathList(dependencies, materialsDir, appBuildDir),
321
- 'node_modules',
322
- ],
323
- watchOptions: {
324
- ignored: /node_modules/,
325
- aggregateTimeout: 600,
326
- poll: 1000,
327
- },
328
- cache: {
329
- type: 'memory',
330
- },
331
- };
332
- }
333
- exports.getWebpackMpBuildParams = getWebpackMpBuildParams;
334
- function getAllPageMpEntryPath(allAppDataList, appBuildDir) {
335
- const entry = {};
336
- // 优先填首页
337
- const mainAppData = getMainAppDataByList(allAppDataList);
338
- const homePageInstance = getHomePageInstance(mainAppData.pageInstanceList);
339
- entry[homePageInstance.id] = path_1.default.resolve(appBuildDir, `src/pages/${getPageName(homePageInstance.id)}/main.mp.jsx`);
340
- allAppDataList.map((app) => {
341
- const { pageInstanceList, rootPath } = app;
342
- const packagePathStr = rootPath ? `packages/${rootPath}` : '';
343
- (0, weapps_core_1.loopDealWithFn)(pageInstanceList, (pageInstance) => {
344
- const pageName = rootPath ? `${rootPath}_${pageInstance.id}` : pageInstance.id;
345
- entry[pageName] = path_1.default.resolve(appBuildDir, path_1.default.join('src', packagePathStr, `pages/${getPageName(pageInstance.id)}/main.mp.jsx`));
346
- });
347
- });
348
- return entry;
349
- }
350
- exports.getAllPageMpEntryPath = getAllPageMpEntryPath;
351
161
  async function downloadAndInstallDependencies(dependencies = [], materialsDir, installOptions = {}) {
352
162
  const localPkg = (0, util_1.getCurrentPackageJson)();
353
163
  await Promise.all(dependencies.map(async (item) => {
@@ -56,3 +56,4 @@ export declare function generateLowcodeImportor(lowcodes?: IWeAppCode[]): {
56
56
  common: boolean;
57
57
  styles: IWeAppCode[];
58
58
  };
59
+ export declare function normalizePackageName(packageName?: string | null): string | null | undefined;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateLowcodeImportor = exports.getCompileDirs = exports.deepDealComponentSchemaJson = exports.canUseVite = exports.isOfficialComponentLib = exports.readComponentLibMata = exports.writeLibCommonRes2file = exports.getYyptConfigInfo = exports.getComponentsInfo = exports.getInputProps = exports.removeRequireUncached = exports.requireUncached = exports.JsonToStringWithVariableName = exports.getSelfPackageJson = exports.getCurrentPackageJson = exports.promiseWrapper = exports.getFileNameByUrl = exports.deepDealSchema = exports.simpleDeepClone = exports.deepDeal = exports.isPlainObject = exports.isArray = exports.getMetaInfoBySourceKey = void 0;
6
+ exports.normalizePackageName = exports.generateLowcodeImportor = exports.getCompileDirs = exports.deepDealComponentSchemaJson = exports.canUseVite = exports.isOfficialComponentLib = exports.readComponentLibMata = exports.writeLibCommonRes2file = exports.getYyptConfigInfo = exports.getComponentsInfo = exports.getInputProps = exports.removeRequireUncached = exports.requireUncached = exports.JsonToStringWithVariableName = exports.getSelfPackageJson = exports.getCurrentPackageJson = exports.promiseWrapper = exports.getFileNameByUrl = exports.deepDealSchema = exports.simpleDeepClone = exports.deepDeal = exports.isPlainObject = exports.isArray = exports.getMetaInfoBySourceKey = void 0;
7
7
  // import * as R from 'ramda'
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -290,3 +290,14 @@ function generateLowcodeImportor(lowcodes = []) {
290
290
  return importor;
291
291
  }
292
292
  exports.generateLowcodeImportor = generateLowcodeImportor;
293
+ function normalizePackageName(packageName) {
294
+ if (!packageName) {
295
+ return packageName;
296
+ }
297
+ const matched = packageName.match(/packages\/(.*)?/);
298
+ if (matched) {
299
+ return matched[1];
300
+ }
301
+ return packageName;
302
+ }
303
+ exports.normalizePackageName = normalizePackageName;