@cloudbase/lowcode-builder 1.8.95 → 1.8.97

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 (38) hide show
  1. package/lib/builder/core/index.d.ts +9 -0
  2. package/lib/builder/core/index.js +118 -1
  3. package/lib/builder/h5/generate.d.ts +1 -1
  4. package/lib/builder/h5/index.d.ts +2 -2
  5. package/lib/builder/h5/webpack.d.ts +2 -2
  6. package/lib/builder/mp/BuildContext.d.ts +18 -14
  7. package/lib/builder/mp/index.d.ts +11 -1
  8. package/lib/builder/mp/index.js +97 -84
  9. package/lib/builder/mp/lowcode.d.ts +5 -3
  10. package/lib/builder/mp/lowcode.js +14 -5
  11. package/lib/builder/mp/materials.d.ts +10 -5
  12. package/lib/builder/mp/materials.js +139 -135
  13. package/lib/builder/mp/util.d.ts +15 -12
  14. package/lib/builder/mp/util.js +50 -22
  15. package/lib/builder/mp/wxml.d.ts +5 -3
  16. package/lib/builder/mp/wxml.js +30 -27
  17. package/lib/builder/service/webpack.js +0 -1
  18. package/lib/builder/util/common.d.ts +0 -1
  19. package/lib/builder/util/common.js +1 -44
  20. package/lib/builder/util/generateFiles.d.ts +1 -1
  21. package/lib/builder/util/generateFiles.js +5 -1
  22. package/lib/builder.web.js +8 -8
  23. package/package.json +2 -2
  24. package/template/html/index.html.ejs +7 -3
  25. package/template/mp/app/weapps-api.js +3 -1
  26. package/template/mp/app.js +2 -2
  27. package/template/mp/common/cloud-sdk.js +28 -0
  28. package/template/mp/common/data-patch.js +9 -1
  29. package/template/mp/common/util.js +11 -2
  30. package/template/mp/common/watch.js +1 -1
  31. package/template/mp/common/weapp-component.js +5 -5
  32. package/template/mp/common/weapp-page.js +4 -3
  33. package/template/mp/common/widget.js +51 -38
  34. package/template/mp/component/index.js +7 -6
  35. package/template/mp/datasources/index.js.tpl +2 -30
  36. package/template/mp/package.json +5 -4
  37. package/template/mp/packages/$wd_system/pages/login/index.wxml +1 -1
  38. package/template/webpack/web.prod.js +1 -1
@@ -3,6 +3,7 @@ import { BuildType, GenerateMpType, WebpackBuildCallBack, WebpackModeType } from
3
3
  import { DEPLOY_MODE, RUNTIME } from '../../types';
4
4
  import { IPlatformApp } from '@cloudbase/cals';
5
5
  import { ICDN_ENDPOINTS_COFIG } from '../config';
6
+ import { ICommonBuildContext } from '../mp/BuildContext';
6
7
  interface IBaseAppProps {
7
8
  appKey: string;
8
9
  dependencies?: IMaterialItem[];
@@ -94,3 +95,11 @@ export declare function normalizeInputs(inputs: INormalizeInput, { envId, getWeb
94
95
  deployOptions: any;
95
96
  }) => string;
96
97
  }): InormalizeOutput;
98
+ export declare function buildComposite({ dependencies, output, isBrowserMpBuilder, }: {
99
+ dependencies: IMaterialItem[];
100
+ rpxCalcRoot?: string;
101
+ output: {
102
+ path: string;
103
+ };
104
+ isBrowserMpBuilder?: ICommonBuildContext['isBrowserMpBuilder'];
105
+ }): Promise<void>;
@@ -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.normalizeInputs = exports.getCompileDirs = exports.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.cleanComponentDir = exports.buildWedaApp = exports.buildWedaConfig = void 0;
6
+ exports.buildComposite = exports.normalizeInputs = exports.getCompileDirs = exports.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.cleanComponentDir = exports.buildWedaApp = exports.buildWedaConfig = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const util_1 = require("../util");
@@ -16,6 +16,7 @@ const cals_1 = require("@cloudbase/cals");
16
16
  const net_1 = require("../util/net");
17
17
  const config_1 = require("../config");
18
18
  const axios_1 = __importDefault(require("axios"));
19
+ const materials_1 = require("../mp/materials");
19
20
  const pkg = require('../../../package.json');
20
21
  async function buildWedaConfig({ output, domain = undefined, isPrivateMode = undefined, endpointType = undefined, buildTypeList = [common_1.BuildType.WEB], }) {
21
22
  if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
@@ -131,6 +132,10 @@ async function buildWedaApp({ cals, subAppCalsList: _subAppCalsList = [], depend
131
132
  }
132
133
  if (value === null || value === void 0 ? void 0 : value.component) {
133
134
  const component = value;
135
+ /**
136
+ * TODO: 判断需要根据 componentType 来
137
+ * 但是此刻还没有具体的 componentInfo 信息
138
+ */
134
139
  if ((value === null || value === void 0 ? void 0 : value.component) &&
135
140
  `${component.module}:${component.component}` === `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_NAME}`) {
136
141
  // 给 Repeater 组件加一层虚拟项组件,在虚拟项组件上挂 for 循环
@@ -362,3 +367,115 @@ function normalizeCals(cals, { buildTypeList, envId, deployOptions, appId, getWe
362
367
  function _getWebRootPath({ appId, deployOptions }) {
363
368
  return (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.UPLOAD ? `/${appId}/production/` : `/${appId}/preview/`;
364
369
  }
370
+ async function buildComposite({ dependencies, output, isBrowserMpBuilder, }) {
371
+ var _a, _b;
372
+ const packageMiniprogramEntry = 'dist';
373
+ const localWedaRoot = path_1.default.join(output.path, packageMiniprogramEntry);
374
+ const buildContext = {
375
+ materialLibs: dependencies.map((lib) => {
376
+ (0, materials_1.normalizeCompositeDependienciesForBuild)(lib);
377
+ return lib;
378
+ }),
379
+ isProduction: true,
380
+ /**
381
+ * 新版本不再默认转换
382
+ * 则此处构建都以px为准
383
+ */
384
+ processCssUnit: 'px',
385
+ isBrowserMpBuilder,
386
+ };
387
+ await (0, index_1.generateWedaRootCommonFile)({
388
+ buildContext,
389
+ buildTypeList: [common_1.BuildType.MP],
390
+ localWedaRoot,
391
+ nativeMode: true,
392
+ // 组件无需生成,节省空间
393
+ filter: (src) => {
394
+ return !/common\/weapp-page/.test(src);
395
+ },
396
+ });
397
+ let usedComps;
398
+ const composite = dependencies.find((lib) => lib.isComposite);
399
+ if (composite) {
400
+ let id = 0;
401
+ const cals = {
402
+ items: [
403
+ {
404
+ id: '$page',
405
+ type: 'PAGE',
406
+ items: ((_b = (_a = composite.components) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (component) => {
407
+ id += 1;
408
+ return {
409
+ id: `id${id}`,
410
+ module: composite.name,
411
+ component: component.name,
412
+ attributes: {},
413
+ };
414
+ })) || [],
415
+ },
416
+ ],
417
+ };
418
+ usedComps = (0, cals_1.getUsedComps)([cals], dependencies, { streamline: true, withAction: true });
419
+ }
420
+ await (0, materials_1.installMaterials)(buildContext, localWedaRoot, usedComps, 'lib');
421
+ await Promise.all(buildContext.materialLibs.map((lib) => {
422
+ return fs_extra_1.default.remove(path_1.default.join(localWedaRoot, config_1.materialsDirName, lib.name, 'meta.json'));
423
+ }));
424
+ await patchMpComponentNPM({
425
+ packageDir: output.path,
426
+ name: composite === null || composite === void 0 ? void 0 : composite.name,
427
+ version: composite === null || composite === void 0 ? void 0 : composite.version,
428
+ packageMiniprogramEntry,
429
+ });
430
+ // await generateCompLibs(dependencies, rpxCalcRoot);
431
+ }
432
+ exports.buildComposite = buildComposite;
433
+ async function patchMpComponentNPM({ packageDir, name, version, packageMiniprogramEntry = '', }) {
434
+ await fs_extra_1.default.mkdirSync(path_1.default.join(packageDir, 'scripts'));
435
+ const packageJsonPath = path_1.default.join(packageDir, 'package.json');
436
+ let packageJSON = {};
437
+ if (fs_extra_1.default.existsSync(packageJsonPath)) {
438
+ packageJSON = await fs_extra_1.default.readJSON(packageJsonPath);
439
+ }
440
+ const BASE_DEPS = {
441
+ mobx: '^5.15.4',
442
+ 'lodash.get': '^4.4.2',
443
+ 'lodash.set': '^4.3.2',
444
+ 'miniprogram-gesture': '^1.0.6',
445
+ 'miniprogram-api-promise': '^1.0.4',
446
+ '@cloudbase/oauth': '^0.1.1-alpha.5',
447
+ '@cloudbase/weda-client': '^1.0.31',
448
+ '@cloudbase/weda-cloud-sdk': '^1.0.59',
449
+ };
450
+ if (packageJSON.dependencies) {
451
+ for (const key in BASE_DEPS) {
452
+ delete packageJSON.dependencies[key];
453
+ }
454
+ }
455
+ packageJSON = {
456
+ ...packageJSON,
457
+ name: `@tcwd/weda-component-${name || 'lib'}`,
458
+ version: version || packageJSON.version || '0.0.1',
459
+ miniprogram: `./${packageMiniprogramEntry}`,
460
+ scripts: {
461
+ ...packageJSON.scripts,
462
+ postinstall: 'node scripts/fixCloudSdk.js',
463
+ },
464
+ peerDependencies: {
465
+ ...packageJSON.peerDependencies,
466
+ ...BASE_DEPS,
467
+ },
468
+ };
469
+ await Promise.all([
470
+ fs_extra_1.default.writeFile(path_1.default.join(packageDir, 'scripts', 'fixCloudSdk.js'), `try {
471
+ const cloudIndex = require.resolve('@cloudbase/weda-cloud-sdk') || '';
472
+ const cloudFixPath = cloudIndex.replace(/@cloudbase\\/weda-cloud-sdk\\/.*$/, '@cloudbase/weda-cloud-sdk/scripts/fix-wx-none-private.js');
473
+ const fix = require(cloudFixPath);
474
+ fix()
475
+ } catch(e) {
476
+ console.log('run scripts error', e)
477
+ }
478
+ `),
479
+ fs_extra_1.default.writeFile(packageJsonPath, JSON.stringify(packageJSON, undefined, 2)),
480
+ ]);
481
+ }
@@ -13,7 +13,7 @@ export declare function generateHTML({ buildContext, appId, envId, description,
13
13
  * 默认值为 undefined 否则应为 false
14
14
  */
15
15
  enableLoading, publicPath, }: {
16
- buildContext: Omit<ICommonBuildContext, 'mainAppData'>;
16
+ buildContext: Pick<ICommonBuildContext, 'materialLibs' | 'uin'>;
17
17
  appId: string;
18
18
  envId: string;
19
19
  description?: string;
@@ -3,10 +3,10 @@ import { BuildType, WebpackModeType } from '../types/common';
3
3
  import { RUNTIME } from '../../types';
4
4
  import { IPlatformApp } from '@cloudbase/cals';
5
5
  import { ICDN_ENDPOINTS_COFIG } from '../config';
6
- import { ICommonBuildContext } from '../mp/BuildContext';
6
+ import { IAppCommonBuildContext } from '../mp/BuildContext';
7
7
  import { IBuildWedaApp } from '../core';
8
8
  export declare function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, buildTypeList, subAppCalsList, mode, devTool, runtime, deployOptions, ignoreInstall, cdnEndpoints, }: {
9
- buildContext: Omit<ICommonBuildContext, 'mainAppData'>;
9
+ buildContext: Omit<IAppCommonBuildContext, 'mainAppData'>;
10
10
  cals: IPlatformApp;
11
11
  subAppCalsList: IPlatformApp[];
12
12
  i18nConfig?: II18nConfig;
@@ -2,9 +2,9 @@ import { IWebRuntimeAppData } from '@cloudbase/lowcode-generator/lib/weapps-core
2
2
  import { BuildAppProps } from '../core/index';
3
3
  import { IPlatformApp } from '@cloudbase/cals';
4
4
  import { ICDN_ENDPOINTS_COFIG } from '../config';
5
- import { ICommonBuildContext } from '../mp/BuildContext';
5
+ import { IAppCommonBuildContext } from '../mp/BuildContext';
6
6
  interface IWebpackCoreProps extends BuildAppProps {
7
- buildContext: Omit<ICommonBuildContext, 'mainAppData'>;
7
+ buildContext: Omit<IAppCommonBuildContext, 'mainAppData'>;
8
8
  cals: IPlatformApp;
9
9
  appBuildDir: string;
10
10
  mainAppData: IWebRuntimeAppData;
@@ -7,18 +7,9 @@ export interface ICommonBuildContext {
7
7
  * 账号信息
8
8
  */
9
9
  uin?: string;
10
- /**
11
- * 应用id
12
- */
13
- appId: string;
14
- projDir: string;
15
- domain: string;
16
10
  materialLibs: IMaterialItem[];
17
11
  isProduction: boolean;
18
- mainAppData: IWeAppData;
19
- isMixMode: boolean;
20
12
  rootPath?: string;
21
- miniprogramPlugins?: IMiniprogramPlugin[];
22
13
  debugMode?: boolean;
23
14
  isBrowserMpBuilder?: boolean;
24
15
  processCssUnit?: 'px' | 'rem' | 'rpx';
@@ -26,6 +17,16 @@ export interface ICommonBuildContext {
26
17
  * 是否是私有化的环境
27
18
  */
28
19
  isPrivateMode?: boolean;
20
+ }
21
+ export interface IAppCommonBuildContext extends ICommonBuildContext {
22
+ /**
23
+ * 应用id
24
+ */
25
+ appId: string;
26
+ projDir: string;
27
+ domain: string;
28
+ mainAppData: IWeAppData;
29
+ isMixMode: boolean;
29
30
  /**
30
31
  * 云开发sdk请求,js-sdk or wx.cloud
31
32
  */
@@ -59,16 +60,19 @@ export interface ICommonBuildContext {
59
60
  */
60
61
  statusPageId?: string;
61
62
  }
62
- export interface IBuildContext extends ICommonBuildContext {
63
+ export interface IMpCommonBuildContext extends ICommonBuildContext {
64
+ /**
65
+ * 组件库目录独立子包
66
+ */
67
+ enableAsyncMaterials?: boolean;
68
+ miniprogramPlugins?: IMiniprogramPlugin[];
69
+ }
70
+ export interface IBuildContext extends IAppCommonBuildContext, IMpCommonBuildContext {
63
71
  /**
64
72
  * 是否在页面层面添加节点
65
73
  * 并设置 #page-root-id
66
74
  */
67
75
  enablePageRoot?: boolean;
68
- /**
69
- * 组件库目录独立子包
70
- */
71
- enableAsyncMaterials?: boolean;
72
76
  /**
73
77
  * weda 默认自身root
74
78
  */
@@ -1,9 +1,19 @@
1
1
  import { IWeAppData, IPlugin } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  import { ICDN_ENDPOINTS_COFIG } from '../config';
3
- import { IBuildContext } from './BuildContext';
3
+ import { IBuildContext, IMpCommonBuildContext } 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 generateWedaRootCommonFile({ buildContext, buildTypeList, localWedaRoot, loginConfigVersion, cssVarConfig, appId, nativeMode, filter, }: {
8
+ buildContext: IMpCommonBuildContext & Partial<Pick<IBuildContext, 'enableExpiredTag' | 'domain' | 'runtimeDynamicConfig'>>;
9
+ buildTypeList: BuildType[];
10
+ localWedaRoot: string;
11
+ appId?: string;
12
+ loginConfigVersion?: string;
13
+ cssVarConfig?: Object;
14
+ nativeMode?: boolean;
15
+ filter?: (src: string) => boolean;
16
+ }): Promise<void>;
7
17
  export declare function generateWxMp({ buildContext: _buildContext, weapps, calses, deployOptions, options, buildTypeList, ignoreInstall, cdnEndpoints, mpConfig, }: {
8
18
  buildContext: Omit<IBuildContext, 'wedaRoot'>;
9
19
  weapps: IWeAppData[];
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.writeLowCodeFiles = exports.generateConfig = exports.generateWxMp = void 0;
29
+ exports.writeLowCodeFiles = exports.generateConfig = exports.generateWxMp = exports.generateWedaRootCommonFile = void 0;
30
30
  const chalk_1 = __importDefault(require("chalk"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const util_1 = require("util");
@@ -66,8 +66,85 @@ function patchBuildContext(ctx, calses) {
66
66
  ctx.miniprogramPlugins = (mainAppData.miniprogramPlugins || []).filter((plugin) => used.component[plugin.name] || used.action[plugin.name]);
67
67
  return { used };
68
68
  }
69
+ async function generateWedaRootCommonFile({ buildContext, buildTypeList, localWedaRoot, loginConfigVersion, cssVarConfig, appId, nativeMode, filter = () => true, }) {
70
+ const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!buildContext.isProduction);
71
+ const expirationStartTimesnap = buildContext.enableExpiredTag ? Date.now() : 0;
72
+ const cssVarMap = Object.entries((0, theme_1.mergeCssVarConfig)(cssVarConfig, 'MP'))
73
+ .map(([key, _value]) => {
74
+ const value = _value || '';
75
+ return [key, value.replace(/;$/, '')];
76
+ })
77
+ .reduce((map, [key, value]) => {
78
+ map[key] = value;
79
+ return map;
80
+ }, {}) || {};
81
+ let customLoginConfig;
82
+ let loginConfigPathname = loginConfigVersion
83
+ ? (0, cals_1.generateCustomLoginConfigPathname)({ appId: appId || '', version: loginConfigVersion })
84
+ : '';
85
+ if (loginConfigPathname && buildContext.domain) {
86
+ const url = `https://${buildContext.domain}${loginConfigPathname}`;
87
+ try {
88
+ const { data } = await axios_1.default.get(url, { responseType: 'json' });
89
+ if (data) {
90
+ customLoginConfig = data;
91
+ }
92
+ }
93
+ catch (e) {
94
+ console.error('预置获取登录配置失败:', url, e);
95
+ }
96
+ }
97
+ const wedaRootFileData = {
98
+ 'common/style.js': {},
99
+ 'common/util.js': {
100
+ skipCheckAuth: process.env.SKIP_CHECK_AUTH,
101
+ isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
102
+ expirationStartTimesnap,
103
+ runtimeDynamicConfig: buildContext.runtimeDynamicConfig || {},
104
+ RUNTIME_CONFIG_URL: index_1.RUNTIME_CONFIG_URL,
105
+ loginConfigPathname,
106
+ customLoginConfig: customLoginConfig ? JSON.stringify(customLoginConfig, undefined, 2) : 'null',
107
+ },
108
+ 'common/cloud-sdk.js': {},
109
+ 'common/widget.js': {},
110
+ 'common/weapp-page.js': {
111
+ expirationStartTimesnap,
112
+ pageStyle: JSON.stringify(cssVarMap || {}, undefined, 2),
113
+ },
114
+ 'common/weapp-component.js': {
115
+ nativeMode,
116
+ },
117
+ 'common/merge-renderer.js': {
118
+ dataPropNames: wxmlDataPrefix,
119
+ debug: buildContext.debugMode,
120
+ },
121
+ 'common/data-patch.js': {},
122
+ 'common/event-emitter.js': {},
123
+ 'common/watch.js': {},
124
+ 'common/constant.js': {
125
+ REPEATER: JSON.stringify(config_1.REPEATER, undefined, 2),
126
+ },
127
+ 'common/query.js': {},
128
+ 'common/flow.js': {},
129
+ 'common/info': {},
130
+ 'common/placeholder': {},
131
+ /**
132
+ * 使用微信的 modal
133
+ * 暂时保留内部实现待之后使用
134
+ */
135
+ // 'common/privacyModal': {},
136
+ // 'common/modal': {},
137
+ /**
138
+ * 调试用
139
+ */
140
+ // 'common/behaviors.js': {},
141
+ };
142
+ console.log(`Generating ${em('weda root')} files`);
143
+ await (0, generateFiles_1.default)(wedaRootFileData, templateDir, localWedaRoot, filter);
144
+ }
145
+ exports.generateWedaRootCommonFile = generateWedaRootCommonFile;
69
146
  async function generateWxMp({ buildContext: _buildContext, weapps, calses, deployOptions, options, buildTypeList, ignoreInstall = false, cdnEndpoints = {}, mpConfig = {}, }) {
70
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
147
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
71
148
  const operationLabel = em('Wexin MiniProgram Generated');
72
149
  console.time(operationLabel);
73
150
  console.log(`Generating ${em('Wexin MiniProgram')} to ${_buildContext.projDir}`);
@@ -104,8 +181,7 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
104
181
  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
182
  _buildContext.materialLibs = [..._buildContext.materialLibs, templateLib];
106
183
  }
107
- const { uin = '', appId, projDir, materialLibs: materials, isProduction, mainAppData, domain, isPrivateMode = false, endpointType = '', isBrowserMpBuilder = false, } = _buildContext;
108
- const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
184
+ const { uin = '', appId, projDir, materialLibs: materials, mainAppData, domain, isPrivateMode = false, endpointType = '', isBrowserMpBuilder = false, } = _buildContext;
109
185
  const hasLowcodePkg = weapps.find((item) => !item.mpPkgUrl);
110
186
  // #1 generate project files
111
187
  if (!mainAppData.mpPkgUrl) {
@@ -131,7 +207,7 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
131
207
  };
132
208
  // #1.5 安装依赖库,生成 materials 目录副作用修改了buildContext 因此需要早于页面生成
133
209
  if (hasLowcodePkg) {
134
- await (0, materials_1.installMaterials)(buildContext, localWedaRoot, used, weapps);
210
+ await (0, materials_1.installMaterials)(buildContext, localWedaRoot, used);
135
211
  }
136
212
  // #2 生成主包, 若主包为代码包上游已经处理过,不再处理
137
213
  if (mainAppData.mpPkgUrl) {
@@ -147,84 +223,21 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
147
223
  isPrivateMode,
148
224
  endpointType,
149
225
  }, localWedaRoot);
150
- const expirationStartTimesnap = buildContext.enableExpiredTag ? Date.now() : 0;
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'))
152
- .map(([key, _value]) => {
153
- const value = _value || '';
154
- return [key, value.replace(/;$/, '')];
155
- })
156
- .reduce((map, [key, value]) => {
157
- map[key] = value;
158
- return map;
159
- }, {}) || {};
160
- let customLoginConfig;
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 })
163
- : '';
164
- if (loginConfigPathname) {
165
- const url = `https://${domain}${loginConfigPathname}`;
166
- try {
167
- const { data } = await axios_1.default.get(url, { responseType: 'json' });
168
- if (data) {
169
- customLoginConfig = data;
170
- }
171
- }
172
- catch (e) {
173
- console.error('预置获取登录配置失败:', url, e);
174
- }
175
- }
176
- const wedaRootFileData = {
177
- 'common/style.js': {},
178
- 'common/util.js': {
179
- skipCheckAuth: process.env.SKIP_CHECK_AUTH,
180
- isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
181
- expirationStartTimesnap,
182
- runtimeDynamicConfig: buildContext.runtimeDynamicConfig,
183
- RUNTIME_CONFIG_URL: index_1.RUNTIME_CONFIG_URL,
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 })
186
- : '',
187
- customLoginConfig: customLoginConfig ? JSON.stringify(customLoginConfig, undefined, 2) : 'null',
188
- },
189
- 'common/widget.js': {},
190
- 'common/weapp-page.js': {
191
- expirationStartTimesnap,
192
- pageStyle: JSON.stringify(cssVarMap || {}, undefined, 2),
193
- },
194
- 'common/weapp-component.js': {},
195
- 'common/merge-renderer.js': {
196
- dataPropNames: wxmlDataPrefix,
197
- debug: buildContext.debugMode,
198
- },
199
- 'common/data-patch.js': {},
200
- 'common/event-emitter.js': {},
201
- 'common/watch.js': {},
202
- 'common/constant.js': {
203
- REPEATER: JSON.stringify(config_1.REPEATER, undefined, 2),
204
- },
205
- 'common/query.js': {},
206
- 'common/flow.js': {},
207
- 'common/info': {},
208
- 'common/placeholder': {},
209
- /**
210
- * 使用微信的 modal
211
- * 暂时保留内部实现待之后使用
212
- */
213
- // 'common/privacyModal': {},
214
- // 'common/modal': {},
215
- /**
216
- * 调试用
217
- */
218
- // 'common/behaviors.js': {},
226
+ await generateWedaRootCommonFile({
227
+ buildContext,
228
+ buildTypeList,
229
+ localWedaRoot,
230
+ appId,
231
+ loginConfigVersion: (_d = (_c = calses[0]) === null || _c === void 0 ? void 0 : _c.extra) === null || _d === void 0 ? void 0 : _d.loginConfigVersion,
232
+ cssVarConfig: (_f = (_e = calses[0]) === null || _e === void 0 ? void 0 : _e.theme) === null || _f === void 0 ? void 0 : _f.cssVarConfig,
233
+ });
234
+ await (0, generateFiles_1.default)({
219
235
  'package.json': {
220
236
  appId,
221
237
  importJSSDK: endpointType === 'tcb-api',
222
238
  extraDeps: resolveNpmDeps(weapps, materials),
223
- cdnEndpoints,
224
239
  },
225
- };
226
- console.log(`Generating ${em('weda root')} files`);
227
- await (0, generateFiles_1.default)(wedaRootFileData, templateDir, localWedaRoot);
240
+ }, templateDir, localWedaRoot);
228
241
  // 生成数据源
229
242
  const officialLib = materials.find((item) => item.name === cals_1.OFFICIAL_LIB_KEY);
230
243
  const datasourceFileData = {
@@ -236,9 +249,9 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
236
249
  appID: appId,
237
250
  resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
238
251
  isProd: (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.UPLOAD,
239
- clientID: ((_o = mainAppData.extra) === null || _o === void 0 ? void 0 : _o.enableLoginStatusShare)
252
+ clientID: ((_g = mainAppData.extra) === null || _g === void 0 ? void 0 : _g.enableLoginStatusShare)
240
253
  ? mainAppData.envId
241
- : (_p = mainAppData.extra) === null || _p === void 0 ? void 0 : _p.clientId,
254
+ : (_h = mainAppData.extra) === null || _h === void 0 ? void 0 : _h.clientId,
242
255
  cdnEndpoints,
243
256
  builderVersion: core_1.version || '',
244
257
  officialLibVersion: (officialLib === null || officialLib === void 0 ? void 0 : officialLib.version) || '',
@@ -288,8 +301,8 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
288
301
  projectConfigJson.setting = {
289
302
  ...projectConfigJson.setting,
290
303
  ...projConfig.setting,
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)
304
+ packNpmRelationList: ((_j = projConfig.setting) === null || _j === void 0 ? void 0 : _j.packNpmRelationList) || ((_k = projectConfigJson.setting) === null || _k === void 0 ? void 0 : _k.packNpmRelationList)
305
+ ? (0, mp_config_1.mergePackNpmRelationList)(projConfig.setting.packNpmRelationList, (_l = projectConfigJson.setting) === null || _l === void 0 ? void 0 : _l.packNpmRelationList)
293
306
  : undefined,
294
307
  };
295
308
  const wedaRoot = path_1.default.posix.join('./', projectConfigJson.miniprogramRoot || '/', projectConfigJson.wedaRoot || '');
@@ -309,7 +322,7 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
309
322
  }
310
323
  const appJsonPath = path_1.default.join(miniprogramRoot, 'app.json');
311
324
  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);
325
+ appJson.subpackages = (0, mp_config_1.mergeSubPackages)(((_o = (_m = appJson.subpackages) === null || _m === void 0 ? void 0 : _m.filter) === null || _o === void 0 ? void 0 : _o.call(_m, (item) => item.name !== 'wd-sys-module' && item.name !== 'wd-sys-materials')) || [], appConfig.subpackages);
313
326
  await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
314
327
  }
315
328
  else {
@@ -473,7 +486,7 @@ async function generatePkg(ctx, { cals, weapp }, appRoot, pageConfigs) {
473
486
  if (weapp.mpPkgUrl) {
474
487
  // 清空历史文件,使用zip覆盖
475
488
  console.log(`Removing ${appRoot}`);
476
- await (0, generateFiles_1.cleanDir)(appRoot, ['materials']);
489
+ await (0, generateFiles_1.cleanDir)(appRoot, [config_1.materialsDirName]);
477
490
  await (0, net_1.downloadZip)(weapp.mpPkgUrl, appRoot, ctx.isBrowserMpBuilder);
478
491
  if (fs.existsSync(path_1.default.join(appRoot, '__MACOSX'))) {
479
492
  await fs.remove(path_1.default.join(appRoot, '__MACOSX'));
@@ -1,9 +1,11 @@
1
1
  import { IWeAppCode, ICompositedComponent } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
- import { IBuildContext } from './BuildContext';
3
- export declare function writeCode2file(ctx: IBuildContext, mod: IWeAppCode, lowcodeRootDir: string, opts?: {
2
+ import { IBuildContext, IMpCommonBuildContext } from './BuildContext';
3
+ export declare function writeCode2file(ctx: IBuildContext | (IMpCommonBuildContext & {
4
+ isMixMode?: undefined;
5
+ }), mod: IWeAppCode, lowcodeRootDir: string, opts?: {
4
6
  pageId?: string;
5
7
  appDir?: string;
6
8
  comp?: ICompositedComponent;
7
- }, themeCode?: ''): Promise<void>;
9
+ }, themeCode?: '', externalAPIImport?: boolean): Promise<void>;
8
10
  export declare function handle$page(code: string): string;
9
11
  export declare function handle$comp(code: string): string;
@@ -9,9 +9,16 @@ const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
9
9
  const style_1 = require("@cloudbase/lowcode-generator/lib/generator/util/style");
10
10
  const generateFiles_1 = require("../util/generateFiles");
11
11
  const cals_1 = require("@cloudbase/cals");
12
- async function writeCode2file(ctx, mod, lowcodeRootDir, opts = {}, themeCode) {
12
+ async function writeCode2file(ctx, mod, lowcodeRootDir, opts = {}, themeCode, externalAPIImport) {
13
13
  const { pageId = 'global', appDir, comp } = opts;
14
14
  const file = path_1.default.join(lowcodeRootDir, (0, weapps_core_1.getCodeModuleFilePath)(pageId || 'global', mod, { style: '.wxss' }));
15
+ function importFromClientSDK(with$w) {
16
+ return [
17
+ `import { getWedaAPI } from '@cloudbase/weda-client';`,
18
+ 'const app = new Proxy({}, { get: function(obj, prop){ return getWedaAPI()?.app?.[prop] }});',
19
+ 'const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});',
20
+ ].concat(with$w ? ['const $w = new Proxy({}, { get: function(obj, prop){ return getWedaAPI()?.$w?.[prop] }});'] : []);
21
+ }
15
22
  let { code } = mod;
16
23
  if (mod.type !== cals_1.ECodeType.STYLE && mod.type !== cals_1.ECodeType.THEME) {
17
24
  if (appDir) {
@@ -19,9 +26,9 @@ async function writeCode2file(ctx, mod, lowcodeRootDir, opts = {}, themeCode) {
19
26
  const baseDir = path_1.default.relative(path_1.default.dirname(file), appDir).replace(/\\/g, '/');
20
27
  // 子包混合模式需要添加相对索引到根目录
21
28
  const relativeRoot = (ctx === null || ctx === void 0 ? void 0 : ctx.isMixMode) && ctx.rootPath ? `${path_1.default.relative(`packages/${ctx.rootPath}`, '')}/` : '';
22
- let weappsApiPrefix = [
23
- `import { app, $app${pageId !== 'global' ? '' : ', $w'} } from '${relativeRoot}${baseDir}/app/weapps-api';`,
24
- ]; // windows compatibility
29
+ let weappsApiPrefix = externalAPIImport
30
+ ? importFromClientSDK(pageId === 'global')
31
+ : [`import { app, $app${pageId !== 'global' ? '' : ', $w'} } from '${relativeRoot}${baseDir}/app/weapps-api';`]; // windows compatibility
25
32
  if (pageId !== 'global') {
26
33
  weappsApiPrefix.push(`import { $page, $w } from '${baseDir}/pages/${pageId}/api';`);
27
34
  }
@@ -29,7 +36,9 @@ async function writeCode2file(ctx, mod, lowcodeRootDir, opts = {}, themeCode) {
29
36
  }
30
37
  else {
31
38
  // Generate component lowcode
32
- code = `import { app, $app, $w } from '${mod.type === 'handler-fn' ? '../' : ''}../../../../app/weapps-api';\n${code.replace(/\$comp/g, weapps_core_1.COMPONENT_API_PREFIX)}`;
39
+ code = `${externalAPIImport
40
+ ? importFromClientSDK(true).join('\n')
41
+ : `import { app, $app, $w } from '${mod.type === 'handler-fn' ? '../' : ''}../../../../app/weapps-api';`}\n${code.replace(/\$comp/g, weapps_core_1.COMPONENT_API_PREFIX)}`;
33
42
  }
34
43
  }
35
44
  else {
@@ -1,11 +1,13 @@
1
- import { IWeAppComponentInstance, IWeAppData } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
- import { IBuildContext } from './BuildContext';
1
+ import { IWeAppComponentInstance } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
+ import { IBuildContext, IMpCommonBuildContext } 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, outDir: string, usedMeta: {
5
+ export declare function normalizeCompositeDependienciesForBuild(lib: any): any;
6
+ declare type TInstallMaterialsType = 'lib' | 'inline';
7
+ export declare function installMaterials(ctx: IMpCommonBuildContext, outDir: string, usedMeta?: {
6
8
  component: IUsedComps;
7
9
  action: IUsedComps;
8
- }, weapps: IWeAppData[]): Promise<void>;
10
+ }, mode?: TInstallMaterialsType): Promise<void>;
9
11
  /**
10
12
  * 过滤组件库文件
11
13
  * @param src 源文件
@@ -13,10 +15,13 @@ export declare function installMaterials(ctx: IBuildContext, outDir: string, use
13
15
  * @returns boolean
14
16
  */
15
17
  export declare function filterMaterial(src: any, dest: any): boolean;
16
- export declare function getWxmlTag(ctx: IBuildContext, cmp: Required<IWeAppComponentInstance>['xComponent'], nameMangler?: NameMangler): {
18
+ export declare function getWxmlTag(ctx: IMpCommonBuildContext & {
19
+ wedaRoot?: IBuildContext['wedaRoot'];
20
+ }, cmp: Required<IWeAppComponentInstance>['xComponent'], nameMangler?: NameMangler): {
17
21
  tagName: string;
18
22
  path?: undefined;
19
23
  } | {
20
24
  tagName: string;
21
25
  path: any;
22
26
  };
27
+ export {};